akhauriyash/Code-Regression huggingface dataset:
/// https://github.com/hatoo/competitive-rust-snippets
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules !get {([$t:ty]) => {{let mut line: String = String::new(); stdin().read_line(&mut line).unwrap(); line.split_whitespace().map(|t| t.parse::<$t>() .unwrap () ) .collect ::<Vec <_ >>() } } ;([$t :ty ] ;$n :expr ) =>{(0 ..$n ) .map (|_ |get !([$t ] ) ) .collect ::<Vec <_ >>() } ;($t :ty ) =>{{let mut line :String =String ::new () ;stdin () .read_line (&mut line ) .unwrap () ;line .trim () .parse ::<$t >() .unwrap () } } ;($($t :ty ) ,*) =>{{let mut line :String =String ::new () ;stdin () .read_line (&mut line ) .unwrap () ;let mut iter =line .split_whitespace () ;($(iter .next () .unwrap () .parse ::<$t >() .unwrap () ,) *) } } ;($t :ty ;$n :expr ) =>{(0 ..$n ) .map (|_ |get !($t ) ) .collect ::<Vec <_ >>() } ;($($t :ty ) ,*;$n :expr ) =>{(0 ..$n ) .map (|_ |get !($($t ) ,*) ) .collect ::<Vec <_ >>() } ;}
#[allow(unused_macros)]
macro_rules !debug {($($a :expr ) ,*) =>{eprintln !(concat !($(stringify !($a ) ," = {:?}, " ) ,*) ,$($a ) ,*) ;} }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
fn solve() {
    let (n, _l) = get!(u8, u8);
    let mut S:Vec<String> = get!(String; n);
    S.sort();
    for s in &S {
        print!("{}", s);
    }
    println!("");
}

Measured memory_bytes: 8572
#include<stdio.h>
int main()
{
	int w,a,b;
	scanf("%d%d%d",&w,&a,&b);
	if(b>a+w) printf("%d\n",b-a-w);
	else if(b+w<a) printf("%d\n",a-b-w);
	else printf("0\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
    
using namespace std;
    
const int N = 305;
const long long INF = 1e18 + 5;
    
int n;
int A[N][N];
vector<pair<int, pair<int, int> > > dists;
vector<pair<int, int> > V[N];
long long dist[N];
bool vis[N];
long long realDist[N][N];
    
long long calcDist(int a, int b) {
    return realDist[a][b];
}
    
long long ans;
void addEdge(int a, int b, int dist) {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            realDist[i][j] = min(realDist[i][j], realDist[i][a] + dist + realDist[b][j]);
        }
    }
    ans += dist;
}
    
int main() {
    
    scanf("%d", &n);
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            realDist[i][j] = INF;
            scanf("%d", &A[i][j]);
            dists.push_back({A[i][j], {i, j}});
        }
    }
    
    for (int i = 1; i <= n; i++) {
        realDist[i][i] = 0;
    }
    
    sort(dists.begin(), dists.end());
    for (auto p : dists) {
        int dist = p.first;
        int a = p.second.first;
        int b = p.second.second;
        long long d = calcDist(a, b);
        if (d == dist) {
            continue;
        } else if (d < dist) {
            printf("-1\n");
            return 0;
        } else {
            addEdge(a, b, dist);
            addEdge(b, a, dist);
        }
    }
    
    printf("%lld\n", ans / 2);
    
    return 0;
}

Measured memory_bytes: 2680
t = []
n = int(input())
for i in range(n):
    t.append(int(input()))



'''
n = 6
t=[4,1,5,7,5,4]
'''


minv = t[0]
maxv = t[1] - t[0]
for j in range(1,n):
    maxv = max([maxv,t[j] - minv])
    minv = min([minv,t[j]])
print(maxv)

Measured memory_bytes: 13592
#include <stdio.h>

int main()
{
   long int a,b,c;
   scanf("%ld %ld %ld",&a,&b,&c);
   if(a==b && b==c)
   {
       printf("1");
   }else{
       if(a==b || b==c || a==c)
       {
           printf("2");
       }else{
           printf("3");
       }
   }
    return 0;
}

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

int main(){
string s;
  cin>>s;
  
  int first=0;
  for(int i=0; i<s.size(); i++){
   if(s[i]=='A'){first=i-1; break;}
  }
  
  int end=0;
  for(int i=s.size()-1; i>=0; i--){
   if(s[i]=='Z'){end=i; break;}
  }
  
  cout<<end-first;
  
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  cin>>n;
  string s;
  ll a[5]={};
  for(int i=0;i<n;i++){
    cin>>s;
    char c=s.at(0);
    if(c=='M')
      a[0]++;
    else if(c=='A')
      a[1]++;
    else if(c=='R')
      a[2]++;
    else if(c=='C')
      a[3]++;
    else if(c=='H')
      a[4]++;
  }
  ll c=0;
  for(int i=0;i<3;i++){
    for(int j=i+1;j<4;j++){
      for(int k=j+1;k<5;k++){
        c+=a[i]*a[j]*a[k];
      }
    }
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    int e;
    cin >> e;
    if (e == 0) break;

    int min_m = e;

    for (int z = 0; z * z * z <= e; z++) {
      int ez = e - z * z * z;
      for (int y = 0; y * y <= ez; y++) {
	int x = ez - y * y;
	int m = x + y + z;
	if (min_m > m) min_m = m;
      }
    }

    cout << min_m << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define pi 3.14159
#define INF 10000000
using namespace std;
int main(){
	int a,b,x;
	cin >> a >> b >> x;
	if(a<=x&&x<=(a+b))
		cout << "YES";
	else 
		cout << "NO";
}

Measured memory_bytes: 256
import numpy as np
height, width = map(int, input().split())
_s_list = [input() for i in range(height)]
s_list = [list(ss) for ss in _s_list]  # 列×行に1文字ずつ区切ってリストへ追加 -> 2次元配列化
s_arr  = np.array(s_list)

# print(s_arr)  # debug
its_ok = True
for _h in range(height):
    for _w in range(width):
        # 自分が'#'のときだけチェック
        if s_arr[_h, _w] == '#':
            checker = False
            # 一番上でなければ、上のマスをチェック
            if _h >= 1:
                if s_arr[_h-1, _w] == '#':
                    checker = True
            # 一番下でなければ、下のマスをチェック
            if _h != height-1:
                if s_arr[_h+1, _w] == '#':
                    checker = True
            # 一番左でなければ、左のマスをチェック
            if _w >= 1:
                if s_arr[_h, _w-1] == '#':
                    checker = True
            # 一番右でなければ、右のマスをチェック
            if _w != width-1:
                if s_arr[_h, _w+1] == '#':
                    checker = True
            
            if checker is False:
                its_ok = False
                break
    
    if its_ok is False:
        break

if its_ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 12440
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    int numData = Integer.parseInt(br.readLine());
    
    int currentT = 0;
    int currentX = 0;
    int currentY = 0;
    int nextT = 0;
    int nextX = 0;
    int nextY = 0;
    int amountMove = 0;
    
    for(int i=0; i<numData; i++){
      String[] data = br.readLine().split(" ");
      nextT = Integer.parseInt(data[0]);
      nextX = Integer.parseInt(data[1]);
      nextY = Integer.parseInt(data[2]);
      
      amountMove = Math.abs(nextX - currentX) + Math.abs(nextY - currentY);
      if(amountMove > nextT-currentT || (nextT-currentT-amountMove)%2 != 0){
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}

Measured memory_bytes: 45976
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	k, _ := strconv.Atoi(Scanner())
	q := make([][]int, 9)
	for i := 1; i < 10; i++ {
		q[i-1] = []int{i}
	}
	c := 0
	p := []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
	for {
		if len(q) >= k {
			ans := q[k-1]
			y := make([]string, len(ans))
			for i := 0; i < len(ans); i++ {
				y[i] = strconv.Itoa(ans[i])
			}
			fmt.Println(strings.Join(y, ""))
			break
		}
		r := q[c]
		last := r[len(r)-1]
		for _, i := range p {
			if abs(last-i) <= 1 {
				x := make([]int, len(r))
				copy(x, r)
				x = append(x, i)
				q = append(q, x)
			}
		}
		c++
	}
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}


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

if M % 2 != 0:
    print(-1)
    exit()

graph = [[] for _ in range(N)]
for _ in range(M):
    u, v = map(int, input().split())
    graph[u - 1].append(v - 1)
    graph[v - 1].append(u - 1)

ans = []
parent = [-1] * N
visited = [False] * N
ctr = [0] * N
record = []
que = [(-1, 0)]

while que:
    pre, u = que.pop()
    if visited[u]:
        ctr[u] += 1
        if pre >= 0:
            ans.append((u, pre))
        continue
        
    visited[u] = True
    record.append(u)
    for v in graph[u]:
        if v != parent[u]:
            parent[v] = u
            graph[v].remove(u)
            que.append((u, v))
            
for u in record[1:][::-1]:
    if ctr[u] % 2 == 1:
        ans.append((u, parent[u]))
    else:
        ans.append((parent[u], u))
        ctr[parent[u]] += 1
        
for x, y in ans:
    print(x + 1, y + 1)




Measured memory_bytes: 72736
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var s = io.S;
        io.Write(s.Contains("9") ? "Yes" : "No");
    }
}

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

//#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
//const int MOD = 1e9 + 7;
using intpair = pair<int, int>;
using ll = long long;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main(){
    int n, m;
    cin >> n >> m;
    vector<intpair> a(n);
    rep(i,n) cin >> a[i].first >> a[i].second;
    sort(ALL(a));
    
    auto it = a.begin();
    priority_queue<int> q;
    ll ans = 0;
    reps(i,1,m){
        while(it != a.end()){
            if(it->first != i) break;
            q.push(it->second);
            it++;
        }
        if(!q.empty()){
            ans += q.top();
            q.pop();
        }
    }
    
    cout << ans << endl;
}

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

typedef long long ll;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

ll mod=1e9+7;

using namespace std;


ll inputValue(){
	ll a;
	cin >> a;
	return a;
};

void inputArray(int * p, ll a){
	rep(i, a){
		cin >> p[i];
	}
};

template<typename T>
void inputVector(vector<T>& p, ll a){
	rep(i, a){
		T input;
		cin >> input;
		p.emplace_back(input);
	}
}


template <typename T>
void output(T a) {
    cout << a << "\n";
}

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	// source code
    ll a,b,c;

    cin >> a>>b>>c;
    
    cout << ((c-(a-b)>0) ?c-(a-b):0) <<endl;

	return 0;
}


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

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m,x;
    cin>>n>>m>>x;
    int a=0,b=0;
    for(int i=1;i<=m;i++){
        int ch;cin>>ch;
        if(x>ch)a++;
        else b++;
    }
    cout<<min(a,b)<<endl;


    return 0;
}


Measured memory_bytes: 3696
using System;
using System.Collections.Generic;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;
        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }
            var res = line[index];
            index++;
            return res;
        }
        public int NextInt()
        {
            return int.Parse(Next());
        }
        public long NextLong()
        {
            return long.Parse(Next());
        }
        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }
        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }
        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }
    }

    class Program
    {
        private int N;
        private string[] S;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            S = new string[N];
            for (int i = 0; i < N; i++)
            {
                S[i] = sc.Next();
            }
        }

        public void Solve()
        {
            Scan();
            var hs = new HashSet<string>();
            hs.Add(S[0]);
            for (int i = 1; i < N; i++)
            {
                if (!hs.Add(S[i]))
                {
                    Console.WriteLine("No");
                    return;
                }

                if (S[i][0] != S[i - 1][S[i - 1].Length - 1])
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
        }

        static void Main() => new Program().Solve();
    }
}

Measured memory_bytes: 13280
import Foundation

let a = readLine()!
let b = readLine()!.components(separatedBy: " ")


var i = Int(b[0])!

var isCheck: Bool = false

//if (Int(a)! == 1) {
  //isCheck = true
//}

while i < Int(b[1])! + 1 {
  
  if (i % Int(a)! == 0) {
    isCheck = true
  }
  i += 1 
}

isCheck ? print("OK") : print("NG")

Measured memory_bytes: 14064
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

const ll MOD = 1000000007LL;
const double PI = 3.14159265358979323846;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

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

	ll N;
	cin >> N;
	
	set<string> Ss;
	string S;
	for (ll i = 0; i < N; ++i) {
		cin >> S;
		Ss.insert(S);
	}

	cout << Ss.size() << endl;

	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

int main2() {
  int N = nextInt();
  map<int, int> m;
  REP(i, N) {
    int a = nextInt();
    m[a]++;
  }
  vector<int> v;
  for (auto it = m.begin(); it != m.end(); ++it) {
    if (it->second >= 4) {
      v.push_back(it->first);
    }
    if (it->second >= 2) {
      v.push_back(it->first);
    }
  }
  sort(ALL(v));
  reverse(ALL(v));
  if (v.size() < 2) cout << 0 << endl;
  else cout << ((ll)v[0] * v[1]) << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 4992
number=list(map(int,input().split()))
H,W,K=number[0],number[1],number[2]
answer=0
nums=[]
for i in range(H):
    tmp=list(str(input()))
    nums.append(tmp)
count=0
for cowmask in range(1<<H):
    for rowmask in range(1<<W):
        count=0
        for x in range(H):
            for y in range(W):
                if (cowmask>>x)&1==0 and (rowmask>>y)&1==0 and nums[x][y]=="#":
                    count+=1
        if count==K:
            answer+=1
            
print(answer)

Measured memory_bytes: 8944
#include<stdio.h>
#include<ctype.h>

int main(){
  int a,b;

  scanf("%d%d",&a,&b);
  if(a>12){
    printf("%d",b);
  }else if(13>a&&a>5){
    printf("%d",b/2);
  }else if(6>a){
    printf("%d",0);
  }


  return 0;
}


Measured memory_bytes: 128
n,k=map(int,input().split())
h=list(map(int,input().split()))

l=[0]+[float("inf")]*(n-1)

for x in range(n):
    for y in range(x+1,min(n,x+k+1)):
        l[y]=min(l[y],abs(h[y]-h[x])+l[x])
print(l[-1])

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

void Cal(int Dice, int Time, int Sec)
{
    double temp = 0;
    temp = (double)Dice / Sec;
    if (temp <= Time)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
}

int main()
{
    int Dice, Time, Sec = 0;
    cin >> Dice >>Time >>Sec;
    Cal(Dice, Time, Sec);


    return 0;
}

Measured memory_bytes: 3564
require 'set'

s = gets.chomp.to_i
def f(n)
  n.even? ? n / 2 : 3 * n + 1
end

n = s
i = 1
set = Set.new
while(true)
  break unless set.add? n
  n = f(n)
  i += 1
end
puts i


Measured memory_bytes: 2300
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(int)(n);i++)


int par[1000000];//親
int ran[200000]; //木の深さ

int par2[1000000];//親
int ran2[200000]; //木の深さ

struct unionfind
{

unionfind(int n) //初期化
{
  rep(i,n)
  {
    par[i]=i;
    ran[i]=0;
  }
}

int root(int x) //木の根を求める
{
  if(par[x]==x) return x;
  else return par[x]=root(par[x]);
}

void unite(int x,int y) //xとyの属する集合を併合
{
  x=root(x);
  y=root(y);
  if(x==y) return;

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

bool same(int x,int y) //xとyが同じ集合に属するのか
{
    return root(x)==root(y);
}

};

struct unionfind2
{

unionfind2(int n) //初期化
{
  rep(i,n)
  {
    par2[i]=i;
    ran2[i]=0;
  }
}

int root(int x) //木の根を求める
{
  if(par2[x]==x) return x;
  else return par2[x]=root(par2[x]);
}

void unite(int x,int y) //xとyの属する集合を併合
{
  x=root(x);
  y=root(y);
  if(x==y) return;

  if(ran2[x]<ran2[y]) par2[x]=y;
  else
  {
    par2[y]=x;
    if(ran2[x]==ran2[y]) ran2[x]++;
  }
}

bool same(int x,int y) //xとyが同じ集合に属するのか
{
    return root(x)==root(y);
}

};


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

  unionfind train(n);
  unionfind2 road(n);


  rep(i,k)
  {
    int r,s;
    cin>>r>>s;
    road.unite(r-1,s-1);
  }

  rep(i,l)
  {
    int r,s;
    cin>>r>>s;
    train.unite(r-1,s-1);
  }

  map <pair<int,int>,int> mp;
  rep(i,n)
  {
    if(mp[make_pair(road.root(i),train.root(i))]==0)
      mp[make_pair(road.root(i),train.root(i))]=1;
    else mp[make_pair(road.root(i),train.root(i))]++;
  }


  rep(i,n)
  {
    cout<<mp[make_pair(road.root(i),train.root(i))];
    if(i<n) cout<<" ";
  }

  cout<<endl;
}

Measured memory_bytes: 17664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 55);
ll dp[1000010][2];
int main(){ 
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i <= n; i++) dp[i][0] = dp[i][1] = INF;
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    int d = s[i] - '0';
    dp[i+1][0] = min(dp[i+1][0], min(dp[i][0], dp[i][1]) + d);
    dp[i+1][1] = min(dp[i+1][1], min(dp[i][0] + 11 - d, dp[i][1] + 9 - d));
  }
  cout << min(dp[n][0], dp[n][1]) << endl;
  return 0;
} 

Measured memory_bytes: 17028
#include<bits/stdc++.h>
#define int long long
#define mp make_pair
#define pb push_back
using namespace std;
const int nx=2e5+5;
//const int inf=1e18+7;
const int mod=1e9+7;
vector<int>adj[nx];


int power(int x,int y)
{
    int res = 1;
	x=x%mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod;
        y = y>>1;
		y %= mod;
        x = (x*x)%mod;
    }
	//assert(res<mod);
    return res%mod;
}

int value(int n, int rem){
	int ans=1;
	for(int i=0; i<rem; i++){
		ans = (ans*(n-i))%mod;
	}
	//cout<<rem<<" "<<ans<<endl;
	return ans%mod;
}

int value1(int n){
	int ans=1;
	for(int i=2; i<=n; i++){
		ans = (ans*(i))%mod;
	}
	return ans%mod;
}
signed main(){
	int n,a,b;
	cin>>n>>a>>b;
	int total=power(2,n)-1;
	//cout<<total<<endl;
	int rem=(value(n,a)*power(value1(a),mod-2))%mod+(value(n,b)*power(value1(b),mod-2))%mod;
	rem %= mod;
	//cout<<rem<<endl;
	int ans=((total-rem)%mod+mod)%mod;
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)
//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int a, b;
    cin >> a >> b;
    if(a % 2 == 0 || b % 2 == 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define ios; ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mk make_pair
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef double db;
mt19937 rnd(random_device{}());
const int mod = 1e9 + 7;
const int N = 1e3 + 5;
const int M = 1e3 + 5;
inline ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
inline ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll ksm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n,m,k;

int main(){
    cin>>n;
    if(n>=30) cout<<"Yes\n";
    else cout<<"No\n";
    //scanf("%d",&n);
    //printf("%s\n",n>=30?"Yes":"No");
    return 0;
}

Measured memory_bytes: 3604
function Main(inputs) {
　const inputlines = inputs.split("\n");
　const firstline = inputlines[0].split(" ");
　const votevalues = inputlines[1].split(" ").map(x => parseInt(x, 10));
　const standard = 1 / (4 * firstline[1]);
　let yes = 0; 
  
　let totalvotes  = function(arr) {
　　　let sum = 0;
　　　arr.forEach(function(elm) {
　　　sum += elm;
    	　});
    	　return sum;
　};
  
　const currentstandard = totalvotes(votevalues) * standard;
  
　for (let i = 0; i < votevalues.length; i++){
　　if(votevalues[i] >= currentstandard){
　　　yes++;
　　　if(yes == firstline[1]){
　　　　console.log("Yes");
　　　　break;
　　　}
　　}
　}
　if(yes != firstline[1]){
　　console.log("No");
    }
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29624
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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 modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  string L;
  cin >> L;
  int N = L.size();

  ll ans = 0;
  ll num_of_one = 0;

  rep(i, N) {
    if (L[i] == '1') {
      ll temp = modpow(2, num_of_one, MOD);
      num_of_one++;
      ll res = N - 1 - i;
      temp *= modpow(3, res, MOD);
      temp %= MOD;
      ans += temp;
      ans %= MOD;
    }
  }
  ans += modpow(2, num_of_one, MOD);
  ans %= MOD;
  cout << ans << endl;
}

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

#define endl '\n'
#define mod 1e7 

using ll = long long;
using namespace std;

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

    int n,W;
    cin >> n >> W;
    vector<long long> w(n), v(n);
    for(auto i=0;i<n;i++) cin >> w[i] >> v[i];

   ll dp[n+1][W+1];

   for(int i=0;i<=n;i++) {
       for(int j =0; j<=W;j++) {
           if(i == 0 || j == 0) dp[i][j] = 0;
           else if(w[i-1] <= j) {
               dp[i][j] = max(dp[i-1][j] , (v[i - 1] + dp[i-1][j - w[i-1]] ) );
           }else {
               dp[i][j] = dp[i-1][j];
           }
       }
   }

   cout << dp[n][W] << endl;

    

    return 0;
}

Measured memory_bytes: 82460
n, m, c = map(int, input().split())
B = list(map(int, input().split()))

cnt = 0

for i in range(n):
    res = c
    A = list(map(int, input().split()))
    for a, b in zip(A, B):
        res += a*b
    if res > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
using ll=long long;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int arr[a+3],ara[b+3];
    arr[0]=c;
    ara[0]=d;
    for(int i=1;i<=a;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+(a+1),greater<int>());
   // cout<<arr[0]<<endl;
    for(int i=1;i<=b;i++)
    {
        cin>>ara[i];
    }
     sort(ara,ara+(b+1));
     // cout<<ara[0]<<endl;
     if(arr[0]<ara[0])
     {
         cout<<"No War"<<endl;
     }
     else
     {
         cout<<"War"<<endl;
     }
     return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
int main() {
  string s;
  cin >> s;

  bool flag = true;
  for (int i = 0; i < s.size(); i++) {
    if ((i + 1) % 2 == 0) {
      if (s.at(i) == 'R') flag = false;
    } else {
      if (s.at(i) == 'L') flag = false;
    }
  }

  if (flag)
  cout << "Yes" << endl;
  else
  cout << "No" << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.A
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var c = ReadText();
            switch (c)
            {
                case "a":
                case "i":
                case "u":
                case "e":
                case "o":
                    return "vowel";
            }
            return "consonant";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


Measured memory_bytes: 25888
S = input()
ans = 1
tmp = S[0]
flg = False
for i in range(1,len(S)):
    if flg:
        tmp += S[i]
        ans += 1
        flg = False
        continue
    if S[i] != tmp:
        tmp = S[i]
        ans += 1
    else:
        flg = True
print(ans)


Measured memory_bytes: 41308
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"reflect"
	"sort"
	"strconv"
	"strings"
)

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var n int
var s string
var patterns []string

func permute(a []string, l, r int) {
	if l == r {
		//fmt.Println(a)
		patterns = append(patterns, strings.Join(a, ""))
	} else {
		for i := l; i <= r; i++ {
			a[l], a[i] = a[i], a[l]
			permute(a, l+1, r)
			a[l], a[i] = a[i], a[l] //backtrack
		}
	}
}

func main() {
	sc.Split(bufio.ScanWords)
	n = nextInt()

	var p, q string
	for i := 1; i <= n; i++ {
		p += nextStr()
	}
	for i := 1; i <= n; i++ {
		q += nextStr()
	}

	nums := make([]string, n)
	for i := 1; i <= n; i++ {
		//fmt.Println(strconv.Itoa(i))
		nums[i-1] = string(strconv.Itoa(i))
	}

	a, b := -1, -1
	permute(nums, 0, len(nums)-1)
	//fmt.Println(patterns)
	//fmt.Println(p, q)
	sort.Sort(SortBy(patterns))
	//fmt.Println(patterns)
	for i, v := range patterns {
		if a > -1 && b > -1 {
			break
		}
		if reflect.DeepEqual(p, v) {
			a = i
		}
		if reflect.DeepEqual(q, v) {
			b = i
		}
	}

	fmt.Println(absInt(a - b))

}

type SortBy []string

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }


Measured memory_bytes: 5248
using System;


class Program
{
    static void Main(string[] args)
    {
        int k = int.Parse(Console.ReadLine());
        string[] s = Console.ReadLine().Split(" ");
        int a = int.Parse(s[0]);
        int b = int.Parse(s[1]);

        if( a > b)
        {
            int temp = a;
            a = b;
            b = temp;
        }

        bool ok = false;
        for(int i = 1; (i*k) <= b; i++)
        {
            if((i*k) >= a & (i*k) <= b)
            {
                ok = true;
                break;
            }
        }

        if( ok)
        {
            Console.WriteLine("OK");
        }
        else
        {
            Console.WriteLine("NG");
        }
    }
}


Measured memory_bytes: 27528
/************************************/
/* NoobM							*/
/* File Name : chaa.cpp				*/
/* Date : 13.07.2020 02:37:00 +06	*/
/************************************/

#include <bits/stdc++.h>

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

void solve() {
	ll n, k;
	cin >> n >> k;
	
	cout << min(n % k, k - n%k) << endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
	
	int t = 1;
	//cin >> t;
	
	while (t--) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

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

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

int N, K;
int dp[105][3][3]; // dp[?????\??????][?????\???????????\???][?????\???????????\???]
int menu[105];

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

    memset(menu, -1, sizeof menu);

    rep(i, K) {
        int a, b; cin >> a >> b;
        menu[a - 1] = b - 1;
    }

    if (menu[0] != -1) {
        dp[1][menu[0]][0] = 1;
    } else {
        rep(i, 3) {
            dp[1][i][0] = 1;
        }
    }

    if (menu[1] != -1) {
        rep(i, 3) {
            dp[2][menu[1]][i] += dp[1][i][0];
        }
    } else {
        rep(i, 3) rep(j, 3) rep(k, 3) {
            dp[2][i][j] += dp[1][j][k];
            dp[2][i][j] %= 10000;
        }
    }

    for (int i = 2; i < N; ++i) {
        if (menu[i] != -1) {
            rep(j, 3) {
                rep(k, 3) {
                    if (menu[i] == j && j == k) continue;
                    dp[i + 1][menu[i]][j] += dp[i][j][k];
                    dp[i + 1][menu[i]][j] %= 10000;
                }
            }
        } else {
            rep(j, 3) {
                rep(k, 3) {
                    rep(l, 3) {
                        if (j == k && k == l) continue;
                        dp[i + 1][j][k] += dp[i][k][l];
                        dp[i + 1][j][k] %= 10000;
                    }
                }
            }
        }
    }

    int ans = 0;

    rep(i, 3) rep(j, 3) {
        ans += dp[N][i][j];
        ans %= 10000;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3040
#ifndef bhartiya
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

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

typedef long long ll;
typedef pair<ll, ll> pll;
// not that imp
typedef pair<pll, ll> plll;
typedef vector<ll> vl;
typedef vector<pll> vll;

#define pb push_back
#define bitc  __builtin_popcountl
#define mp make_pair
#define ff first
#define ss second

#define swap(a,b) {a=a^b;b=a^b;a=a^b;}
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)

#ifdef bhartiya
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cout << "\n\nTime elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
}
#else
#define endl '\n'
#define trace(...)
#define start_routine()
#define end_routine()
#endif

#define inf 200000000000000ll
#define mod 1000000007ll
#define eps 1e-7

ll gcd(ll a, ll b){ return b==0 ? a : gcd(b, a%b); }
const ll maxn = 100005;
ll n;
vector<ll> adj[maxn];
ll anser[2][maxn];
ll parent[maxn];

void assignParent(ll s){
    for(auto x: adj[s]){
        if(parent[s] != x){
            parent[x] = s;
            assignParent(x);
        }
    }
}

ll recur(ll s, ll type){
    if(anser[type][s]) return anser[type][s];
    ll ans = 1;
    for(auto x: adj[s]){
        if(parent[s] != x){
            // trace(ans, s, type);
            ll z = recur(x, 1);
            if(type == 1){
               z = (z + recur(x, 0))%mod;
            }
            ans = (ans*z)%mod;
            // trace(ans, s, type);
        }
    }
    return anser[type][s] = ans;
}

int main()
{ 
    start_routine();
	ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.precision(10);
    cin.exceptions(cin.failbit);
    #ifdef bhartiya
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t = 1;
    // cin>>t;
    while(t--){
        cin>>n;
        ll x,y;
        rep(i,n-1){
            cin>>x>>y;
            x--; y--;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        parent[0] = 0;
        assignParent(0);
        // rep(i,n){
        //     trace(i, parent[i]);
        // }
        ll ans = (recur(0,1) + recur(0,0))%mod;
        cout<<ans<<endl;

    }
    end_routine();
}

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

int main() {
	int K,s=0;
	cin >> K;
	vector<vector<int>> g(K, vector<int>(K));

	rep(i,K)
		rep(j,K)
			g.at(i).at(j) = __gcd(i+1, j+1);
		
	rep(i,K)
		rep(j,K)
			rep(k,K)
				s += g.at(g.at(i).at(j)-1).at(k);

	cout << s << endl;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false); 
    string s;
    cin >> s;
    int f=0;
    map<char,int> A;
    REP(i,s.size()){
        A[s[i]]++;
        if(s[i]=='F' && A['C']>0) f=1; 
    }
    cout << ((f)?"Yes":"No") << endl;
}

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

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


    
    for(unsigned int i=1;i<=N;i++){
        sum = sum + i;
    }


    for(unsigned int j=1;j<=N;j++){
        if(j%3==0&&j!=1){
            sum = sum -j;
      
        }
        if(j%5==0&&j!=1){
            sum = sum -j;
       
        }
        if(j%15==0&&j!=1){
            sum = sum +j;
         
        }
    }


    cout << sum << endl; 

}



Measured memory_bytes: 3560
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   long N = sc.nextLong();
 
   long tmp = N;
   long t2 =2;
   String ans ="";
   if(tmp==0) ans = "0";
   for(int i=0;i<33;i++)
   {
     if(tmp==0) break;
     if(tmp%t2!=0) 
     {
       if(i%2==1) tmp = tmp + t2/2;
       else tmp = tmp - t2/2;
       ans= "1"+ans;
     }
     else ans = "0"+ans;
     t2 *=2;
   }
   
   System.out.println(ans);   
 }
}

Measured memory_bytes: 21844
import sys
def input():
    return sys.stdin.readline()[:-1]
N = int(input())
A = list(map(int, input().split()))

chk = [0]*N

A.reverse()
for i, a in enumerate(A):
    if i+1 <= N//2:
        if a == 0:
            continue
        else:
            chk[N-i-1] = 1
            continue
    else:
        sum_chk = sum(chk[N-i-1::N-i])
        s2 = sum_chk%2
        if a == 0:
            if s2 == 0:
                continue
            else:
                chk[N-i-1] = 1
                continue
        else:
            if s2 == 0:
                chk[N-i-1] = 1
                continue
            else:
                continue

M = sum(chk)
b = [i+1 for i, v in enumerate(chk) if v==1]
print(M)
if M != 0: print(*b)

Measured memory_bytes: 14132
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] b = new int[n];
		int[] f = new int[n];
		int[] r = new int[n];
		int[] v = new int[n];

		int[][][] num = new int[4][3][10];

		for (int i = 0; i < n; i++) {
			b[i] = scan.nextInt();
			f[i] = scan.nextInt();
			r[i] = scan.nextInt();
			v[i] = scan.nextInt();

			num[b[i] - 1][f[i] - 1][r[i] - 1] += v[i];
		}

		for (int i = 0; i < 4; i++) {
			for (int j = 0; j < 3; j++) {
				String str = "";
				for (int k = 0; k < 10; k++) {
					str += " " + num[i][j][k]; 
				}
				System.out.println(str);
			}
			if (i != 3) {
				System.out.println("####################");
			}
		}

		scan.close();
	}

}

Measured memory_bytes: 21068
import sys

N = int(sys.stdin.readline().strip())

def f1(p, k):
  # k以下のpの個数（重複あり）
  u = p
  ans = 0
  while u < k:
    ans += k//u
    u = u*p
  return ans

def f2(p, k):
  # k以下のpの個数
  u = p
  ans = {}
  r = 1
  while u < k:
    ans[r] = k//u
    u = u*p
    r = r+1
  return ans

ps = []
for x in range(2, N+1):
  primeflag = True
  for p in ps:
    if (x % p) == 0:
      primeflag = False
      break
  if primeflag == True:
    ps.append(x)

# print(ps)
# 75 = 3 * 5 * 5
# よって75数としてありうる、m = p1^q1 * .. * p_{l_m}^q_{l_m}
# qの組は、(2,4,4), (2,24), (4,14), (74)
# qに対してpの条件は、N以下のpの倍数
# （p^(2以上)があれば重複してカウント）が延べでq以上あること
# q = 74はない

ps_lim = {p: f1(p, N) for p in ps}

ps_2 = [p for p in ps if ps_lim[p] >= 2]
ps_4 = [p for p in ps if ps_lim[p] >= 4]
ps_14 = [p for p in ps if ps_lim[p] >= 14]
ps_24 = [p for p in ps if ps_lim[p] >= 24]
ps_74 = [p for p in ps if ps_lim[p] >= 74]


# 2,4,4の組
sum1 = len(ps_4) * (len(ps_4) - 1) * (len(ps_2) - 2) // 2
# 2, 24の組
sum2 = len(ps_24) * (len(ps_2) - 1)
# 4, 14の組
sum3 = len(ps_14) * (len(ps_4) - 1)
# 74
sum4 = len(ps_74)
sum = sum1 + sum2 + sum3 + sum4

print(sum)

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

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

   cout << 24 + 24 - n << endl;

   return 0;
}

Measured memory_bytes: 256
import math
 
n = int(input())
L = []
for val in range(0,50001):
    L.append(int(val*1.08))
 
#print(L)
 
#ans = int(n/1.08)
ans = math.ceil(n/1.08)
if n in L:
    print(ans)
else:
    print(":(")

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

typedef long long ll;

using namespace std;
int main(){
    int K, S;
    ll ans = 0;
    cin >> K >> S;

    for (int x = 0; x <= K; x++) {
    	for (int y = 0; y <= K; y++) {
    		int z = S - x - y;
    		if (z >= 0 && z <= K) ans++;
    	}
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
from collections import deque
N, M = map(int, input().split())

adj = [[] for i in range(N)]
signs = [-1 for i in range(N)]
# not_patrolled = set(range(1, N))

for _ in range(M):
  x,y = map(int,input().split())
  adj[x - 1].append(y - 1)
  adj[y - 1].append(x - 1)

queue = deque([0])

while len(queue) > 0:
  cur = queue.popleft()
  for i in adj[cur]:
    if signs[i] == -1:
      queue.append(i)
      signs[i] = cur
      # not_patrolled.remove(i)

if all([sign != -1 for sign in signs[1:]]):
  print("Yes")
  for sign in signs[1:]:
    print(sign + 1)
else:
  print("No")

Measured memory_bytes: 35400