akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int							key    = 0;
		int							len    = 0;
		int[]						team   = null;
		String						number = null;
		HashMap<Integer, Integer>	teams  = new HashMap<Integer, Integer>();
		ArrayList<Integer>			points = new ArrayList<Integer>();

		while ((team = parseTeam()) != null) {
			teams.put(team[0], team[1]);
			if (!points.contains(team[1])) {
				points.add(team[1]);
			}
		}

		len = points.size();
		Collections.sort(points);

		while ((number = parseStdin()) != null) {
			key = Integer.parseInt(number);
			System.out.println(len - points.indexOf(teams.get(key)));
		}
	}

	private static int[] parseTeam() {
		int[]		team  = null;
		String		stdin = null;
		String[]	split = null;

		if ((stdin = parseStdin()) != null) {
			if (!stdin.equals("0,0")) {
				team    = new int[2];
				split   = stdin.split(",");
				team[0] = Integer.parseInt(split[0]);
				team[1] = Integer.parseInt(split[1]);
			}
		}
		
		return team;
	}

	private static String parseStdin() {
		String	stdin = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					stdin = line;
				}
			}
		}
		catch (IOException e) {}

		return stdin;
	}
}

Measured memory_bytes: 16928
from scipy.sparse.csgraph import floyd_warshall
import numpy as np


def main():
    INF = 10**12
    N = int(input())
    A = [list(map(int, input().split(' '))) for _ in range(N)]
    wf = floyd_warshall(A)
    for i in range(N):
        A[i][i] = INF
        wf[i][i] = INF
    ans = 0
    for i in range(N):
        for j in range(N):
            if A[i][j] != wf[i][j]:
                print(-1)
                return
            if wf[i][j] < np.min(wf[i] + wf[j]):
                ans += wf[i][j]
    print(int(ans // 2))


if __name__ == '__main__':
    main()

Measured memory_bytes: 22600
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// Atcoder 086A
      
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a%2==1 && b%2==1) {
			System.out.println("Odd");
		}else {
			System.out.println("Even");
		}
	}
}


Measured memory_bytes: 24020
"""
Given N, D, A, N means no. of monsters, D means distances of bombs, A attack of the bombs

Find the minimum of bombs required to win.

Each monster out of N pairs - pair[0] = position, pair[1] = health

hashmap[i] = H

pref

"""
from collections import deque

mod = 1e9+7
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    INF = 1e9 + 7
    N, D, A = [int(x) for x in raw_input().split()]
    D *= 2
    monsters = []
    #m = {}
    change = [0 for _ in range(N)]
    for _ in range(N):
        pos, health = [int(x) for x in raw_input().split()]
        #m[pos] = m.get(pos, 0) + health
        #smallest_x = min(smallest_x, pos)
        #biggest_x = max(biggest_x, pos)
        health = (health + A - 1) // A
        #print(health)
        
        monsters.append([pos, health])    
    """
    remain_attack = 0
    ans = 0
    for cur in range(smallest_x, biggest_x+1):
        if cur in m and m[cur] > remain_attack:
            remained_health = m[cur] - remain_attack
            times = remained_health / A if remained_health % A == 0 else remained_health // A + 1
            attack = times * A
            pref_sum[cur + D] = pref_sum.get(cur + D, 0) - attack
            remain_attack += attack
            ans += times
        remain_attack += pref_sum.get(cur, 0)
            
    """   
            
    monsters.sort(key = lambda x : x[0])
    
    #remain_attacks_queue = deque([])
    
    #remain_attack = 0
    running_sum = 0
    
    ans = 0
    
    for i in range(N):
        pos, health = monsters[i]
        running_sum += change[i]
        #print(health, running_sum)
        my_health = health - running_sum
        if my_health <= 0:
            continue # Already killed
        
        # Find the last monster hit by this range
        lo = i+1
        hi = N-1
        ok = -1
        while lo <= hi:
            mid = (lo + hi) // 2
            #print(mid, monsters[mid])
            if monsters[mid][0] <= pos + D:
                ok = mid
                lo = mid + 1
            else:
                hi = mid - 1
        
        if ok != -1:
            running_sum += my_health
        if ok + 1 < N:
            change[ok+1] -= my_health
            
            
        ans += my_health
        
                
        """
        while len(remain_attacks_queue) and monster[0] - D > remain_attacks_queue[0][0]:
            remain_attack -= remain_attacks_queue.popleft()[1]
        if remain_attack < monster[1]:
            remained_health = monster[1] - remain_attack
            times = remained_health / A if remained_health % A == 0 else remained_health // A + 1
            #print(times)
            attack = times * A
            remain_attacks_queue.append([monster[0], attack])
            ans += times
            remain_attack += attack
        """
    
        
    print(ans)
    

main()

Measured memory_bytes: 72396
n=int(input())
adj=[]
for i in range(n):
	a=list(map(int,input().split()))
	for j in range(2,len(a)):
		a[j]-=1
	adj.append(a[2:])
visit_time1=[0]*n
visit_time2=[0]*n
visited=[0]*n
def dfs(now):
	global time
	visit_time1[now]=time
	time+=1
	for next in adj[now]:
		if not visited[next]:
			visited[next]=True
			dfs(next)
	visit_time2[now]=time
	time+=1
time=1
for i in range(n):
	if not visited[i]:
		visited[i]=True
		dfs(i)
for i in range(n):
	print(i+1,visit_time1[i],visit_time2[i])


Measured memory_bytes: 5648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
struct node{
	int h,pos;
	ll a;
}e[200005];
bool cmp(node x,node y)
{
	return x.h<y.h;
}
ll t[800005],tag[800008],f[200005],ans;
void pushup(int x)
{
	t[x]=max(t[x+x],t[x+x+1]);
}
void pushdown(int x)
{
	t[x+x]=max(t[x+x],tag[x]);
	t[x+x+1]=max(t[x+x+1],tag[x]);
	tag[x+x]=max(tag[x+x],tag[x]);
	tag[x+x+1]=max(tag[x+x+1],tag[x]);
	tag[x]=0;
}
void build(int x,int l,int r)
{
	if(l==r)
	{
		t[x]=0;
		return;
	}
	int mid=(l+r)>>1;
	build(x+x,l,mid);
	build(x+x+1,mid+1,r);
	pushup(x);
}
void edit(int x,int l,int r,int L,int R,ll val)
{
	if(l>R||r<L) return;
	if(l>=L&&r<=R)
	{
		t[x]=max(t[x],val);
		tag[x]=max(tag[x],val);
		return;
	}
	int mid=(l+r)>>1;
	pushdown(x);
	edit(x+x,l,mid,L,R,val);
	edit(x+x+1,mid+1,r,L,R,val);
	pushup(x);
}
ll query(int x,int l,int r,int L,int R)
{
	if(l>R||r<L) return 0;
	if(l>=L&&r<=R)
	{
		return t[x];
	}
	int mid=(l+r)>>1;
	pushdown(x);
	pushup(x);
	return max(query(x+x,l,mid,L,R),query(x+x+1,mid+1,r,L,R));
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&e[i].h);
	for(int i=1;i<=n;i++) scanf("%lld",&e[i].a);
	for(int i=1;i<=n;i++) e[i].pos=i;
	sort(e+1,e+1+n,cmp);
	build(1,1,n);
	//puts("win");
	for(int i=1;i<=n;i++)
	{
		f[i]=query(1,1,n,1,e[i].pos)+e[i].a;
		//printf("f(%d)=%d\n",i,f[i]);
		edit(1,1,n,e[i].pos,n,f[i]);
	}
	for(int i=1;i<=n;i++) ans=max(ans,f[i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 17408
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;

int main() {
  int N,M,a[1000],b[1000],c[1000]={0};
  cin>>N>>M;
  for (int i(0);i<M;i++){
    cin>>a[i]>>b[i];
    for (int j(0);j<b[i];j++){
      int l;
      cin>>l;
      c[i]+=(int)pow(2,l-1);
    }
  }
  int inf = 1e9;
  int ni=(int)(pow(2,N));
  vector<vector<int>> dp(M,vector<int>((int)pow(2,N)+1, inf));
  dp[0][0]=0;
  dp[0][c[0]]=a[0];
  //c[i] 金庫iを開けることができる鍵の集合
  for (int i(0);i<M-1;i++){
    for (int j(0);j<=(int)pow(2,N);j++){
      if (dp[i][j]!=inf){
        dp[i+1][j|c[i+1]]=min(dp[i+1][j|c[i+1]],dp[i][j]+a[i+1]);
        dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      }
    }
  }
  for (int j(ni);j>=0;j--){
    for (int i(0);i<M;i++){
      //cout << dp[i][j] << " ";
    }
    //cout << endl;
  }
  cout << (dp[M-1][(int)(pow(2,N)-1)]==inf? -1 : dp[M-1][(int)(pow(2,N))-1]) << endl;
  return 0;
}


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

#define ll long long
#define sd(x) scanf("%d", &(x))
#define pii pair<int, int>
#define F first
#define S second
#define all(c) ((c).begin()), ((c).end())
#define sz(x) ((int)(x).size())
#define ld long double

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<", "<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	for(int i = 0;i < (int)v.size(); i++){
		if(i)os<<", ";
		os<<v[i];
	}
	os<<"}";
	return os;
}

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 200005;
int A[N], B[N];
int p[4] = {1, 2, 3, 0};
map<char, int> dirs = {{'L', 0}, {'U', 1}, {'R', 2}, {'D', 3}};

int get(int pos, int w, int n){
	int L = 1, R = w;
	for(int i = n - 1; i >= 0; i--){
		int h1 = A[i] % 2 == 0 ? (A[i] - 1) : 0;
		int h2 = B[i] % 2 == 0 ? B[i] - 1 : 0;
		int L1 = L, R1 = R;
		if(h1 == 1 && h2 == -1){
			R = min(R, w - 1);
		} else if(h1 == -1 && h2 == 1){
			L = max(L, 2);
		} else if(h1 == 1 && h2 == 1){
			L--; R--; L = max(L, 1);
		} else if(h1 == -1 && h2 == -1){
			L++; R++;
			R = min(R, w);
		} else if(h1 == 0 && h2 == 1){
			L--; L = max(L, 1);
		} else if(h1 == 0 && h2 == -1){
			R++; R = min(R, w);
		} else if(h1 == 1 && h2 == 0){
			R--;
		} else if(h1 == -1 && h2 == 0){
			L++;
		}
		if(L > R){
			return 1;
		}
	}
	return !(pos >= L && pos <= R);
}

void rot(int n){
	for(int i = 0; i < n; i++) A[i] = p[A[i]];
	for(int i = 0; i < n; i++) B[i] = p[B[i]];
}

char s[N], t[N];
int main(){
	int H, W, n, sr, sc; sd(H); sd(W); sd(n); sd(sr); sd(sc);
	scanf("%s", s); scanf("%s", t);
	
	for(int i = 0; i < n; i++){
		A[i] = dirs[s[i]];
		B[i] = dirs[t[i]];
	}
	
	if(get(sc, W, n)){
		printf("NO\n");
		return 0;
	}

	rot(n);

	if(get(H - sr + 1, H, n)){
		printf("NO\n");
		return 0;
	}

	printf("YES\n");
}

Measured memory_bytes: 5608
#include<stdio.h>
#include<string.h>

int main(){

	int min=200000;
	int max=0;
	int s=0;
	int len=0;
	char S[200000];


	scanf("%s",S);
	len = strlen(S);

	for(int i=0; i<len; i++){
		if( S[i] == 'A' ){
			if( i < min ){
				min = i;
			}
		}else if( S[i] == 'Z' ){
			if( max < i ){
				max = i;
			}
		}
	}

	printf("%d",max-min+1);

	return 0;


}

Measured memory_bytes: 384
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include <limits.h>
#include <iomanip>
#include <stack>

using namespace std;
using namespace boost::multiprecision;

//重みなしのグラフのクラス
class graph {
public:
	int N;
	vector<set<int>>* E;
	graph(int);
	graph();
	void constructor(int);
	~graph();
	void addEdge(int, int);
	void removeEdge(int, int);
	bool isConnected(int, int);
};

graph::graph(int n) {
	constructor(n);
}

graph::graph() {
	N = 0;
}

graph::~graph() {
	delete E;
}

void graph::constructor(int n) {
	N = n;
	E = new vector<set<int>>;
	E->resize(N);
}

void graph::addEdge(int a, int b) {
	E->at(a).insert(b);
}

void graph::removeEdge(int a, int b) {
	auto itr = E->at(a).find(b);
	if (itr != E->at(a).end())E->at(a).erase(itr);
}

bool graph::isConnected(int a, int b) {
	return (E->at(a).find(b) != E->at(a).end());
}

int N;
graph G;
class ele {
public:
	int cur, col;
	ele(int c1,int c2):cur(c1),col(c2){}
};

vector<int> res;
queue<ele> q;
void solve() {
	cin >> N;
	G.constructor(2*N);
	int next = N;   //次追加する頂点番号
	for (int n = 0; n < N-1; n++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		if (w % 2 == 0) {
			G.addEdge(u, next);
			G.addEdge(next, u);
			G.addEdge(v, next);
			G.addEdge(next, v);
			next++;
		}
		else {
			G.addEdge(u, v);
			G.addEdge(v, u);
		}
	}
	res.resize(next);
	for (int i = 0; i < next; i++)res[i] = -1;   //未決定
	q.push(ele(0,0));
	while (!q.empty()) {
		ele e = q.front();
		q.pop();
		if (res[e.cur] == 1-e.col)
			return;
		if (res[e.cur] != -1) continue;
		res[e.cur] = e.col;
		for (auto itr = G.E->at(e.cur).begin(); itr != G.E->at(e.cur).end(); itr++) {
			q.push(ele(*itr, 1 - e.col));
		}
	}
	for (int n = 0; n < N; n++)cout << res[n] << endl;
	return;
}

Measured memory_bytes: 24448
import sys
N,M = map(int, input().split())
num = ['B'] * N
for _ in range(M):
    s,c = map(int, input().split())
    if num[s-1] != 'B' and num[s-1] != c:
        num.append('No')
    else:
        num[s-1] = c

if N == 1 and num[0] == 'B':
    num[0] = 0
    
if N > 1 and num[0] == 'B':
    num[0] = 1

if 'No' in num:
    print(-1)
    sys.exit()
elif N > 1 and num[0] == 0:
    print(-1)
    sys.exit()
    
for i in range(1,N):
    if num[i] == 'B':
        num[i] = 0

for i in range(N):
    num[i] = str(num[i])

print(''.join(num))

Measured memory_bytes: 3064
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.math.BigDecimal;

public class Main {
    public static Scanner sc;
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        while (sc.hasNext()) {
            ArrayList<Integer> list = new ArrayList<>();
            int n = sc.nextInt();
            if (n == 0) break;
            
            for (int i = 0; i < n; i++) {
                list.add(sc.nextInt());
            }
            
            Collections.sort(list);
            
            BigDecimal sum = new BigDecimal(0);
            for (int i = 1; i <= n; i++) {
                sum = sum.add(new BigDecimal(list.get(i-1)).multiply(new BigDecimal(n-i)));
            }
            
            System.out.println(sum.toString());
        }
    }
}

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

int s[110];

int main(){
	int n, ans=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> s[i];
		ans += s[i];
	}
	if(ans%10 != 0) cout << ans << endl;
	else {
		sort(s, s+n);
		for(int i=0; i<n; i++){
			if(s[i]%10 != 0){
				ans -= s[i];
				break;
			}
		}
		if(ans%10==0) cout << 0 << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var d = int.Parse(Console.ReadLine());
            Console.WriteLine("Christmas");

            while (25 - d > 0)
            {
                Console.WriteLine(" Eve");
                d++;
            }


        }
    }
}


Measured memory_bytes: 11092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

/**
 * Property Distribution
 */
public class Main {

	static char DISTRIBUTED = '\0';
	static Queue<Integer> xs, ys;
	static int count;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0 0")) {

			int h = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			int w = Integer.parseInt(line.substring(line.indexOf(' ') + 1));

			// read in.
			char[][] prop = new char[h + 2][w + 2];
			for (int i = 1; i < h + 1; ++i) {
				line = br.readLine();
				for (int j = 1; j < w + 1; ++j) {
					prop[i][j] = line.charAt(j - 1);
				}
			}

			// solve
			xs = new ArrayDeque<Integer>();
			ys = new ArrayDeque<Integer>();
			count = 0;
			for (int i = 1; i < h + 1; ++i) {
				for (int j = 1; j < w + 1; ++j) {
					if (prop[i][j] != DISTRIBUTED) {
						char fruit = prop[i][j];
						xs.add(i);
						ys.add(j);
						while (!xs.isEmpty() && !ys.isEmpty()) {
							distribute(prop, fruit);
						}
						++count;
					}
				}
			}

			// print
			System.out.println(count);
		}
	}

	static void distribute(char[][] prop, char fruit) {

		final int V[] = { 1, -1, 0, 0 };
		final int H[] = { 0, 0, 1, -1 };

		int x, y;
		x = xs.poll();
		y = ys.poll();

		if (prop[x][y] == fruit) {

			prop[x][y] = DISTRIBUTED;

			for (int i = 0; i < 4; ++i) {
				int xv, yh;
				xv = x + V[i];
				yh = y + H[i];
				if (prop[xv][yh] == fruit) {
					xs.offer(xv);
					ys.offer(yh);
				}
			}
		}
	}
}

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

int main(){
  int n,x,array[100000],kyori[100000],ans=0;
  cin>>n>>x;
  for(int i=0;i<n;i++){
    cin>>array[i];
    kyori[i]=abs(array[i]-x);
  }
  for(int i=0;i<n;i++){
    ans=__gcd(ans,kyori[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}

a=str(input())
print(a.count("+")- a.count("-"))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 998244353;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

const int MAX = 500000;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll pow_mod(ll n, ll k, ll mod)
{
    if (k == 0)
    {
        return 1;
    }
    else if (k % 2 == 1)
    {
        return pow_mod(n, k - 1, mod) * n % mod;
    }
    else
    {
        ll t = pow_mod(n, k / 2, mod);
        return t * t % mod;
    }
}

ll modinv(ll a, ll m)
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

ll kaijyo(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    return n * kaijyo(n - 1) % MOD;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll m, n, k;
    cin >> m >> n >> k;
    m %= MOD;
    // n %= MOD;
    ll ans = pow_mod(m, n, MOD);
    ll b[k] = {};
    ll com[k] = {};
    com[0] = 1;
    ll in[k] = {};
    COMinit();
    for (ll i = 1; i < k; i++)
    {
        in[i] = modinv(i, MOD);
        com[i] = com[i - 1] * ((m + 1 - i) % MOD) % MOD;
        (com[i] *= in[i]) %= MOD;
    }
    for (ll i = 1; i < k; i++)
    {
        b[i] = pow_mod(i, n, MOD);
        for (ll j = 1; j < i; j++)
        {
            (b[i] += MOD - (COM(i, j) * b[j]) % MOD) %= MOD;
        }
    }
    ll t = 0;
    for (ll i = 1; i < k; i++)
    {
        (t += (com[i] * b[i]) % MOD) %= MOD;
    }

    (ans += MOD - t) %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 14952
N,M = map(int,input().split())

def fa(N):
    p = 1
    for i in range(1,N+1):
        p = (p * i)%(10**9+7)
    return p
if abs(N-M) > 1:
    print(0)
elif abs(N-M) == 1:
    print((fa(N)*fa(M))%(10**9+7))
else:
    print((2*fa(N)*fa(M))%(10**9+7))


Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

long long N, M, dp[40][100000], mod = 1000000007, divi[100000];

long long inv[1<<20]; // ith index will store (1/i)%mod
long long finv[1<<20]; // ith index will store (1/i!)%mod
long long fact[1<<20]; // ith index will store (i!)%mod

void populate() {
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;

    for(int i = 2;i <= N;i++) {
        fact[i] = (i*fact[i-1])%mod;
        inv[i] = mod-((inv[mod%i]*(mod/i))%mod);
        finv[i] = (finv[i-1]*inv[i])%mod;
    }
}

int main() {
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);

  cin >> N >> M;
  if(M == 1) {
    cout << 1 << endl;
    return 0;
  }

  int Y = 0;
  for(long long i = 1; i*i <= M;i++) {
    if(i*i == M) {
      divi[Y++] = i;
      continue;
    }

    if(M % i == 0) {
      divi[Y++] = i;
      divi[Y++] = M/i;
    }
  }

  sort(divi, divi + Y);
  for(int i = 1;i < Y;i++) dp[1][i] = 1;

  for(int i = 2;i <= 30;i++) {
    for(int j = 1;j < Y;j++) {
      for(int k = 1;k < j;k++) {
        if(divi[j] % divi[k] == 0) {
          dp[i][j] = (dp[i][j] + dp[i-1][k]) % mod;
        }
      }
    }
  }

  populate();

  long long ans = 0;
  for(int i = 1;i <= min(1LL*30, N);i++) {
    ans = (ans + ((((dp[i][Y-1]*fact[N]) % mod)*((finv[i]*finv[N-i]) % mod)) % mod)) % mod;;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 29696
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll r,d,x;cin >> r >> d >> x;
    for (int i = 0; i < 10; ++i)
    {
    	x=r*x-d;cout << x << "\n";
    }
    }

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

namespace AtCoder
{

    class Program
    {
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var A = vals[0];
            var B = vals[1];
            var K = vals[2];

            var divisors = new List<int>();
            for(var i =1; i<=Math.Min(A,B); i++)
            {
                if(A%i==0 && B%i==0)
                {
                    divisors.Add(i);
                }
            }
            Console.WriteLine(divisors.OrderByDescending(x=>x).ToArray()[K - 1]);

        }

    }
}
//B

Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main()
{
    int a, b, x, y, z, r;
    cin >> a >> b;
    x = a + b;
    y = a + (a-1);
    z = b + (b-1);
    r = max(x,max(y,z));
    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void trace(int A[], int N){
  int i;
  for(i=0; i<N; i++){
    if(i>0) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

void insertionSort(int A[], int N){
  int i, v, j;
  for(i=1; i<N; i++){
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    /*printf("%d", A[i]);*/
    trace(A, N);
    /*if(i!=N-1) printf(" ");
      else printf("\n");*/
  }
}

int main(){
  int N, i;
  int A[100];
  
  scanf("%d", &N);
  for(i=0; i<N;i++) scanf("%d", &A[i]);
  trace(A, N);
  insertionSort(A, N);
  return 0;
}



Measured memory_bytes: 2144
import itertools
n = int(input())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
Z = list(itertools.product(X,Y))
Z = Z[::len(X)+1]
def fn(p):
    D = 0
    for z in Z:
        D += abs(z[0]-z[1])**p
    else:
        print(D**(1/p))
fn(1)
fn(2)
fn(3)
MA = []
for z in Z:
    MA.append(abs(z[0]-z[1]))
print(max(MA))



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

double length(int x1, int x2, int y1, int y2) {
    const int buf = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
    return std::sqrt(buf);
}

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

    int x[N+1];
    int y[N+1];
    std::vector<int> path;
    for (int i = 1; i <= N; ++i) {
        std::cin >> x[i] >> y[i];
        path.push_back(i);
    }

    double sum = 0.0;
    int cnt = 0;
    do {
        ++cnt;
        for (size_t i = 0; i < (path.size() - 1); ++i) {
            sum += length(x[path[i]], x[path[i+1]], y[path[i]], y[path[i+1]]);
        }
    } while (std::next_permutation(path.begin(), path.end()));

    std::printf("%.10lf\n", sum / cnt);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

    string S; cin >> S;
    int cnt=0;
    rep(i,SZ(S)){
        if(S[i]=='o') cnt++;
    }
    if(15-SZ(S)+cnt>=8) cout << "YES" << endl;
    else cout << "NO" << endl;
}

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

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

	int ret = 0;
	for (int i = 1; i <= n; ++i) {
		int a;
		cin >> a;
		if ((i % 2 == 1) && (a % 2 == 1)) {
			++ret;
		}
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int now,cnt=0;
        for(int i=1;i<n;i++){
                now=i;
            for(int j=i+1;j<n;j++){
                if(now+j<n)now+=j;
                else if(now+j==n)cnt++;
                else break;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//-------------------------↓↓↓↓↓↓------------------------
    
//------ 自分を天才だと信じる ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s;
    rep(i,Size(s)){
        if(s[i]=='o')ans++;
    }
    ans+=15-Size(s);
    if(ans>=8)Cout("YES");
    else Cout("NO");
    return 0;
}

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

using namespace std;


#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>

void print(T x)
{
	std::cout << x << '\n';
}


signed main(void) {
	int N,A,B;
	cin >> N >> A >> B ;
	int min;
	if (N*A > B) min = B;
	else min = N*A;
		cout << min<< endl;
	
}


Measured memory_bytes: 256
'use strict'

function Main(input) {
  const S = input.split('\n')[0];
  const w = Number(input.split('\n')[1]);
  let answer = '';

  for(let i=0; i<S.length; i+=w) {
    answer += S.substr(i,1);
  }
  

  console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

Measured memory_bytes: 21064
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define il inline
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define rep0(i, n) for(int i = 0; i < (n); i ++)
#define per0(i, n) for(int i = (n) - 1; i >= 0; i --)
#define ept 1e-9
#define INF 0x3f3f3f3f
#define sz(x) (x).size()
#define ALL(x) (x).begin(), (x).end()
using namespace std;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
inline ll read1()
{
	ll x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
const int N = 210;
int n;
vector<int> G[N];
ll dis[N];
ll sz[N];
ll ans = 1000000, res = 0;
void dfs(int x,int fa)
{
    int nn = G[x].size();
    rep(i, 0, nn - 1)
    {
        int to = G[x][i];
		if(to == fa) continue;
		dis[to] = dis[x] + 1;
        sz[x] ++;
		dfs(to, x);
    }
}
int x[N],y[N];
main()
{
	n = read();
	rep(i, 1, n - 1)
	{
		x[i] = read();
		y[i] = read();
		G[x[i]].pb(y[i]);
		G[y[i]].pb(x[i]);
	}
	rep(i, 1, n)
	{
		memset(dis, 0, sizeof(dis));
		memset(sz, 0, sizeof(sz));
		dis[i] = 1;
		dfs(i ,0);
		ll now = 0;
		rep(i, 1, n) now = max(now, dis[i]);
		ll tmp[N] = {0};
		rep(i, 1, n)
			tmp[dis[i]] = max(tmp[dis[i]], sz[i]);
		ll Tmp = 1;
		rep(i, 1, now - 1) Tmp *= tmp[i];
		if(now < ans) ans = now, res = Tmp;
		else if(now == ans) res = min(res ,Tmp);
	}
	rep(i, 1, n - 1)
	{
		memset(dis, 0, sizeof(dis));
		memset(sz, 0, sizeof(sz));
		dis[x[i]] = dis[y[i]] = 1;
		dfs(x[i], y[i]);
		dfs(y[i], x[i]);
		ll now = 0;
		rep(i, 1, n) now = max(now, dis[i]);
		ll tmp[N] = {0};
		rep(i, 1, n) tmp[dis[i]] = max(tmp[dis[i]], sz[i]);
		ll Tmp = 2;
		rep(i, 1, now - 1) Tmp *= tmp[i];
		if(now < ans) ans = now, res = Tmp;
		else if(now == ans) res = min(res, Tmp);
	}
	cout << ans << " " << res;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>                                        
#include<algorithm>                                       
using namespace std;                                      
                                                          
void insertionSort(int A[],int n){                        
  for(int i=1;i<n;i++){                                   
    int v = A[i];                                         
    int j = i - 1;                                        
    while(j>=0 && A[j] > v){                              
      A[j+1] = A[j];                                      
      j--;                                                
    }                                                     
    A[j+1] = v;                                           
    for(int k=0;k<n;k++){                                 
      if(k>0) cout << " ";                                
      cout << A[k];                                       
    }                                                     
    cout << endl;                                         
  }                                                       
} 
int main(){                                               
  int A[100];                                             
  int n;                                                  
                                                          
  cin >> n;                                               
                                                          
  for(int i=0;i<n;i++){                                   
    cin >> A[i];                                          
    if(i>0) cout << " ";                                  
    cout << A[i];                                         
  }                                                       
  cout << endl;                                           
                                                          
  insertionSort(A,n);                                     
                                                          
  return 0;                                               
}

Measured memory_bytes: 3088
import fractions
N, M = map(int, input().split())
S = input()
T = input()

G = N * M // fractions.gcd(N, M)
slist = [i*(G//N) for i in range(N)]
mlist = [i*(G//M) for i in range(M)]
sm = set(slist) & set(mlist)
for i in sm:
    si = slist.index(i)
    mi = mlist.index(i)
    if S[si] != T[mi]:
        print(-1)
        exit()

print(G)

Measured memory_bytes: 81444
H, W, A, B = map(int, open(0).read().split())
MOD = 10**9+7

factorials = [1] * (H + W + 1)
inv_factorials = [1] * (H + W + 1)

for i in range(H + W):
    factorials[i+1] = factorials[i] * (i + 1) % MOD

inv_factorials = list(map(lambda n: pow(n, MOD - 2, MOD), factorials))

def modcomb(m, n, mod):
    return factorials[m] * inv_factorials[n] % MOD * inv_factorials[m - n] % MOD
 
# total = modcomb(H + W - 2, W - 1, MOD)
total = 0
 
# for i in range(B):
for i in range(B, W):
    total += modcomb(H - A - 1 + i, i, MOD) * modcomb(A - 1 + W - 1 - i, W - 1 - i, MOD) % MOD
    total %= MOD
 
print(total)

Measured memory_bytes: 88988
#include<bits/stdc++.h>
using namespace std;
int main(){
  string str;
  while(1){
    stack<int> s;
    bool ac = true;
    s.push('.');
    getline(cin,str);
    if(str == ".")break;
    for(int i=0;i<str.size();i++){
      if(str[i] == '[' || str[i] == ']' || str[i] == '(' || str[i] ==')'){
	if(str[i] == '[' || str[i] == '('){
	  s.push(str[i]);
	}
	if(str[i] == ']'){
	  if(s.top() == '['){
	    s.pop();
	  }else{
	    ac = false;
	  }
	}else if(str[i] == ')'){
	  if(s.top() == '('){
	    s.pop();
	  }else{
	    ac = false;
	  }
	}
      }
      if(!ac)break;
      
    }
    s.pop();
    if(!s.empty())ac = false;
    if(!ac)cout << "no" << endl;
    else cout << "yes" << endl;
  }
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------


int main(){
    ll a,b,c;
cin>>a>>b>>c;
if(a==b){
    cout<<c<<endl;
}
if(a==c){
    cout<<b<<endl;
}
if(c==b){
    cout<<a<<endl;
}
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MAX_N = 305;
const ll INF = 1e10;
ll edge[MAX_N][MAX_N];
ll wf[MAX_N][MAX_N];
ll fuel[MAX_N][MAX_N];
ll N, M, L;

int main(){
	cin >> N >> M >> L;

	// 初期化
	for(int i=0;i<N;i++) {
		for(int j=0;j<N;j++) {
			fuel[i][j] = wf[i][j] = edge[i][j] = INF;
		}
		fuel[i][i] = 0;
		edge[i][i] = 0;
		wf[i][i] = 0;
	}

	for(int i =0;i<M;i++) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		wf[a][b] = edge[a][b] = c;
		wf[b][a] = edge[b][a] = c;
		if(c <= L) fuel[a][b] = fuel[b][a] = 1;
	}

	// ワーシャルフロイト
	for(int i=0;i<N;i++) {
		for(int j=0;j<N;j++) {
			for(int k=0;k<N;k++) {
				wf[j][k] = min(wf[j][k], wf[j][i]+wf[i][k]);
			}
		}
	}
	
	for(int i=0;i<N;i++) {
		for(int j=0;j<N;j++) {
			if(wf[i][j] <= L) {
				fuel[i][j] = 1;
			}
		}
	}
	for(int i=0;i<N;i++) {
		for(int j=0;j<N;j++) {
			for(int k=0;k<N;k++) {
				fuel[j][k] = min(fuel[j][k], fuel[j][i]+fuel[i][k]);
			}
		}
	}

	int Q;
	cin >> Q;
	for(int i=0;i<Q;i++) {
		ll s,t;
		cin >> s >> t;
		s--, t--;
		if(fuel[s][t] != INF) cout << fuel[s][t]-1 << endl;
		else cout << -1 << endl;
	}
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, a, b, dp[N], cu, cv, vis[N], f[N], in[N], p[N], c, col[N];
vector<int> g[N];
void dfs(int u, int fa) {
    f[u] = fa;
    vis[u] = 1; col[u] = col[fa] ^ 1;
    dp[u] = col[u] ? 1 : -1;
    for(auto v : g[u]) if(v != fa) {
        if(!vis[v]) dfs(v, u), dp[u] += dp[v];
        else cu = u, cv = v;
    }
}
void tree() {
    if(dp[1] != 0) { printf("-1\n"); return; }
    int ans = 0;
    for(int i = 1; i <= n; ++i) ans += abs(dp[i]);
    printf("%d\n", ans);
}
void even() {
    if(dp[1] != 0) { printf("-1\n"); return; }
    while(cu != cv) p[++c] = dp[cv], in[cv] = 1, cv = f[cv];
    sort(p + 1, p + 1 + c);
    int mid = p[(c + 1) / 2];
    int ans = abs(mid);
    for(int i = 1; i <= n; ++i) if(!in[i]) ans += abs(dp[i]);
    for(int i = 1; i <= c; ++i) ans += abs(p[i] - mid);
    printf("%d\n", ans);
}
void odd() {
    if(dp[1] % 2 != 0) { printf("-1\n"); return; }
    int x = -dp[1] / 2;
    while(cu) dp[cu] += x, cu = f[cu];
    while(cv) dp[cv] += x, cv = f[cv];
    int ans = abs(x);
    for(int i = 1; i <= n; ++i) ans += abs(dp[i]);
    printf("%d\n", ans);
}
int main() {
    scanf("%d %d", &n, &m);
    for(int i = 1; i <= m; ++i) scanf("%d %d", &a, &b), g[a].push_back(b), g[b].push_back(a);
    dfs(1, 0);
    if(m == n - 1) tree();
    else if(col[cu] ^ col[cv]) even();
    else odd();
    return 0;
}


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

class UnionFindTree {
private:
    vector<int> parent;
public:
    UnionFindTree(int n) : parent(n) {
        // 最初は全てを根として初期化
        for(int i = 0; i < n; i++) parent[i] = i;
    }

    int get_root(const int x) {
        // データxが属する木の根を取得する
        if (parent[x] == x) return x;
        // 取得したものは直接木の根をつなぐ(経路圧縮)
        return parent[x] = get_root(parent[x]);
    }

    void unite(const int x, const int y) {
        // xとyの木を併合する
        int rx = get_root(x);
        int ry = get_root(y);
        // 元から同じ木に属している場合は何もしない
        if (rx == ry) return;
        // xの属する木をyの属する木につける
        parent[rx] = ry;
    }

    bool is_same_root(const int x, const int y) {
        return get_root(x) == get_root(y);
    }

    void print() {
        for(auto elm : parent) cout << elm << " ";
        cout << endl;
    }
};

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

    vector<pair<int, int>> p;
    for (auto i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        p.emplace_back(a, b);
    }

    int ans = 0;
    for (auto i = 0; i < m; i++) {
        UnionFindTree tree(n);
        for (auto j = 0; j < m; j++) {
            if(i == j) continue;
            tree.unite(p[j].first, p[j].second);
        }
        int cnt = 0;
        for (auto j = 0; j < n; j++) {
            if(tree.get_root(j) == j) {
                cnt++;
            }
        }
        if(cnt != 1) ans++;
//        cout << i << endl;
//        tree.print();
    }

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

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
m = 0
d = defaultdict(int)
for i in range(N):
    S = input()
    d[S] += 1
    m = max(m, d[S])

X = []
for s in d:
    if d[s] == m:
        X.append(s)
X.sort()
for s in X:
    print(s)


Measured memory_bytes: 32452
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
typedef long long ll;
#define out(i) cout<<(i)<<endl

int main() {
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;
  if(x+r>W||x-r<0||y+r>H||y-r<0){cout<<"No"<<endl;}
  else{cout<<"Yes"<<endl;}
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a+b>c+d) cout << "Left" << endl;
  else if(a+b<c+d) cout << "Right" << endl;
  else cout << "Balanced" << endl;
  return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF (1e9+7)

using namespace std;

int main(){
  int n, m, q;
  while(cin >> n >> m >> q and n + m + q){
    vector<bitset<36> > bulbs(m);
    bitset<36> tmp;
    bitset<36> orgn;
    REP(i, n) REP(j, m) bulbs[j][i] = 1;
    REP(count, q){
      orgn = tmp;
      string s, b;
      cin >> s >> b;
      REP(i, s.size()){
        int t = s[i] - '0';
        if(t) tmp[i] = ~tmp[i];
      }
      REP(i, b.size()){
        int t = b[i] - '0';
        if(t) bulbs[i] &= tmp;
        else bulbs[i] &= ~tmp;
      }
    }
    REP(i, m) {
      if(bulbs[i].count() != 1) cout << "?";
      else REP(j, n) if(bulbs[i][j] == 1) cout << (char)((j < 10) ? ('0' + j) : ('A' + j - 10));
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3144
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int S = sc.nextInt();
        
        if (S == N) {
            System.out.println("Yes");
        } else if (S < N) {
            System.out.println("No");
        }
        
    }
}

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

// Begin {{{
using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (i64 i = 0; i < (n); ++i)
#define reps(i, s, n) for (i64 i = (s); i <= (n); ++i)
#define VAR(Type, ...) Type __VA_ARGS__; IN(__VA_ARGS__)
#define Float(x) OUTN(fixed, setprecision(x));

using i64 = int_fast64_t;
using pii = pair<i64, i64>;

template <class A, class B>
inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }

template <class A, class B>
inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

// IN
void IN() {}
template <class Head, class... Tail>
void IN(Head&& head, Tail&&... tail) {
  cin >> head;
  IN(forward<Tail>(tail)...);
}

// OUTS
void OUTS() {}
template <class Head, class... Tail>
void OUTS(Head&& head, Tail&&... tail) {
  cout << head << " \n"[sizeof...(tail)==0];
  OUTS(forward<Tail>(tail)...);
}

template <class T>
void OUTS(vector<T> &vec) {
  for (auto &e : vec) cout << e << " \n"[&e==&vec.back()];
}

template <class T>
void OUTS(vector<vector<T>> &df) {
  for (auto &vec : df) OUTS(vec);
}

// OUTL
void OUTL() {}
template <class Head, class... Tail>
void OUTL(Head&& head, Tail&&... tail) {
  cout << head << "\n";
  OUTL(forward<Tail>(tail)...);
}

template <class T>
void OUTL(vector<T> &vec) {
  for (auto &e : vec) cout << e << "\n";
}

// OUTN
void OUTN() {}
template <class Head, class... Tail>
void OUTN(Head&& head, Tail&&... tail) {
  cout << head;
  OUTN(forward<Tail>(tail)...);
}
// }}} End

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  VAR(int, d);
  if (d == 25) OUTL("Christmas");
  else if (d == 24) OUTL("Christmas Eve");
  else if (d == 23) OUTL("Christmas Eve Eve");
  else OUTL("Christmas Eve Eve Eve");
  return 0;
}


Measured memory_bytes: 256
<?php
//    $test = "100 71 29";
    $input = explode(" ", trim(fgets(STDIN)));
//    $input = explode(" ", $test);
    $num = 0;
    if($input[0] + $input[1] == $input[2] || $input[0] + $input[2] == $input[1] || $input[2] + $input[1] == $input[0]){
        echo "Yes";
    } else {
        echo "No";
    }
?>

Measured memory_bytes: 3704
#include<iostream>
using namespace std;
int main(){
  string S,T;
  cin>>S;
  cin>>T;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)==T.at(i)){
      continue;
    }
    else{
      count++;
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 3868
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {/*
	ll N;
	ll sum=0;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		if (i % 5 != 0&& i % 3 != 0) {
 
 
			sum += i;
		}
	}
	cout << sum;
}*/
	
	int N;
	cin >> N;
	if (N / 100 == 7 || N % 100 / 10 == 7 || N % 10 == 7) {
 
 
		cout << "Yes";
		return 0;
		}
	cout << "No";
 
}

Measured memory_bytes: 3632