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

int N;
vector<vector<int>> edge;
vector<int> df, ds;

void dfs(int at, int from, int d, bool is_f)
{
    if (is_f)
        df[at] = d;
    else
        ds[at] = d;
    for (int next : edge[at]) {
        if (next != from)
            dfs(next, at, d + 1, is_f);
    }
}

int main()
{
    scanf("%d", &N);
    edge = vector<vector<int>>(N, vector<int>());

    int a, b;
    for (int i = 0; i < N - 1; i++) {
        scanf("%d%d", &a, &b);
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    df = vector<int>(N);
    ds = vector<int>(N);
    dfs(0, -1, 0, true);
    dfs(N - 1, -1, 0, false);

    int fennec = 0;
    for (int i = 0; i < N; i++) {
        if (df[i] <= ds[i])
            fennec++;
    }

    if (fennec > N / 2)
        puts("Fennec");
    else
        puts("Snuke");
}

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

n = int(input())
h = list(map(int, input().split()))
dp=[0]*n
dp[1]=abs(h[0]-h[1])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])


Measured memory_bytes: 13708
#include<iostream>
#include<math.h>
using namespace std;
//#define int long long

 signed main() {
 	int a,b,c;
 	cin>>a>>b>>c;
 	int cnt=0;
 	if(a%2==0)cnt++;
 	if(b%2==0)cnt++;
 	if(c%2==0)cnt++;
 	if(cnt>1)cout<<"Tem"<<endl;
 	else cout<<"Hom"<<endl;
 	return 0;
 }


Measured memory_bytes: 3136
a, b, c = map(int, input().split())
d = a - b
e = b - c
f = c - a
if d != 0 and e != 0 and f != 0:
    print(3)
elif d == 0 and e != 0 and f != 0:
    print(2)
elif d != 0 and e == 0 and f != 0:
    print(2)
elif d != 0 and e != 0 and f == 0:
    print(2)
elif d == 0 and e == 0 and f == 0:
    print(1)

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

template <typename T>
void print_vec(vector<T> v) {
  for (T i : v) cout << i << " ";
  cout << endl;
}

int main() {
  vector<int> a(5);
  int mn = 10, l = 0;
  rep(i, 5) {
    cin >> a[i];
    if ((a[i] - 1) % 10 < mn) {
      mn = (a[i] - 1) % 10;
      l = i;
    }
  }
  rep(i, 5) {
    if (i == l) continue;
    if (a[i] % 10 == 0) continue;
    a[i] += 10 - (a[i] % 10);
  }
  int ans = 0;
  rep(i, 5) ans += a[i];
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

const string YES = "YES";
const string NO = "NO";

void solve(std::vector<long long> a, std::vector<long long> b) {
  int deg[4] = {};
  for(int i = 0 ; i < a.size() ; i++){
    deg[a[i]-1]++;
    deg[b[i]-1]++;
  }
  sort(deg, deg + 4);
  if( deg[0] == 1 && deg[1] == 1 && deg[2] == 2 && deg[3] == 2 ){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

}


int main() {
  std::vector<long long> a(3);
  std::vector<long long> b(3);
  for (int i = 0; i < 3; i++) {
    scanf("%lld", &a[i]);
    scanf("%lld", &b[i]);
  }
  solve(std::move(a), std::move(b));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath> 
#define ll long long
using namespace std;
int a[105];
int main(){
	int n,m;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	cin>>m;
	for(int i=0;i<m;i++){
		int x,y,sum=0;
		cin>>x>>y;
		for(int j=1;j<=n;j++){
			if(j!=x)
				sum+=a[j];
			else
				sum+=y;	
		}
		cout<<sum<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int multi4 = 0, even = 0, odd = 0;
  rep(i, n) {
    int num;
    cin >> num;
    if (num % 4 == 0) multi4++;
    if (num % 4 != 0 && num % 2 == 0) even++;
    if (num % 2 != 0) odd++;
  }
  if (odd > multi4) {
    if (odd - multi4 == 1 && even == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;


void solve(long long A, long long B, long long C, long long K){
    vll ans{A, B, C};
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());
    rep(i, K){
        ans[0]*=2;
    }
    ll sum=0;
    rep(i, 3) sum+= ans[i]; 
    cout << sum << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long K;
    scanf("%lld",&K);
    solve(A, B, C, K);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define INF 1e9

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

    int N, M;
    int X, Y;
    vector<int> x, y;

    cin >> N >> M >> X >> Y;
    int num;
    for (int i = 0; i < N; i++) {
        cin >> num;
        x.push_back(num);
    }
    for (int i = 0; i < M; i++) {
        cin >> num;
        y.push_back(num);
    }

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    if (x[N-1] < y[0] && X<y[0] &&x[N-1] < Y) cout << "No War" << endl;
    else cout << "War" << endl;
}

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

class P
{
    static void Main()
    {
        string t = Console.ReadLine();
        bool n = t.Contains('N');
        bool e = t.Contains('E');
        bool w = t.Contains('W');
        bool s = t.Contains('S');
        Console.WriteLine((n && s && !e && !w) || (!n && !s && e && w) || (n && s && e && w) ? "Yes" : "No");
    }
}

Measured memory_bytes: 13268
package main

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

func main()  {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	N, err := strconv.Atoi(scanner.Text())
	if err != nil {
		log.Fatal(err)
	}

	scanner.Scan()
	S := scanner.Text()
	scanner.Scan()
	T := scanner.Text()

	answer := ""

	for i := 0; i < N; i++ {
		answer += S[i:i+1] + T[i:i+1]
	}

	fmt.Println(answer)
}

Measured memory_bytes: 1852
#include <cstdio>
int N, a[100001];
long long S, C;
int main()
{
	scanf("%d", &N);
	if (N == 1)
	{
		puts("YES");
		return 0;
	}
	for (int i = 1; i <= N; i++)
	{
		scanf("%d", a + i);
		S += a[i];
	}
	if (S % ((long long)N * (N + 1) / 2))
	{
		puts("NO");
		return 0;
	}
	S /= (long long)N * (N + 1) / 2;
	for (int i = 1; i <= N; i++)
	{
		long long D = S - a[i % N + 1] + a[i];
		if (D < 0 || D % N)
		{
			puts("NO");
			return 0;
		}
		C += D / N;
	}
	puts(S == C ? "YES" : "NO");
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <queue>
#include <vector>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main(){
    int N, ans = 0;
    cin >> N;
    
    for (int i = 1; i <= N; i+=2) {
        int cnt = 0;
        for (int j = 1; j <= i; j++ ) {
            if ( i%j==0 ) cnt++;
        }
        if (cnt==8) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

n = int(input())
A = list(map(int, input().split()))
g = gcd(A[0], A[1])
for i in range(2,n):
    g = gcd(A[i],g)
print(g)

Measured memory_bytes: 14224
import itertools

N=int(input())
num=[]
for i in range (N):
    num.append(i)

x=[0]*N
y=[0]*N
for i in range (N):
    x[i],y[i]=map(int,input().split())

def dis(a,b):
    return ((x[a]-x[b])**2 + (y[a]-y[b])**2)**(1/2)

l=list(itertools.permutations(num,N))

sum=0
for i in range (len(list(itertools.permutations(num,N)))):
    s=0
    for j in range (N-1):
        s=s+dis(l[i][j],l[i][j+1])
    sum=sum+s

print(sum/len(list(itertools.permutations(num,N))))

Measured memory_bytes: 48748
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main {
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	
	public static FastReader sc = new FastReader();
 
	static int mod = (int) (1e9+7),MAX=(int) (2e5);
	static List<Integer>[] edges;
	public static int[][] parent;
	public static int col = 20;
	public static void main(String[] args) throws IOException{
		
	    
		int a = sc.nextInt();
		int b = sc.nextInt();
		out.print(a*b);
		out.close();
	}
}

Measured memory_bytes: 32796
def readinput():
    a,b,k = list(map(int,input().split()))
    return a,b,k

def main(a,b,k):
    s = set(range(a,min(a+k,b+1)))
    s|=set(range(max(b-k+1,a),b+1))
    ans=sorted(list(s))
    return ans

if __name__=='__main__':
    a,b,k = readinput()
    ans=main(a,b,k)
    for _ in ans:
        print(_)


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        Set<Integer> numberSet = new HashSet<>();
        
        for(int i = 0; i < N; i++) {
            int A = scan.nextInt();
            if(numberSet.contains(A)) numberSet.remove(A);
            else numberSet.add(A);
        }
        
        System.out.println(numberSet.size());
    }
}


Measured memory_bytes: 62432
#include <stdio.h>
int main() {
  char b;
  int k;
  scanf("%c",&b);
  if (b =='A') {
    printf("%c\n",'T');
  }else if(b == 'T'){
    printf("%c\n",'A');
  }else if (b == 'G') {
    printf("%c\n",'C' );
  }else{
    printf("%c\n",'G');
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
bool r[1000001];
int main(){
	int k,dig=1;
	cin>>k;
	int re=7%k;
	if(k%2==0 || k%5==0){
		cout<<-1<<endl;
		return 0;
	}
	while(!r[re]){
		if(re==0){
			cout<<dig<<endl;
			return 0;
		} 
		r[re]==true;
		re=(re*10+7)%k;
		dig++;
	}
	cout<<-1<<endl;
	return 0;
}

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

long long int n;
long double a,p;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	p=3.14159265358979323846;
	a=2*p*n;
	cout<<fixed<<setprecision(10)<<a;
}


Measured memory_bytes: 3752
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
using namespace std;
int top, Stack[1000];
void push(int x) {
	top++;
	Stack[top] = x;
}
int pop() {
	top--;
	return Stack[top + 1];
}
int main()
{
	int a, b;
	char s[100];
	top = 0;
	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s[0] == '*')
		{

			a = pop();
			b = pop();
			push(a*b);
		}
		else
			push(atoi(s));
	}
	cout << pop() << endl;
    return 0;
}



Measured memory_bytes: 3244
import fractions
N = int(input())
A = list(map(int,input().split()))
L = [A[0]]
R = [A[-1]]

for i in range(1,N):
  L.append(fractions.gcd(L[-1],A[i]))
for j in range(N-2,-1,-1):
  R.append(fractions.gcd(R[-1],A[j]))

ans = 0
for m in range(N):
  if m == 0:
    ans = R[-2]
  elif m == N - 1:
    ans = max(ans,L[N-2])
  else:
    M = fractions.gcd(L[m-1],R[N-m-2])
    ans = max(ans,M)
print(ans)

Measured memory_bytes: 16124
#include<bits/stdc++.h>
using namespace std;
#define INF 100000000

int main()
{
  int n,m;cin>>n>>m;
  vector<int> a(m);
  vector<int> b(m);
  vector<int> c(m);
  int i;
  for(i=0;i<m;i++)cin>>a.at(i)>>b.at(i)>>c.at(i);
  int j,k;
  vector<vector<int>> edge(n,vector<int>(n,INF));
  vector<vector<int>> cost(n,vector<int>(n,INF));
  for(i=0;i<n;i++)cost.at(i).at(i)=0;
  for(i=0;i<m;i++)
  {
    a.at(i)--;
    b.at(i)--;
    cost.at(a.at(i)).at(b.at(i))=c.at(i);
    cost.at(b.at(i)).at(a.at(i))=c.at(i);
    edge.at(a.at(i)).at(b.at(i))=c.at(i);
  }
  for(k=0;k<n;k++)
  {
    for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
      {
        cost.at(i).at(j)=min(cost.at(i).at(j),cost.at(i).at(k)+cost.at(k).at(j));
      }
    }
  }
  vector<bool> ch(m,false);
  for(i=0;i<m;i++)
  {
    int hi=a.at(i);
    int hj=b.at(i);
    int s,t;
    for(s=0;s<n;s++)
    {
      for(t=0;t<n;t++)
      {
        if(cost.at(s).at(hi)+edge.at(hi).at(hj)+cost.at(hj).at(t)==cost.at(s).at(t))
        {
          ch.at(i)=true;
        }
      }
    }
  }
  int ans=0;
  for(i=0;i<m;i++)if(!ch.at(i))ans++;
  cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

vector <int> conn[5050];
vector <int> son[5050];
bool dchk[5050];

ll cnt[5050];
ll dp[5050][5050];
int sz[5050];

ll tdp[5050];
ll tdp2[5050];
void DFS(int n) {
	dchk[n] = true;
	sz[n] = 1;
	for (auto it : conn[n]) {
		if (dchk[it]) continue;
		DFS(it);
		sz[n] += sz[it];
		son[n].push_back(it);
	}

	int cur = 0;
	tdp[0] = 1;
	for (auto it : son[n]) {
		memset(tdp2, 0, sizeof(tdp2));
		for (int i = 0; i <= cur; i++) {
			for (int j = 0; j <= sz[it]; j++) {
				tdp2[i + j] = (tdp2[i + j] + tdp[i] * dp[it][j]) % MOD;
				
				ll v = tdp[i] * dp[it][j] % MOD;
				tdp2[i] = (tdp2[i] - v * cnt[j]) % MOD;
			}
		}
		cur += sz[it];
		for (int i = 0; i <= cur; i++) tdp[i] = (tdp2[i] + MOD) % MOD;
	}
	for (int i = 1; i <= cur + 1; i++) dp[n][i] = tdp[i - 1];
}
int main() {
	int N, i, j;
	scanf("%d", &N);
	for (i = 1; i < N; i++) {
		int t1, t2;
		scanf("%d %d", &t1, &t2);
		conn[t1].push_back(t2);
		conn[t2].push_back(t1);
	}
	cnt[2] = 1;
	for (i = 4; i <= 5000; i++) cnt[i] = (cnt[i - 2] * (i - 1)) % MOD;
	DFS(1);

	ll ans = 0;
	for (i = 2; i <= N; i += 2) ans += dp[1][i] * cnt[i] % MOD;
	printf("%lld\n", (ans + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 198912
<?php
fscanf(STDIN, "%d", $n);
for($i = 0; $i < 2; $i++){
    $field[] = array_map('intval', explode(" ", fgets(STDIN)));
}
$scores = array();
$S[0] = $field[0][0];
for($i=0; $i<$n; $i++){//どこで下に行くか
    $cnt=1;
    $S[1] = $S[0] + $field[1][$i];
    $cnt++;
    for($j=1;$j<$n;$j++){
        if($j<=$i){
           $S[$cnt]= $S[$cnt-1] + $field[0][$j];
           $cnt++;
        }else{
           $S[$cnt]= $S[$cnt-1] + $field[1][$j];
           $cnt++;
        }
    }
    $scores[] = $S[$n];
}
rsort($scores);
echo $scores[0];

Measured memory_bytes: 4604
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if((a>=0)&&(b>=0)&&(c>=0)&&(a<=10000)&&(b<=10000)&&(c<=10000)){
        if(a<b){
            if(b<c){
                printf("%d %d %d\n",a,b,c);
            }
            else if(c<b){
                printf("%d %d %d\n",a,c,b);
            }
        }else if(b<c){
            if(a<c){
                printf("%d %d %d\n",b,a,c);
            }
            else if(c<a){
                printf("%d %d %d\n",b,c,a);
            }
        }else if(c<a){
            if(a<b){
                printf("%d %d %d\n",c,a,b);
            }
            else if(b<a){
                printf("%d %d %d\n",c,b,a);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i=0; i<n; i++) {
    cin >> v[i];
  }

  sort(v.begin(), v.end());

  int ans=accumulate(v.begin(), v.end(), 0, [](int x, int y){return x+=y-x;});

  printf("%d\n", ans-v[0]);
  return 0;
}

Measured memory_bytes: 256
-- https://atcoder.jp/contests/abc173/tasks/abc173_c

import Control.Applicative
import Control.Monad
import Data.List

type Line = String
type Lines = [String]

-- white = '.'
black = '#'
red = '*'

fillRed :: Line -> Line
fillRed l = replicate (length l) red

fillLines :: Lines -> [Lines]
fillLines [line] = [[line], [fillRed line]]
fillLines (line:lines) = f line ++ f (fillRed line)
  where f l = map (l:) $ fillLines lines

countBlack :: Lines -> Int
countBlack = foldr ((+) . f black) 0
  where f x = foldr ((+) . (\y -> if x == y then 1 else 0)) 0

main :: IO ()
main = do
  [h, w, k] <- map read . words <$> getLine
  ls <- replicateM h getLine
  let filledPatterns = concatMap (map transpose . fillLines . transpose) $ fillLines ls
  print . length $ filter (\x -> countBlack x == k) filledPatterns


Measured memory_bytes: 4944
def d_unbalanced(S):
    S_length = len(S)
    s = S + '##'  # 統一的に扱うため、アルファベットでない文字を番兵とする
    for i in range(S_length):
        # どちらかを満たす文字列をアンバランスなものとして出せばいい
        # 全部調べても成り立たなければ、アンバランスな文字列はない
        if s[i] == s[i + 1]:  # XXと文字が並んでいる
            return '{} {}'.format(i + 1, i + 2)
        elif s[i] == s[i + 2]:  # XYXと文字が並んでいる
            return '{} {}'.format(i + 1, i + 3)
    # アンバランスな文字列はなかった
    return '-1 -1'

S = input().strip()
print(d_unbalanced(S))

Measured memory_bytes: 3188
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args){
        InputStreamReader inputStreamReader = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(inputStreamReader);

        String str;
        int[] num = new int[2];
        try {
            while(reader.ready()){
                str = reader.readLine();
                num = getNum(str);
                System.out.println(cntDigit(num[0] + num[1]));
            }   
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static int[] getNum(String str){
        String[] data = str.split(" "); 
        int[] num = new int[data.length];

        for (int i = 0; i < data.length; i++){
            num[i] = Integer.parseInt(data[i]);
        }
        return num;
    }

    private static int cntDigit(int num) {
        int n = 1;
        while(num >= 10) {
            n++;
            num /= 10;
        }
        return n;
    }
}


Measured memory_bytes: 24424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18,MOD = 1e9 + 7;
const int INT_INF = 1e9,INT_MOD=1e9+7;
#define rep(i, N) for(int i = 0; i < N; i++)
typedef pair<int, int> Pi;
typedef pair<double, double> P;
signed main(){
    int h,n;cin>>h>>n;
    int waza[n];
    int ans=0;
    rep(i,n){
        int p;cin>>p;
        ans+=p;
    }
    if(ans>=h) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
xyz = []
sings = [[1, 1, 1], [1, 1, -1], [1, -1, 1], [-1, 1, 1],
         [1, -1, -1], [-1, 1, -1], [-1, -1, 1], [-1, -1, -1]]
ans = [0 for _ in range(len(sings))]

for _ in range(n):
    xyz.append(list(map(int, input().split())))

for i in range(len(sings)):
    sum_xyz = [0 for _ in range(n)]
    for j, (x, y, z) in enumerate(xyz):
        sum_xyz[j] = (x*sings[i][0])+(y*sings[i][1])+(z*sings[i][2])
    sum_xyz = sorted(sum_xyz, reverse=True)
    ans[i] = sum(sum_xyz[:m])
print(max(ans))


Measured memory_bytes: 3316
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
int main()
{
	int h, w, k;
	cin>>h>>w>>k;
	ll dp[8][101]={};
	k--;
	ll ct[9]={};
	ct[0]=ct[1]=1;
	for(int i=1; i<w; i++){
		ct[i+1]=(ct[i]+ct[i-1])%MOD;
	}
	dp[0][0]=1;
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			ll c=ct[w];
			if(j>0){
				ll c1=ct[j-1]*ct[w-j-1]%MOD;
				c=(c-c1+MOD)%MOD;
				dp[j-1][i+1]+=(dp[j][i]*c1);
				dp[j-1][i+1]%=MOD;
			}
			if(j<w-1){
				ll c1=ct[j]*ct[w-j-2]%MOD;
				c=(c-c1+MOD)%MOD;
				dp[j+1][i+1]+=(dp[j][i]*c1);
				dp[j+1][i+1]%=MOD;
			}
			dp[j][i+1]+=(dp[j][i]*c);
			dp[j][i+1]%=MOD;
		}
	}
	cout<<dp[k][h]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <string>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;

template<class T> bool chmin(T &a, T b) { return a>b?(a=b,true):false; }
template<class T> bool chmax(T &a, T b) { return a<b?(a=b,true):false; }
#define forn(i,x,y) for(int i=(x);i<(int)(y);i++)
#define rep(i,y) for(int i=0;i<(int)(y);i++)
#define repb(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)

template<class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto it = v.begin(); it != v.end(); ++it) {
    if (it != v.begin()) os << " ";
    os << *it;
  }
  return os;
}

string s;
int cnt;
int main() {
  cin >> s;
  for (char c : s) {
    if (c=='2') cnt++;
  }
  cout << cnt << endl;
}


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};
bool dp[100010];

int main() {
  string S;
  cin >> S;

  dp[0]= 1;
  for (int i = 0; i < S.size(); i++) {
    if(!dp[i])continue; // そこまでで矛盾があったらとりあえず無視
    for(string s : divide) {
      if(S.substr(i, s.size()) == s){ // うまく切れたら先に進む
        dp[i + s.size()] = 1;
      }
    }
  }
  cout << (dp[S.size()] ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <functional>
#include <set>
#include <map>
#define DB cerr<<"D"<<endl
#define pb push_back
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";}
using P=pair<int,int>;
const ll M = 1e9+7, mx = 301;
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; void chmax(ll& x, ll y) {if (x<y) x=y;}; void chmin(ll& x, ll y) {if (x>y) x=y;};
ll pou(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x; x = x * x; a >>= 1;} return an;}

int main() {
  int n; cin>>n;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  ll all = 0;
  for(int i=0;i<n;i+=2) {
    all ^= (a[i]^a[i+1]);
  }
  for(int i=0;i<n;i++) {
    cout<<(all^a[i])<<" ";
  } cout<<endl;
}

Measured memory_bytes: 5124
import heapq
from collections import deque
s = input()
s_list = list(s)
s_list = deque(s_list)
q = int(input())
q_list = []
for i in range(q):
  q_list.append(list(map(str,input().split())))
check = 0
for list_ in q_list:
  if int(list_[0]) == 1:
    check += 1
  if int(list_[0]) == 2:
    if (int(list_[1]) + check) % 2 ==1:
      s_list.appendleft(list_[2])
    else:
      s_list.append(list_[2])
s_list = list(s_list)
if check % 2 == 1:
  s_list = s_list[::-1]
print("".join(s_list))
    

Measured memory_bytes: 46172
import collections
import math

def combinations_count(n, r):
    if n < 2:
        return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
a_list = list(map(int, input().split()))
a_col = collections.Counter(a_list)
c_dic = {}
sm = sum([c * (c - 1) for c in a_col.values()]) // 2
for a in a_list:
    if a in c_dic:
        print(c_dic[a])
    else:
        ans = sm - combinations_count(a_col[a], 2) + combinations_count(a_col[a] - 1, 2)
        print(ans)
        c_dic[a] = ans

Measured memory_bytes: 120908
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

ll N;
ll A[202020], B[202020];
stack<ll>S;
ll push(ll b){
    if(A[b] > B[b])return -1;
    ll a = (b + N - 1) % N;
    ll c = (b + 1) % N;
    if(B[a] < B[b] && B[b] > B[c])S.push(b);
    return 0;    
}

ll solve(){
    cin >> N;
    rep(i, N)cin >> A[i];
    rep(i, N)cin >> B[i];
    ll ans = 0;
    rep(b, N)if(push(b) < 0)return -1;
    while(!S.empty()){
        ll b = S.top();
        S.pop();
        ll a = (b + N - 1) % N;
        ll c = (b + 1) % N;
        ll diff = B[b] - A[b];
        ll sum = B[a] + B[c];
        ll tmp = diff / sum;
        B[b] -= tmp * sum;
        ans += tmp;
        if(push(a) < 0)return -1;
        if(push(c) < 0)return -1;
    }
    rep(i, N)if(A[i] != B[i])return -1;
    return ans;
}

int main(){

    cout << solve() << endl;

    return 0;
}

Measured memory_bytes: 4224
#include<iostream>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
const int NMAX = 200000;

int bit[NMAX + 1], n;

int sum(int i) {
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i = i & (i - 1);
  }
  return s;
}

void add(int i, int x) {
  while (i <= n) {
    bit[i] += x;
    i += i & -i;
  }
}

int sum(int s, int t) {
  return s == 0 ? sum(t) : sum(t) - sum(s - 1);
}

int main() {
  int Q;
  cin >> n >> Q;
  REP(i, Q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      add(x, y);
    } else {
      cout << sum(x, y) << endl;
    }
  }
}

Measured memory_bytes: 1548
#pragma warning(disable : 4996)
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
// https://atcoder.jp/contests/abc169/tasks/abc169_a
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll a,b;
    cin >> a >> b;
    cout << a * b;

    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> PLL;

#define x first
#define y second

const ll N = 1e3 + 10;
const ll M = 6e3 + 10;
const ll dx[] = { 1, 0, -1, 0 };
const ll dy[] = { 0, -1, 0, 1 };

ll u[N], d[N], x[N], l[N], r[N], y[N];
bool wall[M][M], st[M][M];
ll n, m, h, w;

vector<ll> cmpX, cmpY;

void cmp(vector<ll> &v) {
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

ll get(vector<ll> &v, ll x) {
	return lower_bound(v.begin(), v.end(), x) - v.begin();
}

void dfs(ll x, ll y) {
	st[x][y] = true;
	queue<PLL> q;
	q.push(make_pair(x, y));

	while (q.size()) {
		x = q.front().x, y = q.front().y; q.pop();
		for (ll i = 0; i < 4; i++) {
			ll nx = x + dx[i], ny = y + dy[i];
			if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if (st[nx][ny] || wall[nx][ny]) continue;
			st[nx][ny] = true;
			q.push(make_pair(nx, ny));
		}
	}
}

int main() {
	cin >> n >> m;
	for (ll i = 1; i <= n; i++) cin >> u[i] >> d[i] >> x[i];
	for (ll i = 1; i <= m; i++) cin >> y[i] >> l[i] >> r[i];

	cmpX.push_back(-2e9), cmpX.push_back(2e9);
	cmpY.push_back(-2e9), cmpY.push_back(2e9);

	for (ll i = 1; i <= n; i++) cmpX.push_back(x[i]), cmpY.push_back(u[i]), cmpY.push_back(d[i]);
	for (ll i = 1; i <= m; i++) cmpY.push_back(y[i]), cmpX.push_back(l[i]), cmpX.push_back(r[i]);
	cmp(cmpX), cmp(cmpY);
	w = cmpX.size() * 2, h = cmpY.size()*2;

	for (ll i = 1; i <= n; i++){
		ll U = get(cmpY, u[i]) * 2, D = get(cmpY, d[i]) * 2, X = get(cmpX, x[i])*2;
		for (ll j = U; j <= D; j++) wall[X][j] = true;
	}

	for(ll i = 1; i <= m; i++){
		ll L = get(cmpX, l[i]) * 2, R = get(cmpX, r[i])*2, Y = get(cmpY, y[i])*2;
		for (int j = L; j <= R; j++) wall[j][Y] = true;
	}

	ll sx = get(cmpX, 0) * 2 - 1, sy = get(cmpY, 0) * 2 - 1;

	dfs(sx, sy);

	ll res = 0;
	for (ll x = 0; x < w; x++) {
		for (ll y = 0; y < h; y++) {
			if (!st[x][y]) continue;
			if (x == 0 || x >= w - 2 || y == 0 || y >= h - 2) {
				cout << "INF" << endl;
				return 0;
			}
			if (x % 2 == 0 || y % 2 == 0) continue;
			ll X = x / 2, Y = y / 2;
			if (X + 1 >= cmpX.size() || Y + 1 >= cmpY.size()) {
				cout << "INF" << endl;
				return 0;
			}
			res += (cmpX[X + 1] - cmpX[X]) * (cmpY[Y + 1] - cmpY[Y]);
		}
	}

	cout << res << endl;

	return 0;
 }

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

int H, W, N;
map<int, int> mp;
int cnt[10];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> H >> W >> N;
    rep(i, N) {
        int a, b; cin >> a >> b;
        a--;
        b--;
        for (int i=a-2; i<=a; i++) {
            for (int j=b-2; j<=b; j++) {
                if (0<=i && i<=H-3 && 0<=j && j<=W-3) mp[W*i+j]++;
            }
        }
    }
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        int v = it->second;
        cnt[v]++;
    }
    cnt[0] = (H-2)*(W-2);
    for (int i=1; i<=9; i++) cnt[0] -= cnt[i];
    rep(i, 10) cout << cnt[i] << endl;
}

Measured memory_bytes: 56576
#include<bits/stdc++.h>
using namespace std;
int x,y;
int main() {
	cin>>x>>y;
	if(x>0)
		cout<<"Positive";
	else if(x==0||(x<0&&y>0))
		cout<<"Zero";
	else if((abs(y)-abs(x))%2!=0)
		cout<<"Positive";
	else
		cout<<"Negative";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int vis[201][201];
int gcd(int x,int y)
{   if(vis[x][y]) return vis[x][y];
    if(!y) return x;
    return vis[x][y]=gcd(y,x%y);
}
int main()
{   int n,sum=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
           for(int t=1;t<=n;t++)
    {   int x=gcd(i,j);
        sum=sum+gcd(x,t);

    }
    cout<<sum;

    return 0;
}


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

using LL = long long;
using LD = long double;
 
LL mod = 1e9+7;

int main()
{
	string s;
	cin >> s;
	string ans;
	if (s == "ABC") {
		ans = "ARC";
	}
	else {
		ans = "ABC";
	}
	cout << ans <<"\n";

}

Measured memory_bytes: 3632
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
for i in range(n):
  if a[i] <= b[i]:
    if a[i+1] >= b[i] - a[i]:
      ans += b[i]
      a[i+1] -= b[i] - a[i]
    else:
      ans += a[i] + a[i+1]
      a[i+1] = 0
  else:
    ans += b[i]
print(ans)


Measured memory_bytes: 24024
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
typedef pair<ll,ll> pll;
typedef pair<pll,pll> ppll;
typedef vector <ll> vi;
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define lc(n) 2*n+1
#define rc(n) 2*n+2
# define INF 0x3f3f3f3f
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));

int main(){
	FAST;
    ll n, k, m, z = 0, ans = 0, j, t = 0, x = 0, y = 0, c = 0, i;
    cin >> n >> m;  
    string s;
    ll a[n + 1] = { 0 };
    bool b[n + 1] = { 0 };
    for ( i = 0 ; i < m ; i ++ ){
    	cin >> x >> s;
    	if ( s == "AC" ){
    		b[x] = 1;
    	}
    	else if ( b[x] == 0 ){
    		a[x] ++;
    	}
    }
    for ( i = 0 ; i < n + 1 ; i ++ ){
    	if ( b[i] == 1 ){
    		ans ++;
    		c += a[i];
    	} 
    }
    cout << ans << " " << c;
}

Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
	class Program
	{

		static void Main(string[] args)
		{
			var K = int.Parse(Console.ReadLine());
			var valueList = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

			var A = valueList[0];
			var B = valueList[1];

			var flag = false;

			for(int i = A;i <= B; i++)
			{
				if(i % K == 0)
				{
					flag = true;
					break;
				}
			}

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

		}
	}
}

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

int main() {
  int N;
  int cnt=0;
  cin >> N;
  for(int i=0; i<=6; i+=2) {
    cnt += max(0, (min(N, (int)pow(10, i+1)-1) - (int)pow(10, i) + 1));
  }
  cout << cnt << endl;
  return 0;
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;
const ll inf = 1e10;


// 1 2 3 4   5 6 7
// A i B C x D E F
// F E D C B y i A
// 1 2 3 4 5 6 7 8

ll solve(ll x, ll y) {


    function<bool(ll)> ok = [&](ll cnt) {
	ll mx = 0;
	for (ll i=max(1ll, cnt/2 - 10); i<= min(cnt, cnt/2 + 10); i++) {
	    ll lo = i;
	    if (lo >= x) lo++;
	    ll hi = cnt-i+1;
	    if (i <= cnt-y+1) hi++;
	    mx = max(mx, lo*hi);		
	}
	return mx < x*y;
    };


    
    ll lo = 0;
    ll hi = inf;
    while (hi-lo>1) {
	ll mid = (hi+lo)/2;
	if (ok(mid)) {
	    lo = mid;
	} else {
	    hi = mid;
	}
    }

    return lo;
}



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

    int t; cin>>t;
    while (t--) {
	ll a,b;
	cin>>a>>b;
	cout<<solve(a,b)<<"\n";
    }
    
    
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define Int int64_t
#define dump(x) cout << (x) << endl
#define fi first
#define se second
Int mod = 1e9+7;
Int INF = 1e18;
double EPS = 0.00000001;
//Int mod = 1e6+3;

string f(Int x) {
    string s = "";
    while (x > 0) {
        if (x % 2 == 0) {
            s = '0' + s;
        }
        else {
            s = '1' + s;
        }
        x /= 2;
    }
    while (s.size() < 10) s = '0' + s;
    return s;
}

int main() {
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) cin >> a[i];
    vector<Int> b(n + 1, 0), c(n + 1, 0);
    for (Int i = 0; i < n; i++) b[i + 1] += b[i] + a[i];
    for (Int i = 0; i < n; i++) c[i + 1] ^= c[i] ^ a[i];
    //for (Int i = 0; i < n; i++) dump(f(a[i]));
    Int l = 0;
    Int r = 1;
    Int res = 0;
    while (l < r && r <= n) {
        if ((b[r] - b[l]) == (c[r] ^ c[l])) {
           // cout << l << " " << r << endl;
            res += r - l;
            r++;
        }
        else {
            l++;
            if (l == r) r++;
        }
    }
    dump(res);
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
//#pragma GCC target("avx,avx2,sse4.2")
#define re register
#define rep(q, a, b) for (re int q = a, q##_end_ = b; q <= q##_end_; ++q)
#define dep(q, a, b) for (re int q = a, q##_end_ = b; q >= q##_end_; --q)
#define mem(a, b) memset(a, b, sizeof a)
#define debug(a) cerr << #a << ' ' << a << "___" << endl
using namespace std;
//char buf[10000000], *p1 = buf, *p2 = buf;
#define Getchar() getchar()//p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000000, stdin), p1 == p2) ? EOF : *p1++
template<typename T>
void in(T &r) {
    static char c;
    r = 0;
    while (c = Getchar(), c < 48)
        ;
    do
        r = (r << 1) + (r << 3) + (c ^ 48);
    while (c = Getchar(), c > 47);
}
const int mn=100005;
const int mod=1e9+7;
int head[mn],ne[mn<<1],to[mn<<1],cnt1,n,k;
#define link(a,b) link_edge(a,b),link_edge(b,a)
#define link_edge(a,b) to[++cnt1]=b,ne[cnt1]=head[a],head[a]=cnt1
#define travel(x) for(int q(head[x]);q;q=ne[q])
int dp[mn],mul[mn],inv[mn];
int A(int a,int b){
	if(a>b)return 0;
	return 1LL*mul[b]*inv[b-a]%mod;
}
int dfs(int f,int x){
	int tem=1,cnt=0;
	travel(x)if(to[q]!=f)tem=1LL*tem*dfs(x,to[q])%mod,++cnt;
	if(x!=1)tem=1LL*tem*A(cnt,k-2)%mod;
	else tem=1LL*tem*A(cnt+1,k)%mod;
	return tem;
}
int main(){
	in(n),in(k);
	mul[0]=1;
	rep(q,1,k)mul[q]=1LL*mul[q-1]*q%mod;
	inv[0]=inv[1]=1;
	rep(q,2,k)inv[q]=1LL*(mod-mod/q)*inv[mod%q]%mod;
	rep(q,1,k)inv[q]=1LL*inv[q-1]*inv[q]%mod;
	int a,b;
	rep(q,2,n)in(a),in(b),link(a,b);
	printf("%d",dfs(0,1));
	return 0;
}

Measured memory_bytes: 6912
const MOD: usize = 998244353;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let n: usize = sc.read();
    let m: usize = sc.read();
    let a: Vec<Vec<i64>> = (0..n).map(|_| sc.vec(m)).collect();
    let rank = f2_gauss_jordan(a);

    let mut pow2 = vec![1; n + m + 1];
    for i in 1..pow2.len() {
        pow2[i] = (pow2[i - 1] * 2) % MOD;
    }

    let ans = pow2[n + m - 1] + MOD - pow2[n + m - rank - 1];
    println!("{}", ans % MOD);
}

fn f2_gauss_jordan(mut a: Vec<Vec<i64>>) -> usize {
    let n = a.len();
    let m = a[0].len();
    let mut rank = 0;
    let mut row = 0;
    for col in 0..m {
        match (row..n).filter(|&i| a[i][col] == 1).next() {
            Some(pivot) => {
                a.swap(row, pivot);
                rank += 1;
                for k in (row + 1)..n {
                    if a[k][col] == 1 {
                        for i in 0..m {
                            a[k][i] ^= a[row][i];
                        }
                    }
                }

                row += 1;
            }
            None => {}
        }

        if row >= n {
            break;
        }
    }
    rank
}

pub struct Scanner<R> {
    stdin: R,
}

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


Measured memory_bytes: 4352
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;


fn main() {
    input!{
        N: usize, A: i64,
        X: [i64; N]
    }
    let Y = X.into_iter().map(|x| x - A).collect::<Vec<i64>>();
    let mut dp: Vec<Vec<i64>> = vec![vec![0; 5001]; N+1];

    dp[0][2500] = 1;

    for i in 1..N+1 {
        let yi = Y[i-1];
        for j in 0..(5001 as usize) {
            let sum = j as i64 - yi;
            if sum < 0 || sum > 5000 {
                dp[i][j] += dp[i-1][j]
            } else if sum >= 0 && sum <= 5000 {
                dp[i][j] += dp[i-1][j] + dp[i-1][sum as usize];
            }
        }
    }
    println!("{}", dp[N][2500] - 1);

}

Measured memory_bytes: 6396
#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
using namespace std;

#define pa pair<int,int>
#define sc(n) scanf("%d",&n)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define mem(a,b) memset(a,b,sizeof a)

const  int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

typedef long long ll;
typedef long double ld;

int n, t;
int a[N];

int main()
{
	int x, y, z;
	cin >> x >> y >> z;
	cout << z - min(z, x - y) << endl;
}

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

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  cout << fixed << setprecision(10);
  double answer_r1 = atan(2*(b-x/pow(a, 2))/a);
  double answer_r2 = atan(a*pow(b, 2)/(2*x));
  double answer_d;
  if (b-a*tan(answer_r1) <= 0) {
    answer_d = 180*answer_r2/(atan(1.0)*4);
  }
  else {
    answer_d = 180*answer_r1/(atan(1.0)*4);
  }
  cout << answer_d << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(obj) begin(obj), end(obj)
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
using ll      = long long;
const int MOD = (int)(1e9 + 7);
const int INF = (int)(1e13 + 7);

int ceil_(int a, int b) { return (a + (b - 1)) / b; }
int positive_surplus(int &a) { return (a + MOD) % MOD; }
int bpm(int x, unsigned int y) {
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (unsigned int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

signed main() {
  int N;
  cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  rep(i, N) cin >> a[i];
  rep(i, N) cin >> b[i];
  int sum_a = accumulate(ALL(a), 0LL);
  int sum_b = accumulate(ALL(b), 0LL);
  if (sum_b < sum_a) {
    cout << "No" << endl;
    return 0;
  }
  int k     = sum_b - sum_a;
  int num_a = 0, num_b = 0;
  rep(i, N) {
    if (a[i] >= b[i]) {
      num_b += (a[i] - b[i]);
    } else {
      if ((b[i] - a[i]) % 2) {
        num_a += (b[i] - a[i] + 1) / 2;
        num_b += 1;
      } else {
        num_a += (b[i] - a[i]) / 2;
      }
    }
  }
  if ((k - num_a) * 2 == (k - num_b) and k >= num_a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
import numpy as np

n, m = map(int, input().split())
graph = np.zeros((n, n), dtype=np.int8)
for _ in range(m):
    a, b = map(int, input().split())
    graph[a-1, b-1] = 1
    graph[b-1, a-1] = 1

def dfs(node, visited):
    if sum(visited) == n:
        return 1
    res = 0
    for i in range(n):
        if graph[node, i] and not visited[i]:
            visited[i] = 1
            res += dfs(i, visited)
            visited[i] = 0
    return res

print(dfs(0, [1] + [0] * (n - 1)))


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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define INF 		2000000007
#define MOD			10e9+7
#define MAX 		100005

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

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

int main(){
	ll A,B;
	int C,D;cin>>A>>B>>C>>D;
	A--;

	ll CD = (ll)C*D/gcd(C,D);

	ll cntA = A/C + A/D - A/CD;
	ll cntB = B/C + B/D - B/CD;

	cout << ((B-A) - (cntB - cntA)) << endl;

	return 0;
}



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

int main()
{
  int n,count=0;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  for(int i=0;i<n;i++)
  {
    if(arr[i]%2==0)
    {
      if(arr[i]%3!=0 && arr[i]%5!=0)
        count=1;
    }
  }
  if(count==1)
    cout<<"DENIED";
  else
    cout<<"APPROVED";
  return 0;
}

Measured memory_bytes: 256