akhauriyash/Code-Regression huggingface dataset:
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    int a, b;
    cin >> a >> b;
    if (a<10 && b<10) cout << a*b << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int W, H;
  cin >> W >> H;
  int s[52][52] = {0}; // 0は白、1は黒にしたい、2は黒に塗り済み
  rep (pi, W) {
    int i = pi + 1;
    rep (pj, H) {
      int j = pj + 1;
      char sij;
      cin >> sij;
      // DEBUG(sij);
      if (sij == '#') {
        s[i][j] = 1;
      }
    }
  }

  int fixCount = 1;
  while (fixCount > 0) {
    fixCount = 0;

    rep (pi, W) {
      int i = pi + 1;
      rep (pj, H) { 
        int j = pj + 1;
        if (s[i][j] == 1) { // 該当箇所を黒にしたい場合 全部を2にしようとする

          if (s[i-1][j] == 1) { // 上 黒希望
            s[i-1][j] = 2;
            s[i][j] = 2;
            fixCount += 2;
          } else if (s[i-1][j] == 2) { // 上 黒済み
            s[i][j] = 2;
            fixCount += 1;
          } else if (s[i][j-1] == 1) { // 左 黒希望
            s[i][j-1] = 2;
            s[i][j] = 2;
            fixCount += 2;
          } else if (s[i][j-1] == 2) { // 左 黒済み
            s[i][j] = 2;
            fixCount += 1;
          } else if (s[i][j+1] == 1) { // 右 黒希望
            s[i][j+1] = 2;
            s[i][j] = 2;
            fixCount += 2;
          } else if (s[i][j+1] == 2) { // 右 黒済み
            s[i][j] = 2;
            fixCount += 1;
          } else if (s[i+1][j] == 1) { // 下 黒希望
            s[i+1][j] = 2;
            s[i][j] = 2;
            fixCount += 2;
          } else if (s[i+1][j] == 2) { // 下 黒済み
            s[i][j] = 2;
            fixCount += 1;
          }
        }

      }
    }


  }

  int blackNeedCount = 0;
  rep (pi, W) {
    int i = pi + 1;
    rep (pj, H) { 
      int j = pj + 1;
      if (s[i][j] == 1) { // 黒にしたいところがあればカウント
         blackNeedCount++;
      }
    }
  }

  if(blackNeedCount > 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


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

typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	// freopen("input.in", "r", stdin);
	// freopen("input.out", "w", stdout);
    int n; string s; cin >> n >> s;
    int nr{};
    trav(i, s) {
        if (i == 'R') nr++;
    }
    int ans = 0;
    F0R(i, nr) {
        if (s[i] == 'W') ans++;
    }
    cout << ans << nl;
}

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

int main(){

    int n;
    cin >> n;
    vector<pair<int, int>> p;
    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        p.emplace_back(x, y);
    }
    sort(p.begin(), p.end());

    for(const auto x : p){
        cout << x.first << " " << x.second << endl;
    }

    return 0;
}


Measured memory_bytes: 3884
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
#define rep(i, n)for(int i = 0; i < (int)(n); i++)

int main(){
    float n, m;
    cin >> n >> m;
    vector<float> A;
    float a = 0;
    rep(i, n) {
        cin >> a;
        A.push_back(a);
    }

    sort(A.begin(), A.end(), greater<float>());
    if(A[m-1] < accumulate(A.begin(), A.end(), 0) / (4 * m))
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
    
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
typedef vector<ll> vl;
typedef pair<vl,vl> t;
bool p[200005];

int main(){
	for(int i=2;i<200005;i++){
		if(p[i]) continue;
		for(int j=2;j*i<200005;j++) p[i*j] = 1;
	}
	int n; cin >> n;
	for(int i=n;i<200005;i++) if(!p[i]){cout<<i<<endl; return 0;}
}

Measured memory_bytes: 384
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
use proconio::fastout;
use proconio::input;
//use proconio::marker::Usize1;
//use proconio::marker::Chars;
//use std::collections::HashSet;
// use std::cmp::*;
//use std::collections::VecDeque;

#[fastout]
fn main() {
    input! {
       k: u64
    }
    // 同じ数
    let ans1 = k * (k + 1) / 2;
    // 2つが同じ数。
    // 各ペアの6倍。
    let mut ans2 = 0;
    for i in 1..k {
        for j in i + 1..k + 1 {
            ans2 += gcd(j, i);
        }
    }
    ans2 *= 6;
    let mut ans3 = 0;
    for i in 1..k - 1 {
        for j in i + 1..k {
            for l in j + 1..k + 1 {
                ans3 += gcd(l, gcd(j, i));
            }
        }
    }
    ans3 *= 6;

    println!("{}", ans1 + ans2 + ans3);
}

fn gcd(a: u64, b: u64) -> u64 {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}

//fn gcd3(a: u64, b: u64, c: u64) -> u64 {
//    gcd(a, gcd(b, c))
//}


Measured memory_bytes: 2168
// clang-format off
#include <bits/stdc++.h>

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

#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define pii pair<int, int>
#define vi vector<int>

using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T>& p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T>& vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;
constexpr ll MOD = 1000000007;

constexpr int MAX = 100000;

struct Graph
{
    Graph()
    {
        rep(i, MAX){
            edge[i].clear();
        }
    }
    void insert(int a, int b)
    {
        edge[a].pb(b);
        edge[b].pb(a);
    }
    vector<int> edge[MAX];
};

constexpr int DMAX = 11;
int operation[MAX][DMAX];
int color[MAX];

int main()
{
    int N, M;
    cin >> N >> M;
    Graph g;
    rep(i, M){
        int a, b;
        cin >> a >> b;
        g.insert(a-1, b-1);
    }
    constexpr int INFI = -1;
    rep(i, MAX){
        rep(j, DMAX){
            operation[i][j] = INFI;
        }
    }

    int Q;
    cin >> Q;
    rep(i, Q){
        int v, d, c;
        cin >> v >> d >> c;
        operation[v-1][d] = i;
        color[i] = c;
    }

    for(int d = DMAX-1; d >= 1; d--){
        rep(i, N){
            //            if(operation[i][d] != INFI){
                chmax(operation[i][d-1], operation[i][d]);
                for(const auto e : g.edge[i]){
                    //                    assert(e < N);
                    chmax(operation[e][d-1], operation[i][d]);
                }
                //            }
        }
    }
    rep(i, N){
        if(operation[i][0] != INFI){
            //            assert(operation[i][0] < Q);
            cout << color[operation[i][0]] << endl;
        } else {
            cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 11128
#include <cmath>
#include <stdio.h>
using namespace std;

int main(){
    int n, yy;
    scanf("%d", &n);  scanf("%d", &yy);
    //res[3] = {-1, -1, -1};
    
    for(int x = 0; x <= n; x++){
        for(int y = 0; y <= n; y++){
            int z =( yy - (10000*x + 5000*y))/1000;
            if(x+y+z == n && 0 <= z && ( yy - (10000*x + 5000*y))%1000 == 0){
                //res[0] = x; res[1] = y; res[2] = z;
                printf("%d %d %d", x, y, z);
                return 0;                
            }
        }
    }
    printf("%d %d %d", -1, -1, -1);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF 1e9+7
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int lo;
string a,b,c;
lo x,y;

int main(){
    cin >> a;
    for(lo i = 0;i < a.size();i++) cout << "x";
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[] args){

        Scanner scan = new Scanner(System.in);
        String S = scan.next();

        String[] s = S.split("/",0);

        int year = Integer.parseInt(s[0]);
        int month = Integer.parseInt(s[1]);
        int day = Integer.parseInt(s[2]);

        if(year<2019){
            System.out.println("Heisei");
        }else if(year==2019){
            if(month>=5){
                System.out.println("TBD");
            }else{
                System.out.println("Heisei");
            }
        }else{
            System.out.println("TBD");
        }

    }
}

Measured memory_bytes: 23764
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

    long long mod = 1000000007;
    vector<vector<long long>> dp(s + 1, vector<long long>(s + 2, 0));
    dp[0][0] = 1;
    for (int i = 0; i < s; i++) {
        for (int j = 0; j < s; j++) {
            dp[i + 1][min(j + 3, s + 1)] = (dp[i + 1][min(j + 3, s + 1)] + dp[i][j]) % mod;
            dp[i + 1][s + 1] = (dp[i + 1][s + 1] - dp[i][j] + mod) % mod;
        }

        for (int j = 0; j < s; j++) {
            dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i + 1][j]) % mod;
        }
    }

    long long res = 0;
    for (int i = 0; i < s; i++) {
        res = (res + dp[i][s]) % mod;
    }

    cout << res << endl;
}


Measured memory_bytes: 34624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,k;
    string s;
    cin >> n >> s >> k;
    char cr=s[k-1];
    for(ll i=0;i<n;i++){
        if(s[i]==cr) continue;
        s[i]='*';
    }
    cout << s << endl;
}

Measured memory_bytes: 3628
import math

n = int(input())
a = pow(10, n, 10**9+7)
b = pow(9, n, 10**9+7)
c = pow(9, n, 10**9+7)
d = pow(8, n, 10**9+7)
print((a-b-c+d) % (10**9+7))

Measured memory_bytes: 61896
S = list(input())
length = []
t = 0
for i in range(len(S)):
  if S[i] == "A" or S[i]=="C" or S[i]=="G" or S[i]=="T":
    t += 1
  else:
    length.append(t)
    t = 0
length.append(t)
print(max(length))

Measured memory_bytes: 3060
N,T = map(int,input().split())
c = []
for i in range(N):
  ci,ti = map(int,input().split())
  c.append([ci,ti])

c.sort(key=lambda x:x[0])
for i in range(N):
  if c[i][1] <= T:
    print( c[i][0])
    exit()
print('TLE')

Measured memory_bytes: 3060
function main (input) {
    const N = input;
    var ans = 1;
    var cnt = 0;
    var maxCnt = 0;

    for (var i = 1;i <= N;i++){
        cnt = 0;
        var tmp = i;
        while (true) {
            if (tmp%2 === 0) {
                cnt = cnt + 1;
                tmp = tmp/2;
            } else {
                break;
            }
        }
        if (maxCnt < cnt) {
            maxCnt = cnt;
            ans = i;
        }
    }
    console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
    ll  n ;
    cin >> n  ;
    vector<ll> A(n) ;
    vector<ll> B(n) ;
    vector<ll> C(n) ;
    rep(i,n) cin >> A.at(i) ;
    rep(i,n) cin >> B.at(i) ;
    rep(i,n) cin >> C.at(i) ;
    sort(A.begin(),A.end()) ;
    sort(B.begin(),B.end()) ;
    sort(C.begin(),C.end()) ;
    ll ans = 0 ;
    rep(i,n){
      auto iter1 = lower_bound(A.begin(),A.end(),B[i] );
      auto iter2 = upper_bound(C.begin(),C.end(),B[i] );
      ll a = iter1 - A.begin() ;
      ll b = iter2 - C.begin() ;
      //cout << a << ' ' << n - b << endl; 
      ans += a *  ( n - b ) ;
    }
    cout << ans << endl ;
}


Measured memory_bytes: 5616
def is_prime(N):
    i = 2
    table = []
    while i*i <= N:
        while N%i == 0:
            N //= i
            table.append(i)
        i += 1
    if N > 1:
        table.append(N)
    return table

from itertools import groupby
N = int(input())
P = is_prime(N)
ans = 0
for v, g in groupby(P):
    n = len(list(g))
    for i in range(1, 10**5):
        n -= i
        if n >= 0:
            ans += 1
        else:
            break
print(ans)

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

if a % 2 == 0 and b % 2 == 1:
  print("IMPOSSIBLE")
elif a % 2 == 1 and b % 2 == 0:
  print("IMPOSSIBLE")

else:
  if a > b:
    k = b + (a-b)/2
    print(int(k))
  else:
    k = a + (b-a)/2
    print(int(k))

Measured memory_bytes: 3060
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;


//#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        v: [String;n],
    }

    let mut s = BTreeSet::new();
    for str in &v {
        s.insert(str);
    } 

    println!("{}", s.len());
}


Measured memory_bytes: 18240
#include <iostream>
#include <stdio.h>
using namespace std;

#define HEAP_SIZE 250

int min(int x, int y) {
  if(x < y) return x;
  return y;
}

int max(int x, int y) {
  if(x < y) return y;
  return x;
}

int rightChild(int key) {
  return 2*key + 1;
}

int leftChild(int key) {
  return 2*key;
}

int parent(int key) {
  return key/2;
}

int main() {
  int h[HEAP_SIZE];
  int n;
  cin >> n;
  for(int i=1; i<n+1; i++) {
    cin >> h[i];
  }

  for(int i=1; i<n+1; i++) {
    int parentIndex = parent(i);
    if(parentIndex > n || parentIndex < 1) {
      parentIndex = 0;
    }
    int leftIndex = leftChild(i);
    if(leftIndex > n || leftIndex < 1) {
      leftIndex = 0;
    }
    int rightIndex = rightChild(i);
    if(rightIndex > n || rightIndex < 1) {
      rightIndex = 0;
    }

    printf("node %d: key = %d, ", i, h[i]);
    if(parentIndex > 0) {
      printf("parent key = %d, ", h[parentIndex]);
    }
    if(leftIndex > 0) {
      printf("left key = %d, ", h[leftIndex]);
    }
    if(rightIndex > 0) {
      printf("right key = %d, ", h[rightIndex]);
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 3124
package main

import (
	"fmt"
)

func sumOfDegit(n int) int {
	var sum int
	for n > 0 {
		sum += n % 10
		n /= 10
	}
	return sum
}

func main() {
	var n, a, b, sum int
	fmt.Scan(&n, &a, &b)
	for i := 1; i < n+1; i++ {
		if v := sumOfDegit(i); a <= v && v <= b {
			sum += i
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<int> vec;
//配列の添字ズレに注意
//=に注意

int main(){
  int a;  //cin>>a;
  string s; cin>>s;
  
  if(s=="RRR")a=3;
  else if(s=="SSS")a=0;
  else if(s=="RSS"||s=="SRS"||s=="SSR"||s=="RSR")a=1;
  else a=2;
  
  
  cout<< a;
}


Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
	int i,j,n[11],wk;
	for(i=0;i<10;i++){
		scanf("%d",&n[i]);
	}
	for(i=0;i<9;i++){
		for(j=i+1;j<10;j++){
			if(n[i]<n[j]){
				wk=n[i];
				n[i]=n[j];
				n[j]=wk;
			}
		}
	}
	for(i=0;i<3;i++){
		printf("%d\n",n[i]);
	}
	return 0;
}



Measured memory_bytes: 2048
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n+2, 0);
    for(int i=0; i<n; ++i)
        cin >> a[i+1];

    int sum = 0;
    for(int i=0; i<n+1; ++i)
        sum += abs(a[i+1] - a[i]);

    for(int i=0; i<n; ++i){
        int ans = sum;
        ans -= abs(a[i+1] - a[i]);
        ans -= abs(a[i+2] - a[i+1]);
        ans += abs(a[i+2] - a[i]);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
  int a, b;
  cin >> a >> b;
  a = a + b;
  cout << a / 2 + a % 2;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int N;
vector<ll> A;
vector<int> g[100010];
bool used[100010];
ll path[100010];

bool dfs(int now){
    used[now]=true;
    ll sum=0;
    bool leaf=true;
    vector<int> next;
    for(int i=0;i<g[now].size();i++){
        int u=g[now][i];
        if(used[u]) continue;
        if(!dfs(u)) return false;
        sum+=path[u];
        leaf=false;
        next.push_back(u);
    }
    if(leaf){
        path[now]=A[now];
        return true;
    }

    ll res=2*A[now]-sum;
    path[now]=res;
    if(res<0) return false;

    ll tmp=res+sum;
    if(tmp%2||res*2>tmp) return false;
    for(int i=0;i<next.size();i++){
        if(path[next[i]]*2>tmp) return false;
    }
    return true;
}

int main(){
  cin>>N;
  for(int i=0;i<N;i++){
      ll x;
      cin>>x;
      A.push_back(x);
  }
  for(int i=0;i<N-1;i++){
      int a,b;
      cin>>a>>b;
      a--;
      b--;
      g[a].push_back(b);
      g[b].push_back(a);
  }

  int start=0;
  for(int i=0;i<N;i++){
      if(g[i].size()==1) start=i;
  }

  if(!dfs(start)) cout<<"NO"<<endl;
  else{
      if(path[start]==A[start]) cout<<"YES"<<endl;
      else cout<<"NO"<<endl;
  }

  return 0;
}


Measured memory_bytes: 18292
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int k, s; cin >> k >> s;
  int ans = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - x - y;
      if (0 <= z && z <= k) ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;

int main() {
    int n,m; cin>>n>>m;
    if (n == m) cout << "Yes";
    else cout << "No";

    return 0;
}


Measured memory_bytes: 256
import sys
import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics

def main():
    n, k, *a = (int(x) for x in sys.stdin.read().split())

    c = collections.Counter(a)
    diffs = len(c)
    if diffs <= k: print(0); exit()
    remainder = diffs - k
    count = 0
    l = sorted(c.values())
    b = collections.Counter(l)
    for i, j in sorted(b.items()):
        if remainder - j > 0:
            count += j * i
            remainder -= j
        else:
            count += remainder * i
            break
    
    print(count)

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 33556
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define f first
#define s second
typedef pair<int,int> P;
int a[2000][2000],ans[2000][2000],d=0,y=999,x=1001,n,m;
bool b[1000001],used[2000][2000];
int dx[]={-1,0,1,0},tx[]={-1,0,1};
int dy[]={0,1,0,-1},ty[]={1,1,1};
int main(){
  b[0]=b[1]=1;
  for(int i=2;i<1000001;i++)
    for(int j=i+i;j<1000001;j+=i)b[j]=1;
  a[1000][1000]=1;
  a[1000][1001]=2;
  a[999][1001]=3;
  for(int i=4;i<1000001;i++){
    int yy=y+dy[d],xx=x+dx[d];
    int ya=yy+dy[(d+1)%4],xa=xx+dx[(d+1)%4];
    if(!a[ya][xa])d=(d+1)%4;
    a[yy][xx]=i;
    y=yy,x=xx;
  }
  while(cin>>n>>m,n){
    memset(ans,0,sizeof(ans));
    memset(used,0,sizeof(used));
    r(i,2000)r(j,2000)if(a[i][j]==m){
      used[i][j]=1;y=i;
      break;
    }
    for(int i=y;i<2000;i++)r(j,2000)if(a[i][j]&&used[i][j]){
      if(!b[a[i][j]])ans[i][j]++;
      r(k,3){
        y=i+ty[k],x=j+tx[k];
        if(!a[y][x]||a[y][x]>n)continue;
        ans[y][x]=max(ans[y][x],ans[i][j]);
        used[y][x]=1;
      }
    }
    int a1=0,a2;
    r(i,2000)r(j,2000)if(a[i][j]<=n)if(a1<ans[i][j]||a1==ans[i][j]&&a2<a[i][j]&&!b[a[i][j]]){
      a1=ans[i][j],a2=a[i][j];
    }
    if(!a1)cout<<"0 0"<<endl;
    else cout<<a1<<' '<<a2<<endl;
  }
}

Measured memory_bytes: 31324
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define MRE assert(0);
const int inf = 1e17;
const int mod = 998244353;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int a[1000006];
int fac2[1000006];
signed main() {
	int n; cin >> n;
	string s; cin >> s;

	for (int i = 1; i < 20; i++) {
		for (int j = (1 << i); j <= n; j += (1 << i)) {
			fac2[j]++;
		}
	}
	rep(j, n + 1)fac2[j + 1] += fac2[j];
	int c1 = 0, c2 = 0, c3 = 0;
	int res = 0;
	rep(i, n) {
		int f2 = fac2[n - 1] - fac2[i] - fac2[n - i - 1];
		if (f2 == 0)res+=(s[i]-'0');
		if (s[i] == '1')c1++;
		if (s[i] == '2')c2++;
		if (s[i] == '3')c3++;
	}

	/*
	rep(i, n)a[i] = s[i] - '0';
	for(int i=n-1;i>=0;i--) {
		n--;
		rep(j, n)a[j] = (a[j] + a[j + 1])%4;
		rep(j, n)cout << a[j]; cout << endl;
	}*/
	res %= 2;

	if (res == 1) {
		cout << 1 << endl;
		return 0;
	}
	else if (c2) {
		cout << 0 << endl;
		return 0;
	}
	else {
		rep(i, n)a[i] = s[i] - '0';
		n--;
		rep(i, n)a[i] = abs(a[i] - a[i + 1]);
		rep(i, n)a[i] /= 2;
		int res2 = 0;
		rep(i, n) {
			int f2 = fac2[n - 1] - fac2[i] - fac2[n - i - 1];
			if (f2 == 0)res2 += a[i];
		}
		if (res2 & 1)cout << 2 << endl;
		else cout << 0 << endl;
	}

}

Measured memory_bytes: 17028
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int p[100005];

int root(int x) {return p[x] < 0 ? x : p[x] = root(p[x]);}

void mer(int x, int y) {
    if ((x = root(x)) == (y = root(y))) return;
    if (p[x] > p[y]) swap(x, y);
    p[x] += p[y];
    p[y] = x;
}


int main() {
    ios::sync_with_stdio(false);
    int n, m, u, v, a[100005] = {}, z = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i], p[i] = -1;
    while (m--) cin >> u >> v, mer(u, v);
    for (int i = 1; i <= n; i++) if (root(i) == root(a[i])) z++;
    cout << z;
}


Measured memory_bytes: 1024
x,n=map(int,input().split())
p=list(map(int,input().split()))
c=0
if n==0:
    print(x)
else:
    while True:
        if x-c not in p:
            print(x-c)
            break
        elif x+c not in p:
            print(x+c)
            break
        c+=1

Measured memory_bytes: 9132
n=gets.chomp.to_i
n1=n*(n-1)/2
i=0
count=[]
n.times do |i|
  count[i]=0
end
n1.times do |i|
  m =gets
  m=m.split.map(&:to_i)
  a=m[0]-1
  b=m[1]-1
  if m[2]>m[3]
    count[a]+=3
  elsif m[2]==m[3]
    count[a]+=1
    count[b]+=1
  else
    count[b]+=3
  end
end

count2=count.sort.reverse
n.times do |i|
  n.times do |j|
    if count[i]==count2[j]
      p j+1
      break
    end
  end
end

Measured memory_bytes: 6128
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut hs: Vec<usize> = sc.vec(n);

    let mut result = 0;
    loop {
        let mut que = std::collections::VecDeque::new();
        for (idx, &x) in hs.iter().enumerate() {
            if x > 0 {
                que.push_back(idx);
            } else {
                if !que.is_empty() {
                    break;
                }
            }
        }

        if que.is_empty() {
            break;
        }

        result += 1;
        let &src = que.front().unwrap_or(&0);
        let &dst = que.back().unwrap_or(&0);
        for i in src..dst+1 {
            hs[i] -= 1;
        }
    }

    println!("{}", result);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

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

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&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: 8572
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        //MyDebugger.MakeTestCase("../TextFile2.txt"); return;
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var tbl = new List<int>();
        tbl.Add(int.Parse(input.ReadLine()));
        tbl.Add(int.Parse(input.ReadLine()));
        tbl.Add(int.Parse(input.ReadLine()));
        tbl.Add(int.Parse(input.ReadLine()));
        tbl.Add(int.Parse(input.ReadLine()));

        tbl.Sort((x,y) => {
            y=y%10;
            x=x%10;
            return (y==0 ? 10 : y) - (x==0 ? 10 : x);
        });

        int t = 0;
        foreach(var x in tbl) {
            if(t % 10 != 0) { 
                t += 10 - (t % 10);
            }
            t += x;
        }

        return t;
    }
}


Measured memory_bytes: 13268
#include<stdio.h>

int num[10000];
int main( void ) 
{
 
    int n;
    scanf( "%d", &n );
    
    int i, j;

    int cnt = n;
    for( i=0; i<n; i++ ) {
        scanf( "%d", &num[i] );
    }
    for( i=0; i<n; i++ ) {    
        if( 2 == *(num+i) ) { continue; }
        
        if( 0 == *(num+i)%2 ) {
            cnt--;
        } else {
            for( j=3; j*j<=*(num+i); j+=2 ) {
                if( 0 == *(num+i)%j ) {
                    cnt--;
                    break;
                }
            }
        }
    }
     
    printf( "%d\n", cnt );
    
    return 0;
}

Measured memory_bytes: 628
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

int main(){
    int n;cin>>n;
    if(n<1000)cout<<"ABC"<<endl;
    else cout<<"ABD"<<endl;
}

Measured memory_bytes: 256
s = input()
s1 = int(s[:2])
s2 = int(s[2:])

if 1 <= s1 <= 12:
  if 1 <= s2 <= 12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1 <= s2 <= 12:
    print("YYMM")
    exit()
  else:
    print("NA")

Measured memory_bytes: 2940
s = input()

def dfs(i, f, sum):
    if i == 3:
        if sum == 7:
            print(f + '=7')
            exit()
    else:
        dfs(i + 1, f + "-" + s[i + 1], sum - int(s[i + 1]))
        dfs(i + 1, f + "+" + s[i + 1], sum + int(s[i + 1]))

dfs(0, s[0], int(s[0]))


Measured memory_bytes: 3060
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  string s;
  std::cin >> s;
  int ans=999;
  for(int i=0; i<s.size()-2; i++){
    int n=(s[i]-'0')*100 + (s[i+1]-'0')*10 + s[i+2]-'0';
    ans=min(ans,abs(753-n));
  }
  std::cout << ans << '\n';
  return 0;
}


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

int main(){
  ll n;
  cin>>n;
  vector<ll> f(10001,0);
  for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
      for(int z=1;z<=100;z++){
        if(x*x+y*y+z*z+x*y+y*z+z*x<=10000){
          f[x*x+y*y+z*z+x*y+y*z+z*x]++;
        }
      }
    }
  }
  for(int i=1;i<=n;i++){
    cout<<f[i]<<endl;
  }
}


Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <cassert>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
 
const int INF = 1e9;
const int _N = 2e5;
 
int k;
string s;
 
template <typename T>
struct SegmentTree{
    T data[_N*4 + 1];
    T def;
    int m;
    void init(int n, T def){
        m = 1;
        this->def = def;
        while(m<n)m*=2;
        REP(i, m)data[i] = def;
    }
    void update(int i, T x){
        i += m - 1;
        data[i] = x;
        while(i >= 1){
            i = (i - 1)/2;
            data[i] = min(data[i*2 + 1], data[i*2 + 2]);
        }
    }
    T query(int a, int b){
        return _query(a, b, 0, 0, m);
    }
    T _query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return def;
        if(a <= l && r <= b) return data[k];
        T left = _query(a, b, k*2 + 1, l, (l + r) / 2);
        T right = _query(a, b, k*2 + 2, (l + r) / 2, r);
        return min(left, right);
    }
};
 
template <typename T>
struct BIT{
    int data[_N+1];
    int n;
    void init(int n, T def){
        this->n = n;
        REP(i, n+1)data[i] = def;
    }
    void add(int i, T x){
        i++;
        while(i <= n){
            data[i] += x;
            i += i&-i;
        }
    }
    T sum(int i){
        i++;
        int s = 0;
        while(i >= 1){
            s += data[i];
            i -= i&-i;
        }
        return s;
    }
    T get(int i){
        int s = sum(i);
        if(i>0) s -= sum(i-1);
        return s;
    }
};
 
SegmentTree<P> seg;
BIT<int> amount;
int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    cin >> s >> k;
    int n = s.size();
    seg.init(n, {INF, INF});
    REP(i, n)seg.update(i, {s[i] - 'a', i});
 
    amount.init(n, 0);
 
    string ans;
 
    REP(i, n){
        if(k<1){
            REP(i, n)if(!amount.get(i))
                ans += s[i];
            break;
        }
        int target = min(k + 1, n - i);
        int end = 0;
        int low = 0, high = n - 1;
        // serch RANGE whose LENGTH is (target)
        // Binary Search
        while(low < high){
            int mid = (low + high + 1) / 2;
            if(mid + 1 - amount.sum(mid) <= target)
                low = mid;
            else
                high = mid - 1;
        }
        end = low;
 
        int t = seg.query(0, end + 1).second;
        ans += s[t];
        k -= t - amount.sum(t);
        assert(k>=0);
        seg.update(t, {INF, INF});
        amount.add(t, 1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 10668
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int n = sc.nextInt();
        long limit = sc.nextLong();
        long a[] = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextLong();
        }

        boolean ok = false;
        int ans[] = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            if (a[i] + a[i + 1] >= limit) {
                ans[i] = n - 1;
                ok = true;
                break;
            }
        }

        if (!ok) {
            System.out.println("Impossible");
            return;
        }

        int p = 1;
        for (int i = 0; ans[i] == 0; i++) {
            ans[i] = p++;
        }
        for (int i = n - 2; ans[i] == 0; i--) {
            ans[i] = p++;
        }

        System.out.println("Possible");
        for (int i = 0; i < n - 1; i++) {
            System.out.println(ans[i]);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        new Main().main(sc);
        sc.close();
    }
}

Measured memory_bytes: 68832
#include <bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll>pairs;
int main() {
	// your code goes here
	std::ios::sync_with_stdio(false);
	ll t,n,i,j,l,c,f;
	map<ll,ll>m;
	cin>>n;f=1;
	i=2;c=0;
	while(n%2==0)
	{
	    m[2]++;
	    n/=i;
	}//cout<<m[2]<<"\n";
	 j=(ll)sqrt(2*m[i]);
	         if((j*(j+1))/2>m[i])
	         c+=j-1;
	         else
	         c+=j;
	for(i=3;i*i<=n;i+=2)
	{
	    f=0;
	    while(n%i==0)
	    {
	        f=1;
	        n/=i;
	        m[i]++;
	    }if(f){ 
	         j=(ll)sqrt(2*m[i]);
	         if((j*(j+1))/2>m[i])
	         c+=j-1;
	         else
	         c+=j;
	            }
	}
	if(n>2)//cout<<n<<"\n";
	c++;
    cout<<c;
	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N,K;cin >> N >> K;
    vector<LL> a(N);rep(i,N)cin >> a[i];

    LL ans = INF;
    for(int bit = 0;bit < (1 << N);++bit){
        int t = 0;
        for(int i = 1;i < N;++i){
            if(bit & (1 << i))t++;
        }
        if(t < K-1)continue;
        LL tmp = 0;
        LL gen = a[0];
        bool ok = true;
        for(int i = 1;i < N;++i){
            if(gen < a[i]){
                gen = a[i];
                ok = false;
            }
            if(bit & (1 << i)){
                if(gen > a[i])gen++;
                else{
                    if(ok){
                        gen++;
                        ok = false;
                    }
                }
                tmp += abs(gen - a[i]);
            }
        }
        ans = min(ans,tmp);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000000)

x,y = map(int,input().split())

if (y//2==x and y%2 ==0 ) : print('Yes');exit()
if (y//4==x and y%4 ==0 ) : print('Yes');exit()

for i in range(1,x):
    if (y-(i*2)) / 4 == x - i : print('Yes');exit()

for i in range(1,x):
    if (y-(i*4)) / 2 == x - i : print('Yes');exit()

print('No')


Measured memory_bytes: 9200
import math

while True:
    n = int(input())
    if n == 0:
        break
    data = [int(n) for n in input().split()]
    ave = sum(data) / len(data)
    var = 0
    for s in data:
        var += (s - ave) ** 2
    print(math.sqrt(var / len(data)))

Measured memory_bytes: 7736
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) {}
	ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
};
typedef ModInt<1000000007> mint;

struct UnionFind {
	vector<int> data;
	void init(int n) { data.assign(n, -1); }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if(x != y) {
			if(data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) { return root(x) == root(y); }
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	int size(int x) { return -data[root(x)]; }
};

int main() {
	int H; int W;
	while(~scanf("%d%d", &H, &W)) {
		vector<string> S(H);
		rep(i, H) {
			char buf[201];
			scanf("%s", buf);
			S[i] = buf;
		}
		auto revEqual = [](string s) -> bool {
			return s == string(s.rbegin(), s.rend());
		};
		auto countNum = [](string s) -> int {
			const int fact[5] = { 1, 1, 2, 6, 24 };
			map<char, int> cnt;
			for(char c : s) ++ cnt[c];
			int res = fact[s.size()];
			for(auto &&p : cnt)
				res /= fact[p.second];
			return res;
		};
		mint ans = 1;
		if(H % 2 == 1) {
			ans *= revEqual(S[H / 2]) ? 1 : 2;
			S.erase(S.begin() + H / 2);
			-- H;
		}
		if(W % 2 == 1) {
			string col;
			rep(i, H) {
				col += S[i][W / 2];
				S[i].erase(S[i].begin() + W / 2);
			}
			ans *= revEqual(col)  ? 1 : 2;
			-- W;
		}
		UnionFind uf;
		uf.init(H / 2 + W / 2);
		rep(i, H / 2) rep(j, W / 2) {
			string group;
			group += S[i][j];
			group += S[H - 1 - i][j];
			group += S[i][W - 1 - j];
			group += S[H - 1 - i][W - 1 - j];
			int num = countNum(group);
			ans *= num == 24 ? num / 2 : num;
			if(num == 24)
				uf.unionSet(i, H / 2 + j);
		}
		int ways = H / 2 + W / 2;
		rep(i, H / 2 + W / 2)
			ways -= uf.root(i) == i;
		rep(i, ways)
			ans *= 2;
		printf("%d\n", ans.get());
	}
	return 0;
}


Measured memory_bytes: 256
N=gets.to_i
A=gets.split.map(&:to_i)
MOD=10**9+7
counter=[0,0,0]
ans=1

A.each do |a|
  i=counter.index(a)
  ans=ans*counter.count(a)%MOD
  counter[i]+=1 if !i.nil?
end

p ans

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

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

int main() {
    int n;
    cin >> n;
    ll ans = modpow(10, n) - (modpow(9, n)*2 - modpow(8, n));
    ans %= mod;
    if(ans < 0) ans += mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    for(int i=0;i<d-b;i++){
        cout<<'U';
    }
    for(int i=0;i<c-a;i++){
        cout<<'R';
    }
    for(int i=0;i<d-b;i++){
        cout<<'D';
    }
    for(int i=0;i<c-a+1;i++){
        cout<<'L';
    }
    for(int i=0;i<d-b+1;i++){
        cout<<'U';
    }
    for(int i=0;i<c-a+1;i++){
        cout<<'R';
    }
    cout<<'D';
    cout<<'R';
    for(int i=0;i<d-b+1;i++){
        cout<<'D';
    }
    for(int i=0;i<c-a+1;i++){
        cout<<'L';
    }
    cout<<'U'<<endl;
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

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

    ll A, B, C;
    cin >> A >> B >> C;
    cout << ((A == B && B == C )?"Yes":"No") << endl;
    return 0;
}

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

int main() {
  int N, W;
  cin >> N >> W;
  int M = N * 1000 + 1;
  vector<long> V(M, LONG_MAX);
  V.at(0) = 0;
  while (N--) {
    int w, v;
    cin >> w >> v;
    for (int i = M - 1; i >= 0; i--) {
      if (V.at(i) != LONG_MAX && i + v < M) {
        V.at(i + v) = min(V.at(i + v), V.at(i) + w);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < M; i++) {
    if (V.at(i) <= W) ans = max(ans, i);
  }
  cout << ans << "\n";
}

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

char s[20];
int main() {
	int n; scanf("%d", &n);
	int c1 = 0, c2 = 0, c3 = 0, res = 0;
	for(int i = 0; i < n; i++) {
		scanf("%s", s);
		int n = strlen(s);
		for(int j = 0; j < n - 1; j++)
			if(s[j] == 'A' && s[j + 1] == 'B') res++;
		if(s[n - 1] == 'A' && s[0] == 'B') c1++;
		else if(s[n - 1] == 'A') c2++;
		else if(s[0] == 'B') c3++;
	}
bool f = false;
if(c2) f = true;
	int t = min(min(c1, c2), c3);
	res += t * 2;
	c1 -= t; c2 -= t; c3 -= t;
	if(!c1) res += min(c2, c3);
	else {
		res += c1;
		if(!c2 && !c3 && !f) res--;
	}
	printf("%d\n", res);
	return 0;
}

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

int main(){
	char ch;
	int a[26] = {0};
	while ( cin >> ch ){
		if ( ch >='A' && ch <='Z' ) {
			ch-='A'-'a';
		}
		if ( ch >='a' && ch <='z' ) {
			a[ch-'a']++;
		}
	}
	for ( int i = 0 ;i<26 ;i++ ) {
		ch = 'a'+i;
		cout << ch << " : " << a[i] << endl;
	}
}

Measured memory_bytes: 1140
N,M=map(int,input().split())
MOD=10**9+7
 
def cmb(n, r, p):
  numerator = 1
  for i in range(n-r+1, n+1):
    numerator = numerator * i % p
  denominator = 1
  for j in range(1, r+1):
    denominator = denominator * j % p
  denominator = pow(denominator, p-2, p)
  return (numerator * denominator)%p
 
def factorization(n):
  l = []
  t = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if t%i==0:
      cnt=0
      while t%i==0:
        cnt+=1
        t //= i
      l.append([i, cnt])
  if t!=1:
    l.append([t, 1])
  if l==[]:
    l.append([n, 1])
  return l
 
ans=1
F=factorization(M)
for i in range(len(F)):
  f=F[i][1]
  ans*=cmb(f+N-1,f,MOD)
  ans%=MOD

if M==1:
  print(1)
else:
  print(ans)

Measured memory_bytes: 9532
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] a=new int[n];
    boolean mc=false;
    long sum=0;
    for(int i=0;i<n;i++){
      a[i]=sc.nextInt();
      if(a[i]<0){
        mc=!mc;
        a[i]*=-1;
      }
      sum+=a[i];
    }
    if(!mc){
      System.out.println(sum);
      return;
    }
    Arrays.sort(a);
    System.out.println(sum-2*a[0]);
  }
}

Measured memory_bytes: 50940