akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
using namespace std;

void solve(long long A, long long B, long long C, long long D){
    cout << min(A, B) + min(C, D) << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
	int n;
	cin>>n;
	map<int,int>cnt1,cnt2;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		if(i&1)cnt1[a]++;
		else cnt2[a]++;
	}
	vector<pii>a,b;
	for(auto x:cnt1)a.pb({x.se,x.fi});
	for(auto x:cnt2)b.pb({x.se,x.fi});
	int mx = 0;
	sort(all(a),greater<pii>());
	sort(all(b),greater<pii>());
	if(a.size() == 1 && b.size() == 1&& a[0].se != b[0].se)mx = n;
	else if(a.size() == 1 && b.size() == 1 && a[0].se == b[0].se)mx = n/2;
	else{
		if(a[0].se != b[0].se)mx = a[0].fi+b[0].fi;
		if(a.size() > 1)mx = max(mx,a[1].fi+b[0].fi);
		if(b.size() > 1)mx = max(mx,a[0].fi+b[1].fi);
	}
	cout<<n-mx;
	
}


Measured memory_bytes: 8776
N = int(input())
A = list(map(int, input().split()))

cnt = [0] * (N+1)
for i in range(N):
    cnt[A[i]] += 1

nsum = [cnt[n]*(cnt[n]-1)//2 for n in range(N+1)]
SUM = sum(nsum)

for k in range(N):
    kadd = cnt[A[k]] - 1
    print(SUM - nsum[A[k]] + kadd*(kadd-1)//2)

Measured memory_bytes: 26140
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << "(" << p.first << " " << p.second << ")";
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  //os << v[0]; for (ll i = 1; i < (ll)v.size(); i++){ os << " " << v[i]; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::map< T, S > m)
{
  ll i = 0; for (auto p : m){ os << " [" << i << "]" << p.first << "->" << p.second; i++;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }



int main()
{
  ll N, M;
  std::cin >> N >> M;
  std::map<ll, bool> mdanger;
  for (ll i = 0; i < M; i++) {
    ll x;
    std::cin >> x;
    mdanger[x] = true;
  }

  // 0 段目の通り数
  std::vector<ll> dp(N+1, 0LL);
  dp[0] = 1;
  dp[1] = mdanger[1] ? 0 : 1;
  for (ll i = 2; i <= N; i++) {
    dp[i] = mdanger[i] ? 0 : (dp[i-1] + dp[i-2]) % MOD;
  }

  print(dp[N]);
  return 0;
}


Measured memory_bytes: 7296
import heapq

max_d = 10**9
dest_vecs = [(1,0), (0,1), (-1,0), (0, -1)]

def solve():
    H,W = map(int, input().split())
    
    S = [list(input()) for _ in range(H)]
    wall_num = sum(S_row.count('#') for S_row in S)
    
    # 最短経路を求める
    d = [[max_d]*W for _ in range(H)]
    d[0][0] = 0
    prev = [[None]*W for _ in range(H)]
    heap_queue = [(0,0,0)]
    while heap_queue:
        src_distance,y,x = heapq.heappop(heap_queue)
        for dy,dx in dest_vecs:
            ty = y+dy
            tx = x+dx
            if ty < 0 or ty >= H or tx < 0 or tx >= W or S[ty][tx] == '#':
                continue
            
            if d[ty][tx] > src_distance+1:
                d[ty][tx] = src_distance+1
                prev[ty][tx] = (y,x)
                heapq.heappush(heap_queue, (src_distance+1, ty, tx))
                
    ret = -1
    if d[H-1][W-1] < max_d:
        ret = H*W-d[H-1][W-1]-wall_num-1
    
    print(ret)
    
solve()

Measured memory_bytes: 9216
H,W,M = map(int,input().split())
h = []
w = []

for i in range(M):
    tmp1,tmp2 = map(int,input().split())
    h.append(tmp1)
    w.append(tmp2)

dic1 = {}
dic2 = {}

for i in h:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1

val1 = max(dic1,key=dic1.get)
ans = 0
ans +=dic1[val1]
for j in range(M):
    if h[j] != val1:
        if w[j] not in dic2:
            dic2[w[j]] = 1
        else:
            dic2[w[j]] +=1
if dic2:
    val2 = max(dic2,key=dic2.get)
    ans +=dic2[val2]


dic1 = {}
dic2 = {}

for i in w:
    if i not in dic1:
        dic1[i] = 1
    else:
        dic1[i] +=1
val1 = max(dic1,key=dic1.get)
ans1 = 0
ans1 +=dic1[val1]
for j in range(M):
    if w[j] != val1:
        if h[j] not in dic2:
            dic2[h[j]] = 1
        else:
            dic2[h[j]] +=1
if dic2:
    val2 = max(dic2,key=dic2.get)
    ans1 +=dic2[val2]
print(max(ans,ans1))

Measured memory_bytes: 223568
import os, sys, re, math

N = int(input())
A = list(map(int, input().split(' ')))
ret = [0 for _ in range(len(A))]
tmp = [0 for _ in range(len(A))]

init = sum(A) - 2 * sum([A[i] for i in range(1,N,2)])
ret[0] = init
for i in range(N):
    if i == 0:
        tmp[i] += ret[i] // 2
        tmp[i-1] += ret[i] // 2
    else:
        d = A[i-1] - tmp[i-1]
        if d < 0:
            break
        else:
            tmp[i] += d
            ret[i] += d * 2

print(' '.join(map(str,ret)))


Measured memory_bytes: 23596
public class Main {
  static class P implements Comparable<P> {
   final int t, d;
    P(int t, int d) {
     this.t = t;
      this.d = d;
    }
    public int compareTo(P p) {
     return d == p.d ? t - p.t : -d + p.d;
    }
  }
 public static void main(String...args) {
  final java.util.Scanner sc = new java.util.Scanner(System.in);
   final int N = sc.nextInt();
   final int K = sc.nextInt();
   final P[] ps = new P[N];
   for(int i = 0; i < N; i++)
     ps[i] = new P(sc.nextInt(), sc.nextInt());
   java.util.Arrays.sort(ps);
   long ans = 0;
   long sum = 0;
   final boolean[] used = new boolean[N + 1];
   final java.util.PriorityQueue<P> que = new java.util.PriorityQueue<>(java.util.Collections.reverseOrder());
   int k = 0;
   long x = 0;
   for(final P p : ps) 
   if(k < K){
     sum += p.d;
     k++;
     if(!used[p.t]) {
       x++;
       used[p.t] = true;
     } else
       que.offer(p);
     ans = Math.max(ans, sum + x * x);
   } else if(!que.isEmpty() && !used[p.t]) {
     sum -= que.poll().d;
     sum += p.d;
     used[p.t] = true;
     x++;
     ans = Math.max(ans, sum + x * x);
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 90276
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	long H;
	cin >> H;
	long W;
	cin >> W;
	long K;
	cin >> K;

	vector<string> vec;
	for (long i = 0; i < H; ++i)
	{
		string line;
		cin >> line;

		vec.push_back(line);
	}

	long long result = 0;
	long long NH = pow(2, H);
	long long NW = pow(2, W);
	for (long long i = 0; i < NH; ++i)
	{
		vector<bool> rows(H, false);
		long long tempN = i;
		long long currentRow = 0;
		while (tempN > 0)
		{
			rows[currentRow] = ((tempN % 2) > 0) ? 1 : 0;
			currentRow++;
			tempN /= 2;
		}
			
		for (long long j = 0; j < NW; ++j)
		{
			vector<bool> cols(W, false);
			long long tempN = j;
			long long currentRow = 0;
			while (tempN > 0)
			{
				cols[currentRow] = ((tempN % 2) > 0) ? 1 : 0;
				currentRow++;
				tempN /= 2;
			}

			vector<string> vecTemp = vec;
			for (long k = 0; k < H; ++k)
			{
				if (rows[k])
				{
					vecTemp[k].clear();
					for (long l = 0; l < W; ++l)
					{
						vecTemp[k].append("x");
					}
				}
			}

			for (long k = 0; k < W; ++k)
			{
				if (cols[k])
				{
					for (long l = 0; l < H; ++l)
					{
						vecTemp[l][k] = 'x';
					}
				}
			}

			//cout << i << "," << j << endl;
			long count = 0;
			for (long m = 0; m < H; ++m)
			{
				//cout << vecTemp[m] << endl;
				for (long n = 0; n < W; ++n)
				{
					if (vecTemp[m][n] == '#')
					{
						++count;
					}
				}
			}
			if (count == K)
			{
				++result;
			}
		}
	}

	cout << result << endl;
}

Measured memory_bytes: 4112
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int num,num2;
char l,r,ch;
int main()
{
	l=getchar(); num=1;
	while(ch=getchar(),ch<='z'&&ch>='a')
	{
		num++;
		r=ch;
	}
	num%=2;
	if(l==r) num2=1;
	else num2=0;
	if(num==num2) cout<<"Second";
	else cout<<"First";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
// other libs

signed main(int argc, char* argv[]) {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, 3) {
		if (s[i] == t[i])
			ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n = sc.read();
    let a: Vec<i32> = sc.vec(n);
    let res = a.into_iter().fold(0, |acc, x| {
        let mut y = x;
        let mut cnt = 0;
        while y % 2 == 0 {
            y /= 2;
            cnt += 1;
        }
        acc + cnt
    });
    println!("{}", res);
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int[] l = new int[n+2];
        l[0] = 0;
        for (int i = 1; i <= n; i++) {
            l[i] = sc.nextInt();
            l[i] += l[i-1];
        }
        l[n+1] = Integer.MAX_VALUE;
        int ans = 0;
        while(l[ans] <= x) {
            ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007 
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN


ll po(ll x,ll n){
    if(n==0) return 1;
    else if(n%2 == 0) return po((x*x)%MOD,n/2);
    else return (x*po((x*x)%MOD,(n-1)/2))%MOD;
}

void solve(){
    string s;
    cin >> s;
    ll n = s.length();
    for( int i=0;i<n/2;i++ ){
        if( s[i] != s[n-i-1] ){
            cout<<"No"<<endl;
            return;
        }
    }
    n = n/2;
    for( int i=0;i<n/2;i++ ){
        if( s[i] != s[n-i-1] ){
            cout<<"No"<<endl;
            return;
        }
    }
    for( int i=0;i<n/2;i++ ){
        if( s[n + 1 + i] != s[2*n - i] ){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
    return;
}

int main(){
    FAST;
    //init();
    ll t = 1;
    //cin>>t;
    while( t-- ) solve();
    return 0;
} 

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

int MOD = 1000000007;
long long F[3000], RF[3000];

long long Calc(long long X, long long Y) {
	if (Y == 0) return 1;
	if (Y % 2 == 0) {
		long long Z = Calc(X, Y / 2);
		return (Z * Z) % MOD;
	}
	return (X * Calc(X, Y - 1)) % MOD;
}

void init(int N) {
	F[0] = 1;
	F[1] = 1;
	RF[0] = 1;
	RF[1] = 1;
	for (int i = 2; i <= N; i++) {
		F[i] = (F[i - 1] * i) % MOD;
		RF[i] = Calc(F[i], MOD - 2);
	}
}

long long Comb(long long X, long long Y) {
	if (Y < 0 || X < Y) return 0;
	long long Ret = 1;
	Ret *= F[X];
	Ret *= RF[Y];
	Ret = Ret % MOD;
	Ret *= RF[X - Y];
	Ret = Ret % MOD;
	return Ret;
}

int main() {
	int N, K;
	cin >> N >> K;
	init(2500);
	int B = K, R = N - K;
	for (int i = 0; i < K; i++) {
		long long X = 1;
		X *= Comb(R + 1, i + 1);
		X *= Comb(B - 1, i);
		cout << X % MOD << endl;
	}
}

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

using namespace std;

int main(void)
{
    int N, M, X;
    int A[12][12];
    int C[12];
    cin >> N >> M >> X;
    for(int i = 0; i < N; i++){
        cin >> C[i];
        for(int j = 0; j < M; j++){
            cin >> A[i][j];
        }
    }
    
    long int ans = 1200001;
    int max = 1 << N;
    for(int mask = 0; mask < max; mask++){
        int a[12];
        int cost = 0;
        for(int i = 0; i < M; i++){
            a[i] = 0;
        }
        for(int i = 0; i < N; i++){
            if((mask >> i)&1){
                cost += C[i];
                for(int j = 0; j < M; j++){
                    a[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        for(int i = 0; i < M; i++){
            if(a[i] < X)    ok = false;
        }
        if(ok == true && ans > cost){
            ans = cost;
        } 
    }

    if(ans == 1200001) ans = -1;

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;

struct Edge {
    int src, dst, cost;
    Edge(int s, int d, int c = 1) : src(s), dst(d), cost(c) {}
    bool operator<(const Edge &e){ return cost < e.cost;}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

// O(|V|+|E|)log|V|)
void dijkstra(int s, Graph &g, vector<long long> &dist){
    using Info = pair<long long, int>;
    // init
    dist.assign(g.size(),INF);
    dist[s] = 0;
    vector<bool> used(g.size());
    priority_queue<Info, vector<Info>, greater<Info> > pq;
    pq.emplace(0, s);
    //
    // main
    while(!pq.empty()){
        long long d = pq.top().first;
        int v = pq.top().second;
        used[v] = true;
        pq.pop();
        if(dist[v] < d) continue;
        for(Edge e : g[v]){
            if(used[e.dst]) continue;
            if(dist[e.dst] > dist[v] + e.cost){
                dist[e.dst] = dist[v] + e.cost;
                pq.emplace(dist[e.dst], e.dst);
            }
        }
    }
    //
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N;cin>>N;
    int a,b,c;
    Graph g(N);
    REP(i,N-1){
        cin>>a>>b>>c;
        --a;--b;
        g[a].emplace_back(a,b,c);
        g[b].emplace_back(b,a,c);
    }
    int Q,K;cin>>Q>>K;
    --K;
    vector<ll> dist;
    dijkstra(K, g, dist);
    int x,y;
    REP(i,Q){
        cin>>x>>y;
        --x;--y;
        cout << dist[x] + dist[y] << '\n';
    }
    return 0;
}

Measured memory_bytes: 10804
#!/usr/bin/env python
# -*- coding: utf-8 -*-

S = input()  # 回転する方
T = input()

for i in range(len(S)):
    if S == T:
        print("Yes")
        break
    else:
        S = S[-1] + S[:-1]
        if S == T:
            print("Yes")
            break
else:
    print("No")


Measured memory_bytes: 2940
#E
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort()
p.reverse()
q.sort()
q.reverse()
r.sort()
r.reverse()
# print(p, q, r)
p = p[:x]
q = q[:y]
# print(p, q)
p.extend(q)
p.extend(r)
p.sort()
p.reverse()
# print(p[:(x + y)])
print(sum(p[:(x + y)]))


Measured memory_bytes: 23328
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))


def main():
    n,m = LI()
    a = [I() for _ in range(m)] + [inf]
    b = 0
    c = 1
    ai = 0
    for i in range(1,n+1):
        if a[ai] == i:
            ai += 1
            b,c = c,0
        else:
            b,c = c,b+c
            c %= mod

    return c


print(main())



Measured memory_bytes: 10072
import sys

while True:
    try:
        s=input()
        ans=s.split("=")[1]
        a,b=s.split("=")[0].split("+")
        for X in range(10):
            _a=a.replace("X",str(X))
            if str(int(_a))!=_a:
                continue
            _b=b.replace("X",str(X))
            if str(int(_b))!=_b:
                continue
            _ans=ans.replace("X",str(X))
            if str(int(_ans))!=_ans:
                continue
            if int(_a)+int(_b)==int(_ans):
                print(X)
                break
        else:
            print("NA")

    except EOFError:
        sys.exit(0)



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

int main(){
  long long n, k;
  cin >> n >> k;
  if (n <= k / 2) cout << n << endl;
  else if (n <= k) cout << k - n << endl;
  else cout << min(n % k, abs((n % k) - k)) << endl;
}

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

int64_t Q=1000000007;

int64_t si(int64_t x,int64_t y){
   int64_t A=x,B=y,C=1;//A,Bを入れる
  for(int64_t i=1;i<=B;i++){
    C=(C*i)%Q;
  }
  int64_t N=Q-2,a=1,b=0,c=1;
  while(N>0){
    a*=2;
    if(N%a!=0){
      N-=a/2;
      int64_t d=C;
      for(int j=0;j<b;j++){
        d=(d*d)%Q;
      }
      c=(c*d)%Q;
    }
    b++;
  }
  C=c;
  for(int i=0;i<B;i++){
    C=(C*(A-i))%Q;
  }//答はC
  return C;
}


int main() {
  int64_t N,M,K;
  cin>>N>>M>>K;
  int64_t Z=((((M*(M+1)*(M-1))/6)%Q)*(N*N)%Q)%Q;
  swap(N,M);
  Z+=((((M*(M+1)*(M-1))/6)%Q)*(N*N)%Q)%Q;
  Z=(Z*si(N*M-2,K-2))%Q;
  cout<<Z<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (int) (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (int) (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
const ll MOD = 998244353;
//constexpr ll MOD = 1000000007;

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




int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	ll n, k; cin >> n >> k;
	double log2k = log2(k);
	
	vector<vector<int>> a(n, vector<int>(log2k+2));
	rep(i,n) { cin >> a[i][0]; a[i][0]--;}

	rep(i,log2k+1) rep(j,n) {


		a[j][i+1] = a[a[j][i]][i];
	}

	int p = 0;
	for (int i = 0; i < log2k; ++i) {
		if (k >> i & 1) p = a[p][i];
	}

	cout << p + 1 << endl;
}

/*		*/

Measured memory_bytes: 58024
fn main() {
    let r = std::io::stdin();
    let mut sc = Scanner::new(r.lock());
    let v = sc.read_line();
    
    let n : usize = v[0].parse().unwrap();
    let x : usize = v[1].parse().unwrap();

    solve(n, x);
}

fn solve(n: usize, x: usize) {

    if 500 * n >= x {
        println!("{}", "Yes");
    } else {
        println!("{}", "No");
    }
}

pub struct Scanner<R: std::io::Read> (std::io::BufReader<R>);
 
impl<R: std::io::Read> Scanner<R> {
    pub fn new(r: R) -> Scanner<R> {
        Scanner (std::io::BufReader::new(r))
    }
 
    pub fn read_line(&mut self) -> Vec<String> {
        use std::io::BufRead;
        let mut line = String::new();
        self.0
            .read_line(&mut line)
            .unwrap();
 
        line.split_whitespace()
            .map(|b| b.to_string())
            .collect::<Vec<String>>()
    }
}

Measured memory_bytes: 4352
import sys, itertools
from collections import Counter

N = int(input())
A = list(map(int, sys.stdin.readline().rsplit()))
S = [0] + list(itertools.accumulate(A))

C = Counter(S)

res = 0
for v in C.values():
    res += v * (v - 1) // 2

print(res)


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

int main(){
    long long N, K;
    scanf("%lld%lld", &N, &K);
    long long ans;
    if(K % 2 == 0){
        long long ks = N / K;
        long long half = N / (K / 2) - ks;
        ans = ks * ks * ks + half * half * half;
    }else{
        long long ks = N / K;
        ans = ks * ks * ks;
    }
    
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end
bool visited[51];
bool sides[60][60];

void dfs(int v, int N){
    visited[v]=true;
    for(int v2=0; v2<N; v2++){
        if(sides[v][v2] == false) continue;
        if(visited[v2] == true) continue;
        dfs(v2, N);
    }
}

int main() {
    int N,M;
    int ans=0;
    cin >> N >> M;
    vector<unsigned int> A(M),B(M);

    rep(i,M){
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
        sides[A[i]][B[i]]=sides[B[i]][A[i]]=true;
    }

    for(int i=0; i<M; i++){
        // 未訪問にする
        for(int j=0; j<N; j++){
            visited[j]=false;
        }
        // 辺を1つ減らす
        sides[A[i]][B[i]]=sides[B[i]][A[i]]= false;

        bool bridge=false;
        // 0からスタート(どこからスタートしてもよい)
        dfs(0,N);
        for(int j=0; j<N; j++){
            // 訪問してないのであれば減らした辺は橋
            if(visited[j]==false) bridge = true;
        }

        if(bridge) ans++;
        // 辺を元に戻す
        sides[A[i]][B[i]]=sides[B[i]][A[i]]=true;
    }

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
a,b,c=map(int,input().split())
if a<=b<=c:
  print(a+b)
elif b<=c<=a:
  print(b+c)
elif c<=a<=b:
  print(c+a)
elif a<=c<=b:
  print(a+c)
elif b<=a<=c:
  print(b+a)
elif c<=b<=a:
  print(c+b)

Measured memory_bytes: 3060
import numpy as np

MOD = 10 ** 9 + 7
N=int(input())
A = [[int(x) for x in input().split()] for _ in range(N)]

dp = np.zeros(1<<N, dtype=np.uint64)
dp[0] = 1

for A_row in A:
    prev = dp.copy()
    dp = np.zeros_like(prev)
    for n,a in enumerate(A_row):
        if not a:
            continue
        x = 1 << n
        dp[x:] += prev[:-x]
    dp %= MOD

answer = dp[-1]
print(answer)


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

int main()
{
    int H;
    int R;
    cin >> H;
    cin >> R;
    int heigth = H + R;
    if(heigth == 0)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << ((heigth > 0) ? 1 : -1) << endl;
    }
    return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;
char re(int x) {

    return 96 + x;
}

template<typename TypeInt>
std::string Itoa(const TypeInt v)
{
    static const char table[] = "abcdefghijklmnopqrstuvwxyz";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= 26) {
        n--;
        ret += table[n % 26];
        n /= 26;
    }
    n--;
    if (n >= 0) {
        ret += table[n];
    }
    if (t.is_signed) {
        if (v < 0 && 26 == 10) ret += '-';
    }
    // 文字列の順番を逆にする
    std::reverse(ret.begin(), ret.end());

    return ret;
}


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

    cout << Itoa(n);

    return 0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
const int INF = 1e9;
const int MOD = 1e9+7;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int H, W; cin >> H >> W;
    vector<vi> a(H, vi(W)); REP(i, H) REP(j, W) cin >> a[i][j];
    
    int count = 0;
    vector<pair<int, int>> operation;
    REP(i, H)
    {
        if(i % 2 == 0)
        {
            for(int j = 0; j < W-1; j++)
            {
                if(a[i][j] % 2 == 1)
                {
                    count++;
                    operation.push_back(make_pair(i, j));
                    operation.push_back(make_pair(i, j+1));
                    a[i][j]--;
                    a[i][j+1]++;
                }
            }
            if(i != H-1 && a[i][W-1] % 2 == 1)
            {
                count++;
                operation.push_back(make_pair(i, W-1));
                operation.push_back(make_pair(i+1, W-1));
                a[i][W-1]--;
                a[i+1][W-1]++;
            }
        }
        else
        {
            for(int j = W-1; j >= 1; j--)
            {
                if(a[i][j] % 2 == 1)
                {
                    count++;
                    operation.push_back(make_pair(i, j));
                    operation.push_back(make_pair(i, j-1));
                    a[i][j]--;
                    a[i][j-1]++;
                }
            }
            if(i != H-1 && a[i][0] % 2 == 1)
            {
                count++;
                operation.push_back(make_pair(i, 0));
                operation.push_back(make_pair(i+1, 0));
                a[i][0]--;
                a[i+1][0]++;
            }
        }
    }

    cout << count << endl;
    REP(i, operation.size()/2)
    {
        cout << operation[i*2].first + 1 << " " << operation[i*2].second + 1<< " ";
        cout << operation[i*2+1].first + 1 << " " << operation[i*2+1].second + 1<< endl;
    }
}

Measured memory_bytes: 5236
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   String x = sc.next();
   String s = "0";
   for( int i = 0; i <= 2 ; i++){
     String y = x.substring(i, i+1);
	  if( y.equals(x.substring(i + 1, i + 2))){
        System.out.println("Bad");
        s = "1";
        break;
      }
    }
    if( s.equals("0")){
      System.out.println("Good");
    }
  }
} 

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007

int main(void){
    double h,a;
    cin >> h >> a;
    cout << ceil(h/a) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};
using namespace std;
typedef long long  ll;

/** Problem0178 : TETORIS **/
bool board[5][5000];

int main()
{
	int n, d, p, q;
	while (cin>>n, n) {
		rep(x, 5) rep(y, 5000) board[x][y]=false;
		rep(k, n) {
			cin >> d >> p >> q;
			q--;
			
			int dx=1, dy=0;
			if (d==2) {
				dx=0; dy=1;
			}
			
			vector<int> low;
			for (int ii=0; ii<p; ii++) {
				for (int i=4999; i>=0; i--) {
					if (board[q+ii][i]) {
						low.push_back(i+1);
						goto end;
					}
				}
				low.push_back(0);
			end:;
				if (d==2) break;
			}

			int m=0;
			rep(j, low.size()) {
				m = max(m, low[j]);
			}
			
			board[q][m]=true;
			rep(j, p-1) {
				q+=dx;m+=dy;
				board[q][m] = true;
			}
			
			rep(y, 5000) {
				bool flg = true;
				rep(x, 5) {
					flg &= board[x][y];
				}
				if (flg) {
					for (int yy=y; yy<5000; yy++) {
						for (int xx=0; xx<5; xx++) {
							board[xx][yy] = board[xx][yy+1];
						}
					}
					for (int xx=0; xx<5; xx++) {
						board[xx][4999] = false;
					}
					y--;
				}
			}
			/**
			rep(y, 10) {
				rep(x, 5) {
					cout << (board[x][9-y]?"#":"0");
				}
				cout << endl;
			}
			cout << endl; **/
		}
		int ans=0;
		rep(y, 5000) {
			rep(x, 5) {
				if (board[x][y])
					ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1236
N=int(input())
A,B=map(int,input().split())
p=list(map(int,input().split()))
No1=No2=No3=0

for i in p:
    if i <= A:
        No1 += 1
    elif i >= A and i <= B:
        No2 += 1
    else:
        No3 += 1

print(min(No1,No2,No3))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main(void) {

	// TODO: submit前にprintf-debugの削除確認！
	int a, b, k;
	cin >> a >> b >> k;

	for(int i=0; i<k; i++) {
		if(!(i%2)) {
			if(a%2) a--;
			b += a/2;
			a /= 2;
		} else {
			if(b%2) b--;
			a += b/2;
			b /= 2;
		}
	}
	cout << a << " " << b;
	return 0;
}



Measured memory_bytes: 256
from itertools import accumulate
from operator import add
 
N, K = map(int, input().split())
K2 = 2 * K
 
# Gss[i][j]: 「市松模様の黒い部分の右上のマス」が(i,j)のとき、満たせる要望の個数
Gss = [[0] * K2 for i in range(K2)]
 
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
 
    # 要望を「0<=x<2K, 0<=y<K, 'B'」に変換する
    if c == 'W':
        x -= K
    x, y = x % K2, y % K2
 
    if y >= K:
        x, y = (x - K) % K2, y - K
 
    # 要望を満たす「市松模様の黒い部分の右上のマス」に対して、+1する
    # （後で累積和を取る）
    Gss[x][y] += 1
    Gss[x][y - K] += -1
    if x != K:
        Gss[x - K][y - K] += 1
        Gss[x - K][y] += -1
    if x > K:
        Gss[0][y] += 1
        Gss[0][y - K] += -1
 
# 累積和を取る
Gss = [accumulate(Gs) for Gs in Gss]
Gss = [accumulate(Gs) for Gs in zip(*Gss)]
Gss = list(map(list, zip(*Gss))) # 転置
 
# 「K<=y<2K」の部分を、「0<=y<K」に重ね合わせる
Gss = [map(add, Gss[i][:K], Gss[i - K][K:]) for i in range(K2)]
 
# Gssの最大値が答え
print(max(map(max, Gss)))

Measured memory_bytes: 220532
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
 ll mod=998244353;
const ll inf = (ll)1e17;
const ld eps = 1e-12;
const ld PI = 3.14159265358979323846;
ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll powmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res%mod;}
long modInverse(long a) {return powmod(a, mod-2);}
ll my_rand(){ll a=rand();ll b=rand();return (a*RAND_MAX+1)+b;}


int main(){
    ios::sync_with_stdio(false);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0);
    cout.tie(0);
    int x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z<<endl;
    return 0;
    }


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

int main(){
        while(1){
        int w, h;
        cin >> h >> w;
        if(h == 0 && w == 0)break;

        for(int i = 1; i <= h; i++){
                for(int j = 1; j <= w; j++){
                        if((i + j) % 2 == 0)cout << '#';
                        else if((i + j) % 2 == 1)cout << '.';
                        }cout <<endl;
                }
        cout << endl;
        }

        return 0;
}

Measured memory_bytes: 1152
import sys
from copy import deepcopy

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def drop(H, W, G):
    for i in range(H - 1, 0, -1):
        for j in range(W):
            if G[i][j] == -1 and G[i - 1][j] != -1:
                k = i
                while k < H and G[k][j] == -1:
                    G[k][j], G[k - 1][j] = G[k - 1][j], -1
                    k += 1


def main():
    H, W, K = map(int, readline().split())
    G_init = [list(map(int, list(readline().strip()))) for _ in range(H)]

    ans = 0
    for i in range(H):
        for j in range(W):
            G = deepcopy(G_init)
            G[i][j] = -1
            drop(H, W, G)

            current_ans = 0
            step = 0
            while True:
                score = 0
                for row in G:
                    seq = [[row[0], 1]]
                    for n in row[1:]:
                        if n == seq[-1][0]:
                            seq[-1][1] += 1
                        else:
                            seq.append([n, 1])
                    idx = 0
                    for n, c in seq:
                        if n != -1 and c >= K:
                            score += n * c
                            row[idx : idx + c] = [-1] * c
                        idx += c

                if score == 0:
                    break

                current_ans += score * pow(2, step)
                step += 1
                drop(H, W, G)

            if current_ans > ans:
                ans = current_ans

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 56540
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

void dfs ( int now, int n, vector<vector<int>> &g, vector<bool> flg, int &ans ) {
    flg[now] = true;
    int cnt = 0;
    rep(i, n) {
        if ( flg[i] ) ++cnt;
    }
    if ( cnt == n ) {
        ++ans;
        return;
    }
    for ( auto v: g[now] ) {
        if ( flg[v] ) continue;
        dfs(v, n, g, flg, ans);
    } 
    return;
}

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    int ans = 0;
    vector<bool> flg(n, false);
    dfs(0, n, g, flg, ans);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  N = int(input())
  A = [list(map(int, input().split())) for _ in range(N)]
  mod = 10**9+7
  dp = [[0]*(1<<N) for _ in range(N+1)]
  dp[N][0] = 1
  for i in range(N-1,-1,-1):
    for com in combinations(range(N),N-i):
      S = 0
      for k in com:
        S += 1<<k
      for j in com:
        if A[i][j]==1:
          dp[i][S] += dp[i+1][S-(1<<j)]
          dp[i][S] %= mod
  return dp[0][-1]
print(solve())

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



using ll=long long;
int main(){
	
	
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
	#endif
	
	ll h,a,n;
	cin>>h>>n;
	ll arr[n];
	ll sum=0;
	for(ll i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	if(sum>=h)cout<<"Yes";
	else cout<<"No";
	return 0;
	
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
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 n,m,a[1024]={},ans=0;
signed main(){
  while(1){
    cin >> n >> m;
    ans=0;
    if(n==0 && m==0)break;
    for(int i=0;i<n;i++){
      cin >> a[i];
    }
    for(int i=0;i<n-1;i++){
      for(int j=i+1;j<n;j++){
        if(a[i]+a[j]<=m) chmax(ans,a[i]+a[j]);
      }
    }
    if(ans==0) cout << "NONE"<< endl;
    else cout << ans << endl;
  }
  return 0;
}



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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  int N; cin>>N;
  map<int,int> m;
  rep(i,N){
    int a; cin>>a;
    if(m.count(a))m[a]++;
    else m[a]=1;
  }
  int sec = 0;
  for(auto p : m){
    int count = p.second;
    if(count%2==0)sec++;
  }  
  int res = m.size();
  if(sec%2==1||sec==2)res--;
  cout<<res<<endl;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
const int N = 1e5+5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-6;
struct node{
	double x,y;
}g[N];
int main()
{
	int n,x,y;
	cin>>n>>x>>y;
	vector<ll>v(n);
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			ll d=min(j-i,abs(i-x)+1+abs(j-y));
			v[d]++;
		}
	}
	for(int i=1;i<n;i++)cout<<v[i]<<endl;
	return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

void solve() {
    ll n;
    cin>>n;
    vector<ll> temp(4,0);
    string inp;
    for(ll i=0; i<n; i++)
    {
        cin>>inp;
        if(inp == "AC")
            temp[0]++;
        if(inp == "WA")
            temp[1]++;
        if(inp == "TLE")
            temp[2]++;
        if(inp == "RE")
            temp[3]++;
    }
    cout<<"AC x "<<temp[0]<<endl;
    cout<<"WA x "<<temp[1]<<endl;
    cout<<"TLE x "<<temp[2]<<endl;
    cout<<"RE x "<<temp[3]<<endl;
    return;
}


int main()
{
    int testcases=1;
    // cin>>testcases;
    while(testcases--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3628
/*
Author: Sagar Gupta
E mail: sagar.june97p@gmail.com
*/

#pragma comment(linker, "/STACK:268435456")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl ("\n")
#define deb(n) cerr << #n << " = " << (n) << '\n'
#define PI (3.14159265358979323846264338)
#define ordered_set tree<int, null_type, std::less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define MOD (1000000007ll)
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed;
    cout.precision(10);
    // Those who forgive themselves, and are able to accept their true nature...THEY ARE THE STRONG ONES

    int n;
    cin >> n;
    long long arr[n];
    long long sum = 0ll;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
        sum %= MOD;
    }
    long long sol = 0ll;
    for (int i = 0; i < n; i++)
    {
        sum = (sum % MOD - arr[i] % MOD + MOD) % MOD;
        sol += arr[i] * sum % MOD;
        sol %= MOD;
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 5204
#include <iostream>
#include <algorithm>
#include <complex>
using namespace std;
typedef complex<int> P;
const int N = 8;

const P s[7][4] = {{P(0,0),P(1,0),P(0,1),P(1,1)},
		   {P(0,0),P(0,1),P(0,2),P(0,3)},
		   {P(0,0),P(1,0),P(2,0),P(3,0)},
		   {P(1,0),P(0,1),P(1,1),P(0,2)},
		   {P(0,0),P(1,0),P(1,1),P(2,1)},
		   {P(0,0),P(0,1),P(1,1),P(1,2)},
		   {P(1,0),P(2,0),P(0,1),P(1,1)}};

char g[N][N];

int main() {
  while(cin >> g[0][0]) {
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < N; ++j) {
	if(!i&&!j) continue;
	cin >> g[i][j];
      }
    }
    int res = -1;
    for(int n = 0; n < 7; ++n) {
      bool flag = true;
      for(int i = 0; i < N; ++i) {
	for(int j = 0; j < N; ++j) {
	  for(int k = 0; k < 4; ++k) {
	    int ni = i + s[n][k].imag();
	    int nj = j + s[n][k].real();
	    if(ni < 0 || ni >= N ||
	       nj < 0 || nj >= N ||
	       g[ni][nj] != '1') {
	      k = (1<<28);
	    }
	    if(k+1 == 4) {
	      res = n;
	      n = i = j = k = (1<<28);
	    }
	  }
	}
      }
    }
    cout << (char)(res+'A') << endl;
  }
  return 0;
}

Measured memory_bytes: 1132
//Name : Rupa Dey
  //Date : 19 August 2020
//joi sri gour hori gobindo...
//gobindo ja hobe vlor jonnoi hobe..
#include<bits/stdc++.h>
#define ll long long
#define d double
#define ld long double
#define vi vector<int>
#define vul vector<ull>
#define vl vector<ll>
#define pb push_back
#define si set<int>
#define sl set<ll>
#define yes cout<<"YES\n"<<endl
#define no cout<<"NO\n"<<endl
#define ys cout<<"Yes\n"<<endl
#define n cout<<"No\n"<<endl
#define test cin>>t; while(t--)
#define for(i,a,n) for(i=a;i<n;i++)
#define mp make_pair
#define ft first
#define sc second
#define gap " ";
#define MAX 9999999
#define MOD 1000000007
#define nd endl
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    string str;
    int cnt=0,i;
    cin>>str;
     if(str[0]=='R' && str[1]=='R' && str[2]=='R') cnt=3;
     else if((str[0]=='R' && str[1]=='R') ||(str[1]=='R' && str[2]=='R')) cnt=2;
     else if((str[0]=='R' && str[1]=='S')||(str[1]=='S' && str[2]=='R')) cnt=1;
     else if((str[0]=='S' && str[1]=='R')||(str[1]=='R' && str[2]=='S')) cnt=1;

    cout<<cnt<<endl;

}
//hare krishna...
//hey gobindo kripa koro......
//only gobindo exists..^..


Measured memory_bytes: 3660
#include "bits/stdc++.h"

int main() {

    int N, M;
    std::cin >> N >> M;
    int prev = 0;
    int prevnum = 2;
    int64_t ans = 1;
    std::vector<int> a(M);
    for (auto& v : a)std::cin >> v;
    a.push_back(N + 1);
    std::vector<int64_t> dp(N+1, 1);
    for (auto& v : a) {
        int num = v - prev;

        if (num == 0) {
            ans = 0;
            break;
        }

        for (int i = prevnum; i < num; ++i)dp[i] = (dp[i - 2] + dp[i - 1]) % 1000000007;
        ans = (ans * dp[num - 1]) % 1000000007;

        prev = v + 1;
        prevnum = std::max(num, 2);
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 1400
/**
 *      ABC 96 A
 *      author  : kyomukyomupurin
 *      created : 2018/08/23
**/

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

int main(){
    int a, b;
    cin >> a >> b;
    a > b ? cout << a - 1 : cout << a;

    return 0;
    
}


Measured memory_bytes: 256
/************************************************************
	> File Name: f.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Mon 23 Dec 2019 12:04:11 AM CST
************************************************************/

#pragma GCC optimize(2)
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
//#include <unordered_map>
#define lowbit(x) (x&-x)
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXM = 2e5+5;
const int MOD = 1e9+7;
const int dir[4][2] = {1,0,-1,0,0,1,0,-1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
struct Edge{
	int v,next;
}edge[MAXN<<1];
int head[MAXN],tot;
void add_edge(int u,int v){
	edge[++tot].v = v;
	edge[tot].next = head[u];
	head[u] = tot;
}
int dep[MAXN];
int fa[MAXN];
void dfs(int u,int pre){
	fa[u] = pre;
	for(int i = head[u];i;i = edge[i].next){
		int v = edge[i].v;
		if(v==pre)
			continue;
		dfs(v,u);
		dep[u] = max(dep[u],dep[v]+1);
	}
}
int main(void){
	IOS;
	int n, u, v;
	cin >> n >> u >> v;
	for(int i = 1;i < n;i++){
		int x, y;
		cin >> x >> y;
		add_edge(x,y);
		add_edge(y,x);
	}
	dfs(v,-1);
	int dis = 0,rt = u;
	while(rt != v)
		dis++,rt = fa[rt];
	dis = (dis-1) >> 1;
	while(dis--)
		u = fa[u];
	int res = dep[u];
	while(u != v)
		res++,u = fa[u];
	cout << res-1 << endl;
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N,tmp,M=0;
vi As, bxs, states, divs, ans;
bool flag;

vi enum_div(int n)//nの約数を列挙
{
	vi ret;
	for(int i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

void solve(){
    bxs.resize(N+1);
    states.resize(N+1);

    for(int i = N; i >= 1; --i){
        flag = true;
        int val, quo;

        if(i > N/2){
            val = As[i];
        } else {
            quo = states[i] % 2;
            if(quo == As[i])
                val = 0;
            else
                val = 1;
        }

        bxs[i] = val;

        divs = enum_div(i);

        rep(i, divs.size()){
            states[divs[i]] += val;
        }
    }

    for(int i = 1; i < bxs.size(); ++i){
        M += bxs[i];
        if(bxs[i]) ans.push_back(i);
    }

    cout << M << endl;
    rep(i,ans.size()) cout << ans[i] << endl;

}

int main(){
    cin >> N;

    As.push_back(0); //1-indexにする

    rep(i,N){
        cin >> tmp;
        As.push_back(tmp);
    }

    solve();
}


Measured memory_bytes: 4212