akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int zyun(int x)
{
  string src = to_string(x);
  string t = "";
  for(int i=0; i<src.length(); i++) {
    t += src.substr(i,1);
  }
  return stoi(t);
}

int gyaku(int x)
{
  string src = to_string(x);
  string t = "";
  for(int i=src.length(); i>0; i--) {
    t += src.substr(i-1,1);
  }
  return stoi(t);
}

int main() {
  string a, b;
  cin >> a >> b;

  int cnt=0;
  for(int i=stoi(a); i<=stoi(b); i++)
  {
    int A,B;
    A = zyun(i);
    B = gyaku(i);
    if(A == B) {
      cnt++;
    }
  }
  cout << cnt << endl;
  return(0);
}

Measured memory_bytes: 256
N = int(raw_input())
lst = map(int, raw_input().split())
cnt = 0
for i in range(0, len(lst)):
    m = i
    for j in range(i, len(lst)):
        if lst[m] > lst[j]:
            m = j
    if m != i:
        lst[i], lst[m] = lst[m], lst[i]
        cnt+=1

print " ".join(map(str,lst))
print (cnt)

Measured memory_bytes: 6372
#include<stdio.h>
//#include<math.h>
int ifcl(int p0[2],int p1[2],int p2[2],int p3[2]){
  long long x0=p1[0]-p0[0],x1=p2[0]-p0[0],x2=p3[0]-p0[0]/*,x3=x2-x1,x4=x0-x1,x5=-x1*/;
  long long y0=p1[1]-p0[1],y1=p2[1]-p0[1],y2=p3[1]-p0[1]/*,y3=y2-y1,y4=y0-y1,y5=-y1*/;
  long long x3=p3[0]-p2[0],x4=p1[0]-p2[0],x5=p0[0]-p2[0];
  long long y3=p3[1]-p2[1],y4=p1[1]-p2[1],y5=p0[1]-p2[1];
  long long x6=p2[0]-p1[0],x7=p3[0]-p1[0]/*,x3=x2-x1,x4=x0-x1,x5=-x1*/;
  long long y6=p2[1]-p1[1],y7=p3[1]-p1[1]/*,y3=y2-y1,y4=y0-y1,y5=-y1*/;
  
  long long c1=(x0*y1-y0*x1)*(x0*y2-y0*x2),c2=(x3*y4-y3*x4)*(x3*y5-y3*x5);
  long long d1=x1*x6+y1*y6,d2=x2*x7+y2*y7,d3=x1*x2+y1*y2,d4=x6*x7+y6*y7;
  if(c1==0&&c2==0){
    if(d1>0&&d2>0&&d3>0&&d4)return 0;
    else          return 1;
  }
  if(c1<=0&&c2<=0)return 1;
  else return 0;
}
/*double dMIN(double a,double b){return a<b?a:b;}
double drpl(int p0[2],int p1[2],int p2[2]){
  int a=p0[1]-p1[1],b=p0[0]-p1[0],c=p0[0]*p1[1]-p1[0]*p0[1];
  int d=p2[1]-p1[1],e=p2[0]-p1[0];
  int f=p2[1]-p0[1],g=p2[0]-p0[0];
  if(a*d+b*e<0||a*f+b*g>0)return dMIN(hypot(d,e),hypot(f,g));
  return abs(p2[0]*a-p2[1]*b+c)/hypot(a,b);
}
double drll(int *p0,int *p1,int *p2,int *p3){
  double l=drpl(p2,p3,p0);
  l=dMIN(l,drpl(p2,p3,p1));
  l=dMIN(l,drpl(p0,p1,p2));
  l=dMIN(l,drpl(p0,p1,p3));
  if(ifcl(p0,p1,p2,p3))l=0;
  return l;
  }*/
int main(){
  int p[4][2],n,i;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<8;i++)scanf(" %d",&p[i/2][i%2]);
    printf("%d\n",ifcl(p[0],p[1],p[2],p[3]));
  }
  return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		int c = stdIn.nextInt();
		
		if(a+b==c || b+c==a || c+a == b) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		
	}

}


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

using namespace std ;

int main(){
    int a ;
    cin >> a ;
    long long int n[a] ;
    long long int sum = 0 ;
    for(int i=0;i < a;i++){
        cin >> n[i] ;
        if(i > 0 && n[i] < n[i-1]){
            sum += n[i-1] - n[i] ;
            n[i] = n[i-1] ;
    }
    }
    cout << sum << endl ;
    return 0 ;
    }


Measured memory_bytes: 5188
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000)
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def lsi():
    x=list(stdin.readline())
    x.pop()
    return x
def si(): return stdin.readline().rstrip()
#mod=1000000007
res=['Yes', 'No']
############# CODE STARTS HERE #############
a, b, c, d=mi()
f=0
if ceil(c/b)>ceil(a/d):
    f=1
print(res[f])

Measured memory_bytes: 9468
#include <stdio.h>

long long gcd(long long n, long long m);

int main()
{
    long long a, b, c, d;
    long long lc;

    scanf("%lld %lld", &a, &b);
    scanf("%lld %lld", &c, &d);

    lc = c * d / gcd(c, d);

    printf("%lld\n",
           (b - a + 1)
           - (b / c - (a - 1) / c)//cで割り切れる
           - (b / d - (a - 1) / d)//dで割り切れる
           + (b / lc - (a - 1) / lc));

    return 0;
}

long long gcd(long long n, long long m)
{
    if (m < n) {
        long long tmp = n;
        n = m;
        m = tmp;
    }

    while (n) {
        long long r = m % n;
        
        m = n;
        n = r;
    }

    return m;
}


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

int main()
{
  int N;
  
  cin >> N;
  
  if ( N%10 == N/10%10)
    if ( N/10%10 == N/100%10)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  else if ( N/10%10 == N/100%10)
    if ( N/100%10 == N/1000)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 20;

int a[N], x[N][N], y[N][N];
int n, ans;

int main() {
    read(n);
    for(register int i = 1; i <= n; i++) {
        read(a[i]);
        for(register int j = 1; j <= a[i]; j++) {
            read(x[i][j]); read(y[i][j]);
        }
    }
    for(register int state = 0; state < (1 << n); state++) {
        bool ok = 1;
        for(register int i = 1; i <= n; i++) {
            if((state >> (i - 1)) & 1) {
                for(register int j = 1; j <= a[i]; j++) {
                    if(((state >> (x[i][j] - 1)) & 1) != y[i][j]) {
                        ok = 0;
                        break;
                    }
                }
            }
            if(!ok) break;
        }
        if(ok) ans = max(ans, __builtin_popcount(state));
    }
    print(ans, '\n');
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

struct Node {
	int k, d, f;
	vector<int> v;
};

#define MAX_N 100

Node node[MAX_N + 1];

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int u;
		cin >> u;
		cin >> node[u].k;
		for (int j = 0; j < node[u].k; ++j) {
			int v;
			cin >> v;
			node[u].v.push_back(v);
		}
		node[u].d = -1;
	}
	queue<int> q;
	node[1].d = 0;
	q.push(1);
	while(!q.empty()) {
		int u = q.front(); q.pop();
		for (int i = 0; i < node[u].k; ++i) {
			int v = node[u].v[i];
			if (node[v].d == -1) {
				node[v].d = node[u].d + 1;
				q.push(v);
			}
		}
	}
	for (int i = 1; i <= n; ++i)
		cout << i << " " << node[i].d << endl;
	return 0;
}

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

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            int e = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());

            if (e - a > k) Console.WriteLine(":(");
            else Console.WriteLine("Yay!");
        }



        private static int[] Read(string input)
        {
            string[] inputs = input.Split(' ');
            int num = inputs.Length;
            int[] ints = new int[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = int.Parse(inputs[i]);
            }
            
            return ints;
        }


    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <cstring>
#include <fstream>
#include <string>
using namespace std;
int main()
{
    unsigned long long a= 100,b;
    int flags=0;
    cin>>b;
    int i;
    for(i=0;a<b;i++)
    {
        a=a+a*0.01;
    }
    cout<<i;
}


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

long long n, m;
map<int, int> mp;

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    ++mp[a];
  }
  cin >> m;
  bool ch = 1;
  for (int i = 0; i < m; ++i) {
    int a;
    cin >> a;
    if (--mp[a] < 0) ch = 0;
  }
  if (ch)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


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

int main()
{

	int n;
	string a, b;
	string c = "";
	cin >> n;
	cin >> a >> b;
	for(int i=0;i<n;i++){
		c += a[i];
		c+=b[i];
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    double a, b;
    cin >> a >> b;
    double ave = (a + b)/2;
  	int ave_s = (a + b)/2;
    if (ave_s < ave) cout << (ave_s + 1) << endl;
    else cout << ave_s << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

#define x first.first
#define y first.second
#define u second


signed main(){
	cout<<fixed<<setprecision(10);
	
	//U, R, D, L;
	
	int N;
	int ans = INF;
	vector<pair<pair<int,int>,char>> in;
	vector<map<int,vector<pair<int,int>>>> v(6);

	cin>>N;
	
	in.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>in[i].x>>in[i].y>>in[i].u;
		in[i].x *= 10;
		in[i].y *= 10;
		
		if(in[i].u == 'U') {
			v[4][in[i].x].push_back({in[i].y, 0});
			
			v[0][in[i].x+in[i].y].push_back({in[i].x-in[i].y, 1});
			v[2][in[i].x-in[i].y].push_back({in[i].x+in[i].y, 0});
		} else 
		if(in[i].u == 'R') {
			v[5][in[i].y].push_back({in[i].x, 0});
			
			v[0][in[i].x+in[i].y].push_back({in[i].x-in[i].y,0});
			v[3][in[i].x-in[i].y].push_back({in[i].x+in[i].y,0});
		} else 
		if(in[i].u == 'D') {
			v[4][in[i].x].push_back({in[i].y, 1});
			
			v[1][in[i].x+in[i].y].push_back({in[i].x-in[i].y,0});
			v[3][in[i].x-in[i].y].push_back({in[i].x+in[i].y,1});
		} else 
		if(in[i].u == 'L') {
			v[5][in[i].y].push_back({in[i].x, 1});
			
			v[1][in[i].x+in[i].y].push_back({in[i].x-in[i].y, 1});
			v[2][in[i].x-in[i].y].push_back({in[i].x+in[i].y, 1});
		}
	}
	
	for(int i = 0; i < v.size(); i++){
		for(pair<int,vector<pair<int,int>>> t : v[i]){
			sort(t.second.begin(), t.second.end());
			
			for(int j = 0, k = -1; j < t.second.size(); j++){
				if(t.second[j].second == 0) {
					k = t.second[j].first;
				} else {
					if(k != -1) ans = min(ans, (t.second[j].first - k)/2);
				}
			}
		}
	}

	if(ans == INF) cout<<"SAFE"<<endl;
	else {
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 72752
#include <bits/stdc++.h>
using namespace std;
#define MM 200100
#define MN 15
int N,M;
int a[55],b[55];
int c[55],d[55];
int ans[55];
int main(){
	cin >> N >> M;
	for(int i=0;i<N;i++){
		cin >> a[i] >> b[i];
	}
	for(int i=0;i<M;i++){
		cin >> c[i] >> d[i];
	}
	for(int i=0;i<N;i++){
		int val = 1145141919;
		for(int j=M-1;j>=0;j--){
			int ret = abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(ret<=val){
				val = ret;
				ans[i] = j;
			}
		}
	}
	for(int i=0;i<N;i++){
		cout << ans[i]+1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
d = {}
for i in range(N):
    c = input()
    d[c] = d.get(c, 0) + 1

M = int(input())
for i in range(M):
    c = input()
    d[c] = d.get(c, 0) - 1

print(max(max(d.items(), key=lambda x: x[1])[1], 0))

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

int main(){
  string o,e;
  cin >> o >> e;
  int l = e.size();
  for(int i = 0; i < l; i++){
    cout<<o.at(i)<<e.at(i);
  }
  if(l<o.size())cout<<o.at(l);
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;

int D;
VI c;
VVI s;
VI lastday;


VI solve_simple() {
	VI t(D, 1);

	return t;

}

int main() {
	cin >> D;

	c.assign(26, 0);
	for (int i = 0; i < c.size(); i++) {
		cin >> c[i];
	}
	s.assign(D, VI(26, 0));
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < s[i].size(); j++) {
			cin >> s[i][j];
		}
	}
	lastday.assign(26, 0);

	VI t = solve_simple();

	for (auto x: t) {
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 3268
#include<iostream>

using namespace std;

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

	int n;
	cin >> n;
	int a[n];
	for(int i=0; i<n; i++)
		cin >> a[i];
	int ans = 0;
	for(int i=1; i<n-1; i++){
		if(a[i] != max(a[i-1], max(a[i],a[i+1])) and a[i] != min(a[i-1], min(a[i],a[i+1])))
			ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3620
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
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)*}};}
#[allow(unused_macros)]
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)*}};}
#[allow(unused_macros)]
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")};}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{n:usize, p:[i64;n]};
    let mut p = p;
    let mut ans = 0i64;

    for i in 0..n-1 {
        if p[i] == i as i64 +1 {
            ans += 1;
            p.swap(i,i+1);
        }
    }
    if p[n-1] == n as i64 { ans += 1; }

    println!("{}", ans);

}

Measured memory_bytes: 4352
s = input()

l = [0]
for c in s:
    if c == "<":
        l.append(l[-1]+1)
    else:
        l.append(0)

r = [0]
for c in s[::-1]:
    if c == ">":
        r.append(r[-1]+1)
    else:
        r.append(0)

ans = 0
for a, b in zip(l, r[::-1]):
    ans += max(a, b)
print(ans)

Measured memory_bytes: 37380
n, m = map(int, input().split())

dwa = {}
dac = {}

for i in range(m):
    p, s = input().split()
    if s == "AC":
        if int(p) not in dac:
            dac[int(p)] = 1
        # else:
        #     dac[int(p)] += 1
    else:
        if (int(p) not in dac) and (int(p) not in dwa):
            dwa[int(p)] = 1
        elif int(p) not in dac:
            dwa[int(p)] += 1


# print(dac, dwa)
ans1 = sum(dac.values())
# ans2 = sum(dwa.values())
ans2 = 0
for i in dac.keys():
    if i in dwa:
        ans2 += dwa[i]

print(ans1, ans2)



Measured memory_bytes: 15068
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

ll ketasuu(ll X){
    ll t=0;
    while(X>0){
        X/=10;
        t++;
    }
    return t;
}

int main(){
    ll N,A,B,C,mi=MOD;cin>>N;
    vector<ll> yakusuu;
    REP(i,1,sqrt(N)+1){
        if(N%i==0){
            yakusuu.push_back(i);
        }
    }
    cout << ketasuu(N / (*yakusuu.rbegin())) << endl;
}

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

using namespace std;

#define ll long long
typedef complex<double> P;

int main() {
  int n; cin >> n;
  int p=1, fib=1;
  if(n == 1 || n == 0) cout << 1 << endl;
  else {
    for (int i = 1; i < n; i++) {
      int t = p;
      p = fib;
      fib += t;
    }
    cout << fib << endl;
  }
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(a,b,c) for(int a=b;a<c;++a)
#define repeq(a,b,c) for(int a=b;a<=c;++a)
#define debug(x) cerr<<(#x)<<": "<<x<<endl
typedef long long ll;
const int SZ=1e5;
int a[SZ];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	rep(i,0,n)
		cin >> a[i];
	int c = 0;
	rep(i,0,n-1)
		if(a[i]==i+1)
		{
			swap(a[i],a[i+1]);
			++c;
		}
	if(a[n-1]==n)
	{
		swap(a[n-1],a[n-2]);
		++c;
	}
	cout << c << endl;
}


Measured memory_bytes: 640
import sys
readline = sys.stdin.readline
def MAIN():
    n, m = map(int, input().split())
    li = [i for i in range(n)]
    def f(a):
        if li[a] == a:
            return a
        li[a] = f(li[a])
        return li[a]
    def f2(a, b):
        if li[a] == a:
            li[a] = b
            return
        f2(li[a], b)
        li[a] = b
    def solve(a, b):
        if f(a) == f(b):
            return "yes"
        return "no"
    for _ in range(m):
        x, y = map(int, readline().split())
        if f(x) > f(y):
            f2(x, li[y])
        else:
            f2(y, li[x])
    for _ in range(int(input())):
        x, y = map(int, readline().split())
        print(solve(x, y))
MAIN()



Measured memory_bytes: 10032
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include "bits/stdc++.h"
static const int MOD = 998244353;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

template <class T>
T pow_ (T x, T n, T M){
    uint64_t u = 1, xx = x;
    while (n > 0){
        if (n&1) u = u * xx % M;
        xx = xx * xx % M;
        n >>= 1;
    }
    return static_cast<T>(u);
};



int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    int sum = accumulate(v.begin(), v.end() , 0);
    auto dp = make_v(n+1, sum+1, 0LL);
    dp[0][0] = 1;
    auto dp2 = dp;
    int x = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= x; ++j) {
            (dp[i+1][j+v[i]] += dp[i][j]) %= MOD;
            (dp[i+1][j] += dp[i][j]*2) %= MOD;
            (dp2[i+1][j+v[i]] += dp2[i][j]) %= MOD;
            (dp2[i+1][j] += dp2[i][j]) %= MOD;
        }
        x += v[i];
      	for(ll j=0;j<=x;j++) dp[i][j]=0;
    }
    ll ans = pow_(3, n-1, MOD);
    for (int i = (sum+1)/2; i <= sum; ++i) {
        (ans += MOD - dp[n][i]) %= MOD;
    }
    if(sum%2 == 0){
        (ans += dp2[n][sum/2]) %= MOD;
    }
    cout << (ans*3)%MOD << "\n";
    return 0;
}


Measured memory_bytes: 423104
import java.util.HashSet;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String s = scan.next();

		HashSet<String> at = new HashSet<>();
		at.add("A");
		at.add("C");
		at.add("G");
		at.add("T");

		int i,j,temp;
		int len = s.length();
		int max = Integer.MIN_VALUE;

		for(i = 0; i < len; i++) {
			temp = 0;
			for(j = i; j < len; j++) {
				if(!at.contains(s.substring(j, j + 1))) {
					break;
				}
				temp++;
			}
			max = Math.max(max, temp);
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 21844
#include<iostream>

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

ll inv2;

ll modpow(ll a, ll b) {
	ll base = 1, kakeru = a;
	while (b > 0) {
		if (b & 1)base *= kakeru, base %= MOD;
		kakeru *= kakeru, kakeru %= MOD;
		b >>= 1;
	}
	return base;
}

int main() {

	inv2 = modpow(2, MOD - 2);

	ll N, K;
	ll A[2000];
	ll memo[2002] = {};
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		memo[A[i]]++;
	}
	for (int i = 1; i <= N + 1; i++) {
		memo[i] += memo[i - 1];
	}
	ll ans = 0;
	for (int i = 0; i < N; i++) {
		ll cnt = 0;
		for (int j = 0; j < i; j++) {
			if (A[i] < A[j])cnt++;
		}

		ll cnt2 = 0;
		for (int j = 0; j < N; j++) {
			if (A[i] < A[j])cnt2++;
		}

		cnt = ((((cnt * K) % MOD) + ((((K * (K - 1) % MOD) * inv2) % MOD) * (cnt2) % MOD)) % MOD);

		ans += cnt;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
o=input()
e=input()

p=''
for i in range(0,len(e)):
  p=p+o[i]+e[i]
if len(o)>len(e):
  p=p+o[len(o)-1]
print(p)
  
  


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
typedef vector<P> vec;

double eps=1e-8;
double PI=acos(-1);

bool eq(double a,double b){return (b-a<eps&&a-b<eps);}
double dot(P a,P b){return real(b*conj(a));}
double cross(P a,P b){return imag(b*conj(a));}
P project(P a,P b,P c){b-=a;c-=a;return a+b*real(c/b);}
P reflect(P a,P b,P c){b-=a;c-=a;return a+conj(c/b)*b;}
int ccw(P a,P b,P c){
  b-=a,c-=a,a=c*conj(b);
  if(a.imag()>eps)return 1;//ccw
  if(a.imag()<-eps)return -1;//cw
  if(a.real()<-eps)return 2;//ob
  if(abs(b)+eps<abs(c))return -2;//of
  return 0;//os
}

//segment ab , point c
double dist(P a,P b,P c){
  if(dot(b-a,c-a)<0)return abs(c-a);
  if(dot(a-b,c-b)<0)return abs(c-b);
  return abs(cross(b-a,c-a))/abs(b-a);
}

bool isintersect(P a,P b,P c,P d){
  return ((ccw(a,b,c)*ccw(a,b,d)<=0)&&(ccw(c,d,a)*ccw(c,d,b)<=0));
}

//segment ab , segment cd
P intersect(P a,P b,P c,P d){
  a-=d;b-=d;c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}

double dist(P a,P b,P c,P d){
  if(isintersect(a,b,c,d))return 0;
  double ab=min(dist(a,b,c),dist(a,b,d));
  double cd=min(dist(c,d,a),dist(c,d,b));
  return min(ab,cd);
}

double calcArea(vec &t){
  double res=0;
  int n=t.size();
  for(int i=0;i<n;i++)res+=cross(t[i],t[(i+1==n?0:i+1)]);
  return abs(res/2.0);
}

double Arg(P a,P b,P c){
  b-=a,c-=a;
  return arg(c*conj(b));
}

int inPolygon(vec &t,P p){
  double sum=0;
  for(int i=0;i<(int)t.size();i++){
    P a=t[i],b=(i==0?t.back():t[i-1]);
    if( ccw(a,b,p) == 0 )return 1;// on
    sum+= Arg(p,a,b);
  }
  if( abs(sum) < eps )return 0;//out
  else  return 2;//in
}

int main(){
  int n;
  cin>>n;
  vec t;
  double x,y;
  for(int i=0;i<n;i++){
    cin>>x>>y;
    t.push_back(P(x,y));
  }
  int q;
  cin>>q;
  while(q--){
    cin>>x>>y;
    cout<<inPolygon(t,P(x,y))<<endl;
  }

  return 0;
}

Measured memory_bytes: 1336
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

int main()
{
	ll x;
	cin >> x;
	for (ll i = 0;;i++)
	{
		if (i *(i + 1) / 2 < x && x <= (i + 1) *(i + 2) / 2){		
			cout << i + 1 << endl;
			return 0;
		}

	}

	return 0;
}




Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int H;
vi A;
inline void maxHeapify(int i) {
	int l = 2 * i;
	int r = 2 * i + 1;
	int largest = (l <= H && A[l] > A[i] ? l : i);
	if(r <= H && A[r] > A[largest]) largest = r;
	if(largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}
int main() {
	cin >> H;
	A.resize(H + 1); rep(i, 1, H + 1) cin >> A[i];
	rrep(i, H / 2, 0) maxHeapify(i);
	rep(i, 1, H + 1) cout << " " << A[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 4556
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

map<string, int> mp;
vector<string> v;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    cin >> N;
    int ans = 0;
    for(int i = 0; i < N; i++){
        string s;
        cin >> s;
        if(mp.count(s) == 0){
            mp[s] = 1;
        }else{
            mp[s]++;
        }
        ans = max(ans, mp[s]);
    }
    for(auto iter = mp.begin(); iter != mp.end(); iter++){
        if(iter->second == ans) v.push_back(iter->first);
    }
    sort(v.begin(), v.end());
    for(int i = 0; i < v.size(); i++){
        cout << v[i] << endl;
    }
}

Measured memory_bytes: 25584
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

const ll N = 1e5 + 1;
vector<ll> adj[N];
bool visited[N];
ll dp[N];

void dfs(int s){
	visited[s] = 1;
	dp[s] = 0;
	for(auto u : adj[s]){
		if(!visited[u]){
			dfs(u);
		}
		dp[s] = max(dp[s], dp[u] + 1);
	}
}

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

	ll n, m;
	cin>>n>>m;
	ll x, y;
	for(int i=0;i<m;i++){
		cin>>x>>y;
		adj[x].pb(y);
	}
	ll i;
	for(i=1;i<=n;i++){
		if(!visited[i]){
			dfs(i);
		}
	}
	cout<<*max_element(dp+1, dp+n+1);
	return 0;
}


Measured memory_bytes: 8704
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <numeric>


int main() {
	std::string s;

	std::cin >> s;

	int count1, count2;

	count1 = count2 = 0;
	for (size_t i = 0; i < s.length(); i++)
	{
		if (i % 2 == 0) {
			count1 += s[i] - '0';
			count2 += '1' - (int)s[i];
		}
		else {
			count1 += '1' - (int)s[i];
			count2 += (int)s[i] - '0';
		}
	}

	std::cout << std::min(count1, count2) << std::endl;
	return 0;
}

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

int main(){
	int Wp[10], Kp[10];
	int W, K;
	
	for(int i = 0; i < 10; i++){
		cin >> Wp[i];
	}
	for(int i = 0; i < 10; i++){
		cin >> Kp[i];
	}
	sort(Wp, Wp+10);
	sort(Kp, Kp+10);
	
	W = Wp[9] + Wp[8] + Wp[7];
	K = Kp[9] + Kp[8] + Kp[7];
	
	cout << W << ' ' << K << endl;
	
	return 0;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> pq;
    rep(i, 0, N) {
        int a; cin >> a;
        pq.push(a);
    }
    while(M--) {
        int t = pq.top(); pq.pop();
        pq.push(t / 2);
    }
    long long ans = 0;
    while(!pq.empty()) {
        ans += pq.top(); pq.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n;
  	string s;
  
  string s1;
  string s2;
  
  cin>>n;
  cin>>s;
  
  if(n%2==0)
  {
    for(int i=0;i<n/2;i++)
    {
      s1.push_back(s[i]);
    }

    for(int i=n/2;i<n;i++)
    {
      s2.push_back(s[i]);
    }
    
      if(s1==s2)
    {
      cout<<"Yes"<<endl;
    }
    else
    {
      cout<<"No"<<endl;
    }
    
    
  }
  else
  {
    cout<<"No"<<endl;
  }
  
  return 0;
}


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

int main(){
    int d, g; cin >> d >> g;
    vector<int> p(d);
    vector<int> c(d);

    for(int i = 0; i < d; i++) cin >> p[i] >> c[i];

    //dp[i][j] := i番目の問題まで見る。解いた問題数をj。得られる得点
    int dp[12][2000] = {};

    for(int i = 0; i < d; i++){
        for(int j = 0; j < 1500; j++){

            //k問解く
            for(int k = 0; k < p[i]; k++){
                //if(i + 1 == 2 && j + k == 0) cout << dp[2][0] << endl; 
                dp[i + 1][j + k] = max(dp[i + 1][j + k], dp[i][j] + k * (i + 1) * 100);
                //if(i + 1 == 2 && j + k == 0) cout << dp[2][0] << endl;                
            }

            //max解く
            dp[i + 1][j + p[i]] = max(dp[i + 1][j + p[i]], dp[i][j] + p[i] * (i + 1) * 100 + c[i]);
            //cout << i << " " << j << " " << dp[2][0] << endl;
        }
    }

    /*for(int i = 0; i < d + 1; i++){
        for(int j = 0; j < 20; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/


    for(int j = 0; j < 1210; j++){
        if(dp[d][j] >= g){
            cout << j << endl;
            break;
        }
    }

    return 0;
    
}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		 int A =sc.nextInt();
		 int B =sc.nextInt();
		 //i*0.08とi*0.1が等しくなるまで繰り返す
		 for(int i=1; i<=100000; i++) {
		 if((int)(i*0.08)==A && (int)(i*0.1)==B) {
			 System.out.println(i);
			 return;
		 	}
		 }	//なかった場合は-1を表示
			 System.out.println("-1");
    }
}

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

int main(){
    int i,j,k,temp,n,m;
    cin >> n >> m ;
    int a[n][m],b[m],c[m];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin >> temp;
            a[i][j] = temp;
        }
    }
    for(k=0;k<m;k++){
        cin >> temp;
        b[k] = temp;
    }
    temp = 0;
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            temp += a[i][j]*b[j];
        }
        c[i] = temp;
        cout << c[i] << endl;
        temp = 0;
    }
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1e9+10;
const ll inf = 1ll<<60;
const ll mod = 1e9+7 ;


void GG(){cout<<"0\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b, ll mo = mod){
    if (b==1) return b;
    return (mo-mo/b) * inv(mo%b,mo) % mo;
}

const int maxn = 1e6+5;


signed main(){
    IOS();
    ll a,b,v,w,t; cin>>a>>v>>b>>w>>t;
    if (v>w && (abs(a-b) +v-w-1)/ (v-w) <= t) {
        cout<<"YES"<<endl;
    }else cout<<"NO"<<endl;


}


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


void solve(long long N, long long K){
  if (K > (N - 2) * (N - 1) / 2) {
      cout << -1 << endl;
      return;
  }

  vector<pair<int, int>> edges;
  for (int i = 2; i <= N; i++) {
      edges.emplace_back(1, i);
  }
  int paths = (N-1)*(N-2)/2;
  for (int i = 2; i <= N; i++) {
    for (int j = i + 1; paths > K and j <= N; j++) {
	edges.emplace_back(i, j);
	paths--;
    }
  }
  cout << edges.size() << endl;
  for (auto e : edges) {
      cout << e.first << " " << e.second << endl;
  }
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD=1e9+7;
const int N=200000+10;
vector<int> g[N]; int n;

LL fac[N],invfac[N];

LL mpow(LL a,LL x){
	if(x==0)return 1;
	LL t=mpow(a,x>>1);
	if(x%2==0)return t*t%MOD;
	return t*t%MOD*a%MOD;
}

LL down[N],sz[N],up[N],par[N];
LL dfs(int u,int p){
	int son=0; sz[u]=1; par[u]=p;
	for(auto v:g[u]){
		if(v==p)continue;
		dfs(v,u);++son;sz[u]+=sz[v];
	}
	if(son==0) return down[u]=1;
	down[u]=fac[sz[u]-1];
	for(auto v:g[u]){
		if(v==p)continue;
		down[u]=down[u]*invfac[sz[v]]%MOD;
		down[u]=down[u]*down[v]%MOD;
	}
	return down[u];
}

LL dfs2(int u,int p){
	//LL pre[N],suf[N];
	vector<LL> pre, suf;
	pre.resize(g[u].size() + 3);
	suf.resize(g[u].size() + 3);
	pre[0]=1; suf[g[u].size()+1]=1;
	for(int i=0;i<g[u].size();i++){
		if(g[u][i]!=p)
			pre[i+1]=pre[i] * (down[g[u][i]]%MOD*invfac[sz[g[u][i]]]%MOD) % MOD;
		else
			pre[i+1]=pre[i];

		//if (u == 1) printf("! %lld\n", pre[i+1]);
	}
	for(int i=(int)g[u].size()-1;i>=0;i--){
		if(g[u][i]!=p)
			suf[i+1]=suf[i+2] * (down[g[u][i]]%MOD*invfac[sz[g[u][i]]]%MOD) % MOD;
		else
			suf[i+1]=suf[i+2];
	}
	for(int i=0;i<g[u].size();i++){
		int v=g[u][i];
		if(v==p)continue;
/*
if (u==1 && v==6) {
	printf("# %lld, %lld\n", up[u]%MOD*invfac[n-sz[u]]%MOD, pre[i]%MOD*suf[i+2]%MOD);
	printf("# %lld\n", down[2]);
	for (int x = 0; x <= g[u].size(); x ++) {
		printf("%d %d\n", pre[x], suf[x]);
	}
}
*/
		up[v]=fac[n-sz[v]-1];
		up[v]=up[v]*up[u]%MOD*invfac[n-sz[u]]%MOD;
		up[v]=up[v]*pre[i]%MOD*suf[i+2]%MOD;
		dfs2(v,u);
	}
}
LL ans[N];
void dfs3(int u,int p){
	ans[u]=fac[n-1];
	for(auto v: g[u]) {
		if(v==p){
			ans[u]=ans[u]*up[u]%MOD*invfac[n-sz[u]]%MOD;
			continue;
		} 
		ans[u]=ans[u]*down[v]%MOD*invfac[sz[v]]%MOD;
		dfs3(v,u);
	}
}
int main() {
	fac[0]=1; for(int i=1;i<N;i++)fac[i]=fac[i-1]*i%MOD;
	for(int i=0;i<N;i++){
		invfac[i]=mpow(fac[i],MOD-2);
	}
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int u,v; 
		scanf("%d%d",&u,&v);
		//u=i+1,v=rand()%i+1;
		//printf("%d %d\n", u,v);
		g[u].push_back(v); g[v].push_back(u);
	}
	dfs(1,1);
	up[1]=1; dfs2(1,1);
	//printf("$ %lld\n", up[6]);
	dfs3(1,1);
	for(int i=1;i<=n;i++){
		printf("%lld\n",ans[i]);
	}
}	




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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] S = sc.nextLine().split("");
		int[] ans = new int[S.length];

		int cnt = 0;
		for (int i = 0; i < S.length; i++) {
			if ("R".equals(S[i])) {
				cnt++;
			} else {
				ans[i] += cnt / 2;
				ans[i - 1] += (cnt + 1) / 2;
				cnt = 0;
			}
		}
		for (int i = S.length - 1; i >= 0; i--) {
			if ("L".equals(S[i])) {
				cnt++;
			} else {
				ans[i] += cnt / 2;
				ans[i + 1] += (cnt + 1) / 2;
				cnt = 0;
			}
		}

		Arrays.stream(ans).forEach(s -> System.out.print(s + " "));
	}
}

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

int main() {  
  string S;
  cin >> S;
  int s=S.size();
  int a=0,b=0;
  for(int i=0;i<s;i++){
    if(S[i]=='0'){
      if(i%2==0){a++;}
      else{b++;}
    }
    else{
      if(i%2==0){b++;}
      else{a++;}
    }
  }
  cout << min(a,b) << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
string s;
int sR[N], sG[N], sB[N];

int32_t main(){_

   cin >> n >> s;

   for (int i = n-1; i >= 0; --i)
   {
      sR[i] = sR[i+1];
      sG[i] = sG[i+1];
      sB[i] = sB[i+1];

      if (s[i] == 'R'){
         sR[i]++;
      }
      else if (s[i] == 'G'){
         sG[i]++;         
      }
      else{
         sB[i]++;
      }
   }

   int ans = 0;
   for (int i = 0; i < n; ++i)
   {
      for (int j = i+1; j < n; ++j)
      {
         if(s[i] == s[j])
            continue;
         if (s[i] == 'R' and s[j] == 'G'){
            ans += sB[j];
            int nxt = j + j-i;
            if (nxt < n and s[nxt] == 'B'){
               ans--;
            }
         }
         else if (s[i] == 'G' and s[j] == 'R'){
            ans += sB[j];
            int nxt = j + j-i;
            if (nxt < n and s[nxt] == 'B'){
               ans--;
            }
         }
         else if (s[i] == 'G' and s[j] == 'B'){
            ans += sR[j];            
            int nxt = j + j-i;
            if (nxt < n and s[nxt] == 'R'){
               ans--;
            }
         }
         else if (s[i] == 'B' and s[j] == 'G'){
            ans += sR[j];            
            int nxt = j + j-i;
            if (nxt < n and s[nxt] == 'R'){
               ans--;
            }
         }
         else if (s[i] == 'R' and s[j] == 'B'){
            ans += sG[j];                        
            int nxt = j + j-i;
            if (nxt < n and s[nxt] == 'G'){
               ans--;
            }
         }
         else if (s[i] == 'B' and s[j] == 'R'){
            ans += sG[j];                        
            int nxt = j + j-i;
            if (nxt < n and s[nxt] == 'G'){
               ans--;
            }
         }
      }
   }

   cout<<ans;

   return 0;
}

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

int main() {
int N;//カードの枚数
  cin >> N;
int Alice, Bob;
vector<int> cards(N);
  int i;
  for (i = 0; i < N; i++)
    cin >> cards.at(i);//カードの読み込み完了
  Alice = 0;
  Bob = 0;
  for (i = 0; i < N / 2 + 1; i++){
    int j;
    int k = 0;
    int l = 0;
  for (j = 0; j < N; j++){//Aliceの処理開始
    if (l < cards.at(j)){
      k = l;
      l = cards.at(j);
      cards.at(j) = k;//仮に持っているカードとより大きなカードを交換する
    }
  }
  Alice += l;//最終的に決めたカードをAliceの合計点に加える
  l = 0;//lのリセット
  for (j = 0; j < N; j++){//Bobの処理開始
      if (l < cards.at(j)){
        k = l;
        l = cards.at(j);
        cards.at(j) = k;//仮に持っているカードとより大きなカードを交換する
      }
  }
  Bob += l;//最終的に決めたカードをBobの合計点に加える
  }
	cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
a, b = map(int, input().split())

if (a <= 0 and b >= 0):
    print('Zero')
    exit()
elif(a < 0 and b < 0 and a < b):
    c = b - a + 1
    if (c % 2 == 0):
        print('Positive')
    else:
        print('Negative')
else:
    print('Positive')


Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;

ll n,k,ans=1,cnt=0;
vector<ll> E[100010];
ll s[111111]={};
stack<ll> que;
bool sb[111111]={};


int main(){
    cin>>n>>k;
    rep(i,n-1){
        ll a,b;
        cin>>a>>b;
        E[a].push_back(b);
        E[b].push_back(a);
        s[a]++;s[b]++;
    }
    for(auto i:E[1]){
        que.push(i);
        cnt++;
    }
    ans*=k;
    while(cnt>0){
        ans=ans*(k-cnt)%MOD;
        cnt--;
    }
    sb[1]=1;
    while(!que.empty()){
        ll now=que.top();
        que.pop();
        sb[now]=1;
        s[now]--;
        while(s[now]>0){
            ans=ans*(k-1-s[now])%MOD;
            s[now]--;
        }
        for(auto i:E[now]){
            if(!sb[i]){
            que.push(i);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8180
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

typedef struct {
    int from;
    int to;
    ll cost;
} edge;


//負の閉路がない時にはtrueを返し、dにsからの最短距離を格納する
//負の経路が存在する時にはfalseを返す
bool bellman_ford(vector<edge> G, int n, int s, ll *d) {
    ll INF = 100000000000000;
    for (int i = 0; i < n; i++)
        d[i] = INF;
    d[s] = 0;

    for (int i = 0; i < n; i++) {
        bool check = false;
        for (int j = 0; j < G.size(); j++) {
            edge e = G[j];
            int u = e.from, v = e.to;
            ll c = e.cost;

            if (d[u] != INF && d[v] > d[u] + c) {
                d[v] = d[u] + c;
                check = true;
            }
        }
        if (i == n - 1 && check)
            return false;
    }
    return true;
}

int main() {
    int n, m, r;   cin >> n >> m >> r;
    vector<edge> G;

    for (int i = 0; i < m; i++) {
        int s, t;   ll c;
        cin >> s >> t >> c;
        edge e = {s, t, c};
        G.push_back(e);
    }

    ll INF = 100000000000000;

    ll *d = new ll[n];
    if (bellman_ford(G, n, r, d)) {
        for (int i = 0; i < n; i++) {
            if (d[i] == INF)
                cout << "INF" << endl;
            else 
                cout << d[i] << endl;
        }
    }
    else 
        cout << "NEGATIVE CYCLE" << endl;

    return 0;
}


Measured memory_bytes: 3184
# coding: utf-8

# 入力
n = int(input())
k = int(input())
li = list(map(int, input().split()))

# メイン処理
count = 0
for p in li:
    if p < k - p:
        count += p * 2
    else:
        count += (k-p) * 2

# 出力
print(count)

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

void solve() {
    int n, m, q; cin >> n >> m >> q; if (n == 0) exit(0);
    vector<vector<bool>> vb(m, vector<bool>(n, true));
    string s(n, '0');
    for (int kkt = 0; kkt < q; kkt++) {
        string ts, b; cin >> ts >> b;
        for (int i = 0; i < ts.size(); i++) if (ts[i] == '1') {
            if (s[i] == '0') s[i] = '1';
            else s[i] = '0';
        }
        for (int i = 0; i < s.size(); i++) {
            for (int j = 0; j < b.size(); j++) {
                if (s[i] == '0' and b[j] == '1') {
                    vb[j][i] = false;
                }
                if (s[i] == '1' and b[j] == '0') {
                    vb[j][i] = false;
                }
            }
        }
    }
    string res;
    for (int i = 0; i < m; i++) {
        vector<int> v;
        for (int j = 0; j < n; j++) if (vb[i][j]) v.emplace_back(j);
        if (v.size() != 1) res += '?';
        else {
            if (v[0] <= 9) res += (char)('0' + v[0]);
            else {
                v[0] -= 10;
                res += (char)('A' + v[0]);
            }
        }
    }
    cout << res << "\n";
}

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

    int kkt = 89;
	while (kkt) {
		solve();
	}
    return 0;
}


Measured memory_bytes: 3276