akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  vector<string> v;
  while(cin>>s){
    while(s[s.size()-1]=='.'||s[s.size()-1]==',')
      s.erase(s.end()-1);
    if(3<=s.size()&&s.size()<=6)
      v.push_back(s);
    //cout<<v.size()<<endl;                                
  }
  rep(i,v.size()){
    if(i)cout<<" ";
    cout<<v[i];
  }
  cout<<endl;
}

Measured memory_bytes: 3000
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    H, N = map(int, input().split())
    A = [None] * N
    B = [None] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    INF = 10**12
    dp = [[INF]*(H+1) for _ in range(N+1)]
    dp[0][0] = 0
    for i in range(N):
        for j in range(H+1):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            dp[i+1][min(j+A[i],H)] = min(dp[i+1][min(j+A[i],H)],dp[i+1][j]+B[i])
    print(dp[N][H])

if __name__ == "__main__":
    main()


Measured memory_bytes: 145640
n, m = map(int, input().split())
a = []
b = []

for i in range(m):
    x, y = map(int, input().split())
    if x == 1:
        a.append(y)
    elif y == n:
        b.append(x)

if set(a) & set(b):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  cout << s.substr(0, 3) << endl;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

// 素数取得
vector<bool> get_prime_list(int n) {
  vector<bool> prime_flag(n, true);
  prime_flag[0] = false;
  prime_flag[1] = false;

  for (int i = 2; i < n; i++) {
    if (!prime_flag[i]) continue;
    for (int j = i * 2; j < n; j += i) prime_flag[j] = false;
  }

  return prime_flag;
}

signed main() {
  int N;
  cin >> N;
  int ans = 0;
  bool finish = false;
   while (N > 1) {
    for (int i = 2; i < (ll)1e6 +100; i += 2) {
      if (i >= (ll)1e6 + 10) {
        finish = true;
        break;
      }
      if (i == 4) i--;
      int count = 0;
      while (N % i == 0) {
        count++;
        N /= i;
        PRINT(N)
      }
      for (int j = 1; count >= j; j++) {
        count -= j;
        ans++;
        if (count < j + 1) {
          break;
        }
        PRINT(N)
      }
      if (N == 1) break;
    }
    if(finish) break;
  }
  if(N>1) ans += 1;
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <set>

using namespace std;

int main()
{
string s;
set<char> skup;
cin >> s;
int n = s.length();
for(int i = 0; i < n; i++)
{
skup.insert(s[i]);
}
if((skup.find('W') != skup.end() && skup.find('E') == skup.end()) || (skup.find('W') == skup.end() && skup.find('E') != skup.end()) || (skup.find('N') != skup.end() && skup.find('S') == skup.end()) || (skup.find('S') != skup.end() && skup.find('N') == skup.end()))
{
 cout << "No";
}
else
{
cout << "Yes";
}
return 0;
}

Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
stones = []
h.times { stones << gets.chomp.split("") }
left_edge = 0
right_edge = 0
stones.each_with_index do |row, row_index|
  tmp_left_edge = 8
  tmp_right_edge = -1
  row.each_with_index do |column, column_index|
    if column == "#"
      tmp_left_edge = [tmp_left_edge, column_index].min
      tmp_right_edge = [tmp_right_edge, column_index].max
    end
  end
  if right_edge <= tmp_left_edge
    left_edge = tmp_left_edge
    right_edge = tmp_right_edge
  else
    puts "Impossible"
    exit
  end
end
puts "Possible"


Measured memory_bytes: 1788
#undef NDEBUG
#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

//#define YA

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cerr << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}


int n, x, a[1111];

void solve(bool __attribute__((unused)) read) {
    cin >> n >> x;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        if (a[i] <= x) {
            x -= a[i];
            ++ans;
        }
    }
    if (x == a[n - 1])
        ++ans;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// clang-format off
const double PI=3.14159265358979323846;
using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

void solve(long long A, long long B, long long H, long long M) {
  // solver code

  double angle_H = (double)H / 12.0 * 360.0 + 30.0 * (M / 60.0);
  double angle_M = (double)M / 60.0 * 360.0;

  double angle_diff = abs(angle_H - angle_M);

  // COUT(angle_diff);
  // COUT(A);
  // COUT(B);
  //
  double distance = sqrt(A * A + B * B - 2 * A * B * cos(angle_diff / 180 * PI));

  cout << fixed << setprecision(10);
  cout << distance << endl;
}

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


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

using namespace std;

const int MAX_N = 200000;

int main(int argc, char const *argv[])
{
	int n, x[MAX_N], y[MAX_N];
	vector<int> b;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		scanf("%d", &x[i]);
		y[i] = x[i];
	}
	sort(y, y+n);

	int mid = n/2 - 1;

	for (int i = 0; i < n; ++i) {
		if (x[i]<=y[mid]) b.push_back(y[mid+1]);
		else b.push_back(y[mid]);
	}

	for (int i = 0; i < n; ++i) {
		printf("%d\n", b[i]);
	}
	return 0;
}

Measured memory_bytes: 4724
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;
using pll = std::pair<long long, long long>;
static const int nmax = 200011;
long long p2[nmax];

template <typename T>
T gcd(T a, T b)
{
    if(a < b) std::swap<T>(a, b);
    T r = a % b;
    while(r > 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main()
{
    int N, M;
    long long mod = 1000000007;
    p2[0] = 1;
    for (int i = 0; i < nmax - 1; ++i)
    {
        p2[i + 1] = 2 * p2[i] % mod;
    }

    scanf("%d", &N);
    vector<long long> A(N), B(N);
    for (int i = 0; i < N; ++i)
    {
        scanf("%lld %lld", &A[i], &B[i]);
    }

    map<pll, pll> Map;
    long long zero = 0;;
    for (int i = 0; i < N; ++i)
    {
        if (A[i] == 0 && B[i] == 0)
        {
            ++zero;
            continue;
        }

        if (A[i] != 0 && B[i] != 0)
        {
            if (B[i] < 0) A[i] = -A[i], B[i] = -B[i];
            long long c = gcd<long long>(abs(A[i]), abs(B[i]));
            A[i] = A[i] / c, B[i] = B[i] / c;
            if (A[i] < 0) ++Map[make_pair(B[i], -A[i])].first;
            else ++Map[make_pair(A[i], B[i])].second;
        }
        else if (A[i] == 0 && B[i] != 0)
        {
            ++Map[make_pair(1, 0)].first;
        }
        else
        {
            ++Map[make_pair(1, 0)].second;
        }
    }
    long long ans = 1;
    for (auto m : Map)
    {
        long long cnt = p2[m.second.first] + p2[m.second.second] - 1; // どちらも選ばない状態(1通り)を引く
        ans = (ans * cnt) % mod;
        if (ans < 0) ans = (ans + mod) % mod;
    }
    ans = (ans + zero - 1 + mod) % mod;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 23432
n, k = map(int, input().split())
ans = 0
for b in range(1, n+1):
    p = n // b
    r = n - p*b
    ans += p*(max(0, b-k)) + max(0, r-k+1)
if k == 0:
    ans -= n
else:
    pass
print(ans)

Measured memory_bytes: 3060
#![allow(non_snake_case)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! test {
    ($($input:expr => $expected_output:expr),*) => {
        #[test]
        fn solve_test() {
            let mut i = 0;
            println!("");
            $(
                i += 1;
                println!("Case {}:", i);
                println!("[in]\n{}", $input);
                println!("[out]\n{}", solve($input));
                println!("[expected out]\n{}", $expected_output);
                println!("");
                assert_eq!(solve($input), $expected_output);
             )*
        }
    }
}

test! {
r"2
10000 JPY
0.10000000 BTC
" => r"48000",

r"3
100000000 JPY
100.00000000 BTC
0.00000001 BTC
" => r"138000000.0038"
}

use std::cmp::max;
use std::cmp::min;

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        N: i32,
        xu: [(f64, String); N]
    }

    const BTC_YEN: f64 = 380000.0;

    let mut sum_yen: f64 = 0.0;
    for (x, u) in xu {
        if u == "BTC" {
            sum_yen += x*BTC_YEN;
        } else {
            sum_yen += x;
        }
    }

    let ans: String = sum_yen.to_string();
    return ans;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
// int N が既に与えられているとする.

int main() {
  int N;
  cin >> N;
  std::unordered_map<std::string, int> um;
  for (int i = 0; i < N; i++) {
    string str;
    cin >> str;
    um[str] = 1;
  }
  cout << um.size();
}

Measured memory_bytes: 17792
/* Author : arman_ferdous 
 * Date   : 10 May 2020 10:09:33
 * TAG    : Noob Problem 
 */

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

using ll = long long;
using ii = pair<int,int>;

const int N = 110;
int n, m;
int a[N][N]; char s[N];

int dist[N][N];
deque<pair<int,int>> q;

int dx[] = {1, 0};
int dy[] = {0, 1};

int main() { 
  scanf("%d %d", &n, &m);
  for(int i = 1; i <= n; i++) {
    scanf(" %s", s + 1);
    for(int j = 1; j <= m; j++) {
      a[i][j] = (s[j] == '.' ? 0 : 1);
    }
  }
  for(int i = 0; i <= n + 1; i++) a[i][0] = a[i][m + 1] = 1; 
  for(int j = 0; j <= m + 1; j++) a[0][j] = a[n + 1][j] = 1;
  a[0][1] = 0; a[n][m + 1] = 0;

  memset(dist, -1, sizeof dist);
  q.push_front({0, 1});
  dist[0][1] = 0;
  while(!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop_front();
    for(int k = 0; k < 2; k++) {
      int tx = x + dx[k], ty = y + dy[k];
      if(min(tx, ty) <= 0 || tx > n || ty > m) continue;

      if(a[x][y] == a[tx][ty] || (a[x][y] == 1 && a[tx][ty] == 0)) {
        if(dist[tx][ty] != -1 && dist[tx][ty] <= dist[x][y]) continue;
        dist[tx][ty] = dist[x][y];
        q.push_front({tx, ty});
      } else {
        if(dist[tx][ty] != -1 && dist[tx][ty] <= dist[x][y]) continue;
        dist[tx][ty] = dist[x][y] + 1;
        q.push_back({tx, ty});
      }
    }
  }
  printf("%d\n", dist[n][m]);
  return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    int count = 0;
    while(count!=k){
        if(count%2==0){
            if(a%2!=0) a-=1;
            a /= 2;
            b += a;
        }
        else{
            if(b%2!=0) b-=1;
            b /= 2;
            a += b;
        }
        count++;
    }
    printf("%d %d",a,b);
    return 0;
}    

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#define max(a,b) (a>b?a:b)
using namespace std;

int main(){
	stack<char> st;
	string s;
	getline(cin, s);
	int ans = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (!st.empty() && ((st.top() == '1' && s[i] == '0') || (st.top() == '0' && s[i] == '1')))
		{
			ans += 2;
			st.pop();
			
		}
		else
			st.push(s[i]);
	}
	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int a[100][301];
int dp[101][301];
int w[50];
int p[50];

int main() {
  int s, d, m;
  while(cin>>s>>d>>m) {
    memset(a,0,sizeof(a));
    REP(i,s) {
      int k;
      cin >> k;
      REP(j,k) {
        int w, p;
        cin >> w >> p;
        for (int l=300; l>=p; --l) {
          a[i][l] = max(a[i][l], a[i][l-p]+w);
        }
      }
    }
    memset(dp,0,sizeof(dp));
    REP(i,d) {
      int f;
      cin >> f;
      REP(j,301) {
        for (int k=300; k>=j; --k) {
          dp[i+1][k] = max(dp[i+1][k], dp[i][k-j]+a[f][j]);
        }
      }
    }
    int ma=-1,ans=0;
    for (int i=0;i<=m; ++i) {
      if (dp[d][i]>ma) {
        ma = dp[d][i];
        ans = i;
      }
    }
    cout << ma << " " << ans << endl;
  }
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <set>
#include <map>
using namespace std;

struct UnionFind {
	vector<int> par;

	UnionFind(int n) : par(n, -1) { }
	void init(int n) { par.assign(n, -1); }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

int main() {
	int N, K, L;
	cin >> N >> K >> L;
	UnionFind uf0(N);
	UnionFind uf1(N);
	for (int n = 0; n < K; ++n) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		uf0.merge(p, q);
	}
	for (int n = 0; n < L; ++n) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		uf1.merge(p, q);
	}
	map<pair<int,int>,int>mp;
	for (int i= 0;i<N;++i) {
		pair<int, int>p = make_pair(uf0.root(i),uf1.root(i));
		mp[p]++;
	}
	for (int i = 0; i < N; ++i) {
		pair<int, int>p = make_pair(uf0.root(i), uf1.root(i));
		cout << mp[p]<<" ";
	}
	return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  int ans=0;
  for (int i=A;i<=B;i++){
    if (i/10000==i%10 and i/1000%10==i/10%10){
      ans+=1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
# 問題：https://atcoder.jp/contests/abc140/tasks/abc140_a

n = int(input())
a = list(map(int, input().strip().split()))
b = list(map(int, input().strip().split()))
c = list(map(int, input().strip().split()))

res = b[a[0]-1]
for i in range(1, n):
    res += b[a[i]-1]
    if a[i] - a[i-1] == 1:
        res += c[a[i-1]-1]

print(res)


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

#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define RFOR(i, l, r) for (int i = (int)(r); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vll a(n);
    REP(i, n) cin >> a[i];

    ll ans = 0;
    while (true) {
        ll s = 0;
        REP(i, n) {
            s += a[i] / n;
        }
        if (s == 0) break;
        REP(i, n) {
            ll x = s - a[i] / n;
            a[i] %= n;
            a[i] += x;
        }
        ans += s;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;



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

    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    REP(i, m) cin >> a[i] >> b[i];
    vector<P> p(m);
    REP(i, m){
        p[i].first = a[i], p[i].second = b[i];
    }

    vector<bool> hasi(n-1, false);
    sort(all(p));
    int l = p[0].first, r = p[0].second;
    int ans = 1;
    FOR(i, 1, m){
        if(p[i].first >= r){
            ans++;
            l = p[i].first, r = p[i].second;
            continue;
        }
        r = min(p[i].second, r);
    }
    
    cout << ans << endl;
} 


Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iterator>
#include <set>
#include <functional>

using namespace std;

#define DT int
#define forn(i,n)for(i=0;i<n;i++)
#define forc(i,c,n)for(i=c;i<=n;i++)
#define all(x) (x).begin(), (x).end()


int main() {
	ifstream fin("Text.txt");
	DT i, j, q;
	DT a=-1, b, n, m,x;
	string st;
	cin >> st;
	x = st.size();
	forn(i, st.size()) {
		if (st[i] == 'A' && a == -1)
			a = i;
		if (st[i] == 'Z')
			b = i;
	}
	cout << b - a + 1 << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
using namespace std;
 
int main(){
  //入力
  long long N;
  cin>>N;
  //出力
  long long ans=0;
  for(int i=0;i<N;i++){
    ans+=i;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <unordered_map>
#include <queue>

using namespace std;

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

    int n;
    cin >> n;
    if (n % 1000 == 0) {
        cout << 0 << endl;
    } else {
        cout << (1000 - (n % 1000));
    }
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;
int main(){
	char a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	if (a == f&&b == e&&c == d){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
while True:
    try:
        input_line = input()
        if input_line == '':
            break
        else:
            a, b, c, d, e, f = map(float, input_line.split())
            x = (b*f-c*e) / (b*d-a*e)
            y = (c-a*x)/b
            print("{:.3f} {:.3f}".format(x+0,y+0))
    except:
        break


Measured memory_bytes: 5588
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int a,b,c;
  cin >> a >> b >> c;

  cout << min(b / a , c);


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
local xor = bit.bxor
local n = io.read("*n")
local t = {}
local z = 0
for i = 1, n do
  t[i] = io.read("*n")
  z = xor(z, t[i])
end
local r = {}
for i = 1, n do
  r[i] = xor(z, t[i])
end
print(table.concat(r, " "))


Measured memory_bytes: 11156
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
int n,w;
vector<pair<int,int>> v;
ll dp[N][101];
bool vis[N][101];
ll calc(int wgt,int cnt)
{
  if(wgt>w)
    return -1e18;
  if(cnt==n)
    return 0;
  if(vis[wgt][cnt])
    return dp[wgt][cnt];
  vis[wgt][cnt]=1;
  ll x=calc(wgt+v[cnt].first,cnt+1)+v[cnt].second;
  ll y=calc(wgt,cnt+1);
  return dp[wgt][cnt]=max(x,y);
}
int main() {
 // freopen("in.txt", "r", stdin);
 // freopen("out.txt", "w", stdout);
  scanf("%d%d", &n,&w);
  for(int i=0;i<n;++i)
  {
    int x,y;
    scanf("%d%d", &x,&y);
    v.push_back({x,y});
  }
  cout<<calc(0,0);
}






Measured memory_bytes: 88832
#include <cstdio>

const int P=1000000007;
inline int mul(const int &a,const int &b){return 1ll*a*b%P;}
struct matrix{
	int num[2][2];
	matrix operator*(matrix a){
		matrix c;
		for(int i=0;i<2;i++)
			for(int j=0;j<2;j++)
				c.num[i][j]=(1ll*num[i][0]*a.num[0][j]+1ll*num[i][1]*a.num[1][j])%P;
		return c;
	}
}a,ans;
void qsm(matrix a,long long n){
	for(int i=0;i<2;i++)
		for(int j=0;j<2;j++)
			ans.num[i][j]=(i==j);
	while(n){
		if(n&1)ans=ans*a;
		a=a*a;
		n>>=1;
	}
}
int qsm(int a,long long b){
	int ans=1;
	while(b){
		if(b&1)ans=mul(ans,a);
		a=mul(a,a);
		b>>=1;
	}
	return ans;
}
int W,H,in,out,cnt,stat;
long long k;
bool mat[2001][2001];
char str[2001];
int get(){
	char ch=getchar();
	while(ch!='.'&&ch!='#')ch=getchar();
	return (ch=='#');
}
int main(){
	scanf("%d%d%lld",&W,&H,&k);
	if(k<=1){
		puts("1");
		return 0;
	}
	for(int i=1;i<=W;i++){
		scanf("%s",str+1);
		for(int j=1;j<=H;j++)
			cnt+=(mat[i][j]=(str[j]=='#'));
	}
	for(int i=1;i<=W;i++)
		if(mat[i][1]&&mat[i][H])stat|=1,++out;
	for(int i=1;i<=H;i++)
		if(mat[1][i]&&mat[W][i])stat|=2,++out;
	if(stat==3){
		puts("1");
		return 0;
	}
	if(!stat){
		printf("%d\n",qsm(cnt,k-1));
		return 0;
	}
	for(int i=1;i<=W;i++)
		for(int j=1;j<=H;j++)
			if(stat==1&&j<H&&mat[i][j]&&mat[i][j+1])++in;
			else if(stat==2&&i<W&&mat[i][j]&&mat[i+1][j])++in;
	a.num[0][0]=cnt;
	a.num[0][1]=0;
	a.num[1][0]=in;
	a.num[1][1]=out;
	qsm(a,k-2);
	long long _ans=1ll*cnt*ans.num[0][0]-(1ll*cnt*ans.num[1][0]+1ll*in*ans.num[1][1]);
	_ans=((_ans%P)+P)%P;
	printf("%lld\n",_ans);
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int n; cin >> n;
   long long sum =0;
   int p = n+1;
   while(p--)
   {
       if (p%5==0 || p%3 == 0){/*do nth */}
       else {sum += p;}
   }
   cout << sum <<endl;
    return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    string s,t;cin>>s>>t;
    map<char,int>c;
    rep(i,s.size())c[s[i]]++;
    rep(i,t.size()){
        if(c[t[i]]==0){
            cout<<-1<<endl;
            return 0;
        }
    }
    vvi a;
    a.resize(26);
    rep(i,s.size()){
        a[s[i]-'a'].PB(i+1);
    }
    int d=a[t[0]-'a'][0];
    ll ans=d;
    for(int i=1;i<t.size();++i){
        int l=upper_bound(all(a[t[i]-'a']),d)-a[t[i]-'a'].begin();
        if(l==a[t[i]-'a'].size()){
            ans+=s.size()-d;
            ans+=a[t[i]-'a'][0];
            d=a[t[i]-'a'][0];
        }
        else{
            ans+=a[t[i]-'a'][l]-d;
            d=a[t[i]-'a'][l];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
int main()
{
    ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    string S;
    cin>>S;
    int N=S.size();
    if(S[0]=='?')
        S[0]='D';
    for(int i=1;i<N;i++)
    {
        if(S[i]=='?')
        {
            // if(S[i-1]=='P')
            // {
                S[i]='D';
            // }
        }
    }
    cout<<S;
}

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

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

	int min = numeric_limits<int>::max();
	int max = numeric_limits<int>::min();
	long sum = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		min = std::min(min, x);
		max = std::max(max, x);
		sum += x;
	}
	cout << min << " " << max << " " << sum << endl;
}



Measured memory_bytes: 3112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		double[] a = new double[n];
		
		String[] input = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++) {
			a[i] = Double.parseDouble(input[i]);
		}
		
		double ans = solve(a);
		
		System.out.println(ans);
	}

	private static double solve(double[] a) {
		
		double[][] dp = new double[a.length+1][a.length+1];
		
		dp[0][0]=1;
		
		for (int i = 1; i < dp.length; i++) {
			for (int j = 0; j < dp.length; j++) {
				if(j==0) {
					dp[i][j] = (1-a[i-1])*dp[i-1][j];
				}else {
					dp[i][j] = (1-a[i-1])*dp[i-1][j]+a[i-1]*dp[i-1][j-1];
				}
			}
		}
		
		double res = 0;
		
		for(int i=((a.length/2)+1); i<=a.length; i++) {
			res += dp[a.length][i];
		}
		
		return res;
	}
}


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

int main(){
	int n;
	cin >> n;
	vector<int> num(n);
	rep(i, n) cin >> num.at(i);

	sort(num.begin(), num.end());
	reverse(num.begin(), num.end());

	int alice = 0;
	int bob = 0;

	rep(i, n){
		if(i%2 == 0)
			alice += num.at(i);
		else
			bob += num.at(i);
	}
	cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    ll n;cin>>n;
    string s,t; cin>>s>>t;
    ll ans = 1;
    ll id=0;
    ll prev = 0;
    while(id<s.size()){
        if (s[id]==t[id]){
            id++;
            if (prev==1) ans*=2;
            else if(prev==2) ans*=1;
            else if(prev==0) ans*=3;
            prev = 1;
            ans %= mod;
        }
        else if(s[id]==s[id+1] && t[id]==t[id+1]){
            id += 2;
            if(prev==1) ans*=2;
            else if(prev==2) ans*=3;
            else if (prev==0) ans*=6;
            prev=2;
            ans %=mod;
        }
    }
    cout<<ans%mod<<endl;
    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();

		int a = Integer.parseInt(s.substring(0, 2));
		int b = Integer.parseInt(s.substring(2, 4));

		if (a <= 12 && a >= 1 && b <= 12 && b >= 1) {
			System.out.println("AMBIGUOUS");
		} else if (a <= 12 && a >= 1) {
			System.out.println("MMYY");
		} else if (b <= 12 && b >= 1) {
			System.out.println("YYMM");
		} else {
			System.out.println("NA");
		}

		sc.close();

	}
}

Measured memory_bytes: 35508
#include<bits/stdc++.h>
using namespace std;
const int maxn=100010;
struct node
{
	int x;
	int a;
	int b;
}edge[maxn];
bool cmp(node a,node b)
{
	return a.x<b.x;
}
int x,y,z,a,b,c,n;
multiset<int>G;
long long sum,f[maxn],p[maxn],ans;
int main()
{
	cin>>x>>y>>z;
	n=x+y+z;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b>>c;
		ans+=c;
		a-=c,b-=c;
		edge[i].x=a-b;
		edge[i].a=a,edge[i].b=b;
	}
	sort(edge+1,edge+1+n,cmp);
	for(int i=1;i<=n;i++)
	{
		sum+=edge[i].b;
		G.insert(edge[i].b);
		if(G.size()>y)
		{
			sum-=*G.begin();
			G.erase(G.begin());
		}
		f[i]=sum;
	}
	G.clear(),sum=0;
	for(int i=n;i;i--)
	{
		sum+=edge[i].a;
		G.insert(edge[i].a);
		if(G.size()>x)
		{
			sum-=*G.begin();
			G.erase(G.begin());
		}
		p[i]=sum;
	}
	long long tmp=ans;
	ans=0;
	for(int i=y;i+x<=n;i++)
	{
		ans=max(ans,tmp+f[i]+p[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 7424
#include <stdio.h>

int main()
{
    int a, b, c;
    int max;            // a, b, cのうち最大のもの
    int x;              // a, b, cの最終的な値
    
    scanf("%d %d %d", &a, &b, &c);

    // maxを求める
    max = a;
    if (max < b)
    {
	max = b;
    }
    if (max < c)
    {
	max = c;
    }

    // xを求める
    if (((3 * max) % 2) == ((a + b + c) % 2))
    {
	x = max;
    }
    else
    {
	x = max + 1;
    }

    printf("%d\n", ((3 * x) - (a + b + c)) / 2);

    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

bool isOK(ll x, vector<ll>& a) {
	ll cn = x;
	for (int i = 0; i < a.size(); i++) {
		cn = (cn / a[i]) * a[i];
	}
	return cn == 2;
}

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N);
	for (int i = 0; i < N; i++)cin >> a[i];


	ll mx = 2;
	for (int i = N-1; i >= 0; i--) {
		mx = ((mx + a[i] - 1) / a[i]) * a[i];
	}
	
	ll cn = mx;
	for (int i = 0; i < N; i++) {
		cn = (cn / a[i]) * a[i];
	}
	if (cn != 2) {
		cout << -1 << endl;
		return 0;
	}

	ll ng = INF_LL/4; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll ok = mx; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;
		
		if (isOK(mid, a)) ok = mid;
		else ng = mid;
	}
	cout << mx << " " << ok << endl;

}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    char field[310][310];
    cin>>n;
    rep(i,n){
        rep(j,n){
            cin>>field[i][j];
        }
    }
    ll ans=0;
    rep(k,n){
        bool flag=true;
        rep(i,n){
            for(int j=i+1;j<n;j++){
                ll xk =(j-k<0)? j+n-k :j-k;
                ll yk =(i-k<0)? i+n-k :i-k;
                if(field[i][xk] !=field[j][yk]) flag=false;
            }
        }
        if(flag) ans++;
    } 
    cout<<ans*n<<endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const ll mod =1000000007;
int main(){
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vector<long long> a(x), b(x), c(x);
    for(int i=0; i<x; i++) cin>>a[i];
    for(int i=0; i<y; i++) cin>>b[i];
    for(int i=0; i<z; i++) cin>>c[i];
    priority_queue<long long> pq;
    for(int j=0; j<x; j++){
        for(int l =0; l<y; l++){
            pq.push(a[j] +b[l]); 
        }
    }
    priority_queue<long long> ans;
    for(int i=0; i<z; i++){
        priority_queue<long long> tpq=pq;
        for(int j=0; j<min(k,x*y); j++){
            long long tmp = tpq.top();
            tpq.pop();
            ans.push(tmp +c[i]);
        }
    }
    for(int i=0; i<k; i++){
        cout<<ans.top()<<endl;
        ans.pop();
    }
}

Measured memory_bytes: 50652
A, B = map(int, input().split())
S = input()
flag = True

for i in S[:A]:
  if i == '-':
    flag = False
if S[A] !='-':
  flag = False
for i in S[A+1:A+B+1]:
  if i == '-':
    flag = False
   
if flag:
  print('Yes')
else:
  print('No')


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

INF = float('inf')

N = int(input().strip())
data = [list(map(int, input().split())) for _ in range(N)]
cost_b = []
cost_D = []
for b in range(1<<N):
  towns = []
  cost = INF
  for i in range(N):
    if (b>>i)&1:
      towns.append(data[i])
  for i in range(len(towns)):
    X = towns[i][0]
    cost = min(cost,sum(abs(towns[j][0]-X)*towns[j][2] for j in range(len(towns))))
  for i in range(len(towns)):
    Y = towns[i][1]
    cost = min(cost,sum(abs(towns[j][1]-Y)*towns[j][2] for j in range(len(towns))))
  if len(towns) == 0:
    cost = 0
  cost_b.append(cost)
  cost_D.append(sum(min(abs(towns[j][0]),abs(towns[j][1]))*towns[j][2] for j in range(len(towns))))

dp = [[INF]*(N+1) for i in range(1<<N)]

for i in range(1<<N):
  dp[i][0] = cost_D[i]
count = 0
for k in range(1,N+1):
  for i in range(1<<N)[::-1]:
    x = i
    while x>=0:
      x &= i
      new = dp[i-x][k-1]+cost_b[x]
      if dp[i][k] > new:
        dp[i][k] = new
      if new == 0:
        break
      x -= 1
for i in range(N+1):
  print(dp[-1][i])


Measured memory_bytes: 111060
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();

        int[] a = new int[n];
        int[] b = new int[n];

        for(int i=0; i<m; i++) {
            a[sc.nextInt()-1]++;
            b[sc.nextInt()-1]++;
        }
        sc.close();

        for(int i=0; i<n; i++) {
            System.out.println(a[i] + b[i]);
        }
    }
}


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

class BIT{
public:
  int n,bit[555555];
  BIT(){fill(bit,bit+555555,0);}
  void add(int i,int x){
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  int sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
};

int main() {
  int n;
  cin >> n;
  ll a[n],x=0;
  for(ll i=0; i<n; i++) {
    cout << "? " << 1 << " " << i+1 << endl;
    cin >> a[i];
    ll y=a[i];
    a[i]-=x;
    x=y;
  }
  BIT b=BIT();
  b.n=n;
  for(int i=0; i<n; i++) {
    b.add(i+1,1);
  }
  ll d[n];
  for(int i=n-1; i>=0; i--) {
    int l=1,r=n+1;
    while(l+1!=r) {
      int m=(l+r)/2;
      if(b.sum(m-1)<=a[i]) l=m;
      else r=m;
    }
    d[i]=n-l+1;
    b.add(l,-1);
  }
  cout << "!";
  for(int i=0; i<n; i++) cout << " " << d[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 288880
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N;cin>>N;
  vector<int64_t>A(N);
  for(int i=0;i<N;i++)
    cin>>A.at(i);
  int64_t ans=A.at(0)-1;int64_t a=2;
  for(int i=1;i<N;i++){
  if(A.at(i)==a)a++;
    else
      ans+=(A.at(i)-1)/a;
  }cout<<ans<<endl;
   return 0;
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int sum = a + b + c;
	if (sum >= 22) {
		cout << "bust";
		return 0;
	}
	else {
		cout << "win";
		return 0;
	}

}


Measured memory_bytes: 3632
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	
	scanf("%d", &n);
	
	vector<pair<int, pair<string, int> > > v;
	for (int i = 0; i < n; i++){
		char pName[8];
		int num;
		scanf("%s %d", pName, &num);
		v.push_back(make_pair(strlen(pName), make_pair((string)pName, num)));
	}
	
	sort(v.begin(), v.end());
	
	string lead = "$";
	int cnt = 0;
	for (int i = 0; i < n; i++){
		if (lead != v[i].second.first){
			if (lead != "$") printf("%s %d\n", lead.c_str(), cnt);
			lead = v[i].second.first;
			cnt = v[i].second.second;
		}
		else cnt += v[i].second.second;
	}
	return (!printf("%s %d\n", lead.c_str(), cnt));
}

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

int main() {

    int n;
    string s;
    cin >> n >> s;

    int leftcount = 0,rightcount = 0;

    for(int i=0; i<s.size(); i++){
        if(s[i] == 'E'){
            rightcount++;
        }
    }

    int ans = 1000000;

    for(int i=0; i<s.size(); i++){
        if(s[i] == 'E'){
            rightcount--;
        }
        ans = min(ans,leftcount + rightcount);
        if(s[i] == 'W'){
            leftcount++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 900
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
using namespace std;
typedef long long ll;

int main(){
    int a,b,c;cin>>a>>b>>c;
    if(a>b)swap(a,b);
    if(c<=b&&c>=a)cout<<"Yes";
    else cout<<"No";
}

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

int main(){
	int n, q, l, r, result, io[100000] = {}, t = 0;
	char s[100000];
	cin >> n >> q;
	cin >> s;
	for(int i = 1; i < n; i++){
		if(s[i-1] == 'A'){
			if(s[i] == 'C'){
				t++;
			}
		}
		io[i] = t;
		//cout << io[i];
	}
	//cout << endl;
	for(int i = 0; i < q; i++){
		cin >> l >> r;
		result = 0;
		result = io[r-1] - io[l-1];
		cout << result << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#define ios ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int maxn=1e5+100;
int a[maxn];
int main()
{
	ios;
	int N,K,Q;
	cin>>N>>K>>Q;
	while(Q--){
		int t; cin>>t;
		if(t==1){
			a[2]--;
		}
		else if(t==N){
			a[1]--;
			a[N]++;
		}
		else {
			a[1]--; a[t]++;
			a[t+1]--;
		}
	}
	for(int i=1;i<=N;i++){
		a[i]+=a[i-1];
		if(a[i]+K<=0) puts("No");
		else puts("Yes");
	}
	return 0;
}

Measured memory_bytes: 1024