akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e18
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  vector<ll> d = divisor(c);
  int ans = 0;
  for (int i = 0; i < d.size();i++){
    //cout << d[i] << endl;
    if (a <= d[i] && d[i] <= b)
      ans++;
  }

  cout << ans << endl;
  return 0;
}



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

using namespace std;

int main(void) {
    long A, B;
    cin >> A >> B;
    if (A == B || abs(A + B) % 2 == 0){
        if(A==B)cout<<0<<endl;
        else if((A+B)%2==0 && (A-(A+B)/2))
        cout << (abs(A + B) / 2) << endl;
    }
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include <cassert>
#include<cmath>
using namespace std;
int main() {
	int i, j;
	int flag = 0;
	char hoji;
	string S, T;
	cin >> S >> T;

	for (i = 0; i < S.size(); ++i) {
		hoji = S.front();//まずは末尾保持
		//cout << "ほじ" << hoji << endl;
		for (j = 0; j < S.size(); ++j) {

			S[j] = S[j + 1];//位置文字ずつ移動
		}
		S.back() = hoji;//保持してた末尾を先頭に移動
		//cout << S << endl;
		if (S == T) {
			++flag;
			break;
		}
	}

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

}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int c[2000], t[2000],N,T,cmax = 10000 ,tmax = 10000;
    scanf("%d %d", &N,&T);
    for(int i =0; i < N; i++){
        scanf("%d %d", &c[i], &t[i]);
    }
    for(int i = 0; i < N; i++){
        if(t[i] <= T && c[i] <= cmax){
            tmax = t[i];
            cmax = c[i];
        }
    }
    if(tmax <=T){
    printf("%d\n", cmax);
    return 0; 
    }
    printf("TLE\n");
    // printf("debug\n");
    // for(int i = 0; i < N; i++){
    //     printf("%d %d\n", c[i], t[i]);

    // }
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

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

    double px = sc.nextDouble();
    double py = sc.nextDouble();
    double qx = sc.nextDouble();
    double qy = sc.nextDouble();

    System.out.println(Math.sqrt(Math.pow(px-qx, 2) + Math.pow(py-qy, 2)));
  }
}


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

int main() {
  int a,b;
  cin >>a >>b;
  if(a%3==0){
    cout <<"Possible" <<endl;
    return 0;
  }
  if(b%3==0){
    cout <<"Possible" <<endl;
    return 0;
  }
  if((a+b)%3==0){
    cout <<"Possible" <<endl;
    return 0;
  }
  cout <<"Impossible" <<endl;
  return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> like(m);
    for (int i = 0; i < n; i++)
    {
        int k, ki;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> ki;
            like.at(ki - 1)++;
        }
    }
    int out = 0;
    for (int i = 0; i < m; i++)
        if (like.at(i) == n)
            out++;
    cout << out << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdint>
using namespace std;
 
const int MOD = 1000000007;
int main() {
	int N, M;
	int64_t paturn = 1;
	cin >> N >> M;
	if (N >= M + 2 || N <= M - 2) cout << 0;
	else {
		for (int i = 1;i <= N;i ++) {
			paturn = (paturn * i) % MOD;
		}
		for (int i = 1;i <= M;i ++) {
			paturn = (paturn * i) % MOD;
		}
		if ((N + M) % 2 == 0) paturn = (paturn * 2) % MOD;
		cout << paturn;
	}
	return 0;
}
// 犬同士、及び猿同士が隣合わない→犬猿を(N+M)/2個並べ、左端に猿を置くか右端に犬を置く
// 次に、(N+M)%2==0なら左右反転版があるので、最終結果を2倍する
// この時、犬がN!通り、猿がM!通りの並べ方があるので、N!M!通りあるね

Measured memory_bytes: 256
from itertools import combinations
S = input()
zenbu = list(range(len(S)+1))
soto = (zenbu[0], zenbu[-1])
naka = zenbu[1:-1]
kumi = []
for i in range(len(naka)+1):
    comb = list(combinations(naka, i))
    for c in comb:
        kumi.append(sorted(c + soto))

total_list = []
for k in kumi:
    total_list.append(sum([int(S[k[i]:k[i+1]]) for i in range(len(k)-1)]))
print(sum(total_list))

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

int main()
{
    int a, b;
    cin >> a >> b;
    string s1, s2;
    int i=a;
    while(i>0)
    {
        s1.push_back(b + '0');
        i--;
    }
    i=b;
    while(i>0)
    {
        s2.push_back(a + '0');
        i--;
    }
    cout << min(s1, s2) << endl;
}

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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    bool bo = 1;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        if( !(a&1)  && !(a%3 == 0 || a%5 == 0)){
            bo = 0;
        }
    }
    if(!bo)
        cout << "DENIED" << endl;
    else
        cout << "APPROVED" << endl;




}
// APPROVED
// DENIED


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>

int main()
{
	int n;
	while( std::cin >> n, n )
	{
		int id, d = 0;

		for( int i = 0; i != n; ++i )
		{
			int p, d1, d2;
			std::cin >> p >> d1 >> d2;
		
			if( d1 + d2 > d )
			{
				d = d1 + d2;
				id = p;
			}
		}

		std::cout << id << ' ' << d << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include<cstdio>
using namespace std;

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

  int a; 
  string s;
  
  cin >> a; 
  cin >> s;
  
  if (a >= 3200) {
    cout << s;
  } else {
    cout << "red";
  }
}

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

int main()
{
	int n, a[3];
	cin >> n;
	for (int i=0; i<n; ++i) {
		for (int j=0; j<3; ++j) {
			cin >> a[j];
		}
		sort(a, a+3);
		cout << (a[2]*a[2] == a[0]*a[0] + a[1]*a[1] ? "YES" : "NO") << '\n';
	}
}

Measured memory_bytes: 3028
using System;
class Program
{
    static void Main(string[] args)
    {
        string s = Console.ReadLine();

        for (int i = 0; i < s.Length; i++)
        {
            if ((i + 1) % 2 == 1)
            {
               if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D')
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            else
            {
                if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D')
                {
                    Console.WriteLine("No");
                    return;
                }
            }

        }
        Console.WriteLine("Yes");
    }

}

Measured memory_bytes: 13140
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
Believe in yourself ,( try and try and then try ), You can do it
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, Mod = 1e9 + 7;
using namespace std;
typedef long long ll;
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int n;
vector<ll>arr;
ll dp[405][405];
ll sol(int l,int r){
	if (l == r)
		return 0;
	ll &ret = dp[l][r];
	if (~ret)
		return ret;
	ret = OO;
	for (int i = l; i <= r; i++){
		ret = min(ret, sol(l, i) + sol(i + 1, r) + (arr[r] - arr[l - 1]));
	}
	return ret;
}
int main(){
	K_K();
	cin >> n;
	arr.resize(n + 1, 0);
	clr(dp, -1);
	for (int i = 1; i <= n; i++){
		cin >> arr[i];
		arr[i] += arr[i - 1];
	}
	cout << sol(1, n);
}

Measured memory_bytes: 4968
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, M);
    i64 D = 0;
    i64 S = 0;
    rep(i, 0, M) {
        var(i64, d, c);
        D += c;
        S += d * c;
    }

    print((D - 1) + (S - 1) / 9);

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<vector<Int> > G(n);
  for(Int i=1;i<n;i++){
    Int a,b;
    cin>>a>>b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  Int r=-1,deg=0;
  for(Int i=0;i<n;i++)
    if((Int)G[i].size()>deg)
      r=i,deg=G[i].size();

  if(deg<=2){
    cout<<1<<endl;
    return 0;
  }

  function<Int(Int, Int)> dfs=[&](Int v,Int p)->Int{
    Int res=0,z=0;
    for(Int u:G[v]){
      if(u==p) continue;
      Int x=dfs(u,v);
      if(x==0){
	if(z) x=1;
	else z=1;
      }
      res+=x;
    }
    return res;
  };
  cout<<dfs(r,-1)<<endl;
  return 0;
}


Measured memory_bytes: 13056
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] A = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }

        int[] B = new int[N+1];
        int x = 0;
        for(int i = 0; i < N; i++){
            B[A[i]]++; 
        }
        Arrays.sort(B);
        for(int i = N; i >= N - K + 1; i--){
            x += B[i];
        }

        System.out.println(N - x);
    }
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl '\n'
#define int long long

const int N = 1e5+5;
int dp[N];

int32_t main()
{
	IOS;

	int n, k; cin >> n >> k;
	int a[n+5];
	memset(dp, 0, sizeof(dp));
	for(int i = 1; i <= n; i ++) 
		cin >> a[i];
	for(int stones = 0; stones <= k; stones ++) {
		for(int j = 1; j <= n; j ++) {
			if(stones - a[j] >= 0 and ! dp[stones - a[j]]) dp[stones] = 1;
		}
	}
	
	if(dp[k]) cout << "First" << endl;
	else cout << "Second" << endl;

	return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
const ll INF = (1ll << 60);

int main() {
  ll N, M, L;
  cin >> N >> M >> L;

  vvi G(N, vi(N, INF));
  for (ll i = 0; i < M; i++) {
    ll a, b, c;
    cin >> a >> b >> c;
    a -= 1;
    b -= 1;
    G[a][b] = G[b][a] = c;
  }

  auto f = [&] {
    for (ll k = 0; k < N; k++) {
      for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
          G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
        }
      }
    }
  };

  f();

  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      if (G[i][j] <= L) {
        G[i][j] = 1;
      } else {
        G[i][j] = INF;
      }
    }
  }

  f();

  ll Q;
  cin >> Q;
  for (ll i = 0; i < Q; i++) {
    ll s, t;
    cin >> s >> t;
    s -= 1;
    t -= 1;
    if (G[s][t] == INF)
      cout << -1 << endl;
    else
      cout << G[s][t] - 1 << endl;
  }
}


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

int main()
{
    string S, T;
    cin >> S >> T;
    int count = 0;
    if(S[0] == T[0])
        count++;
    if(S[1] == T[1])
        count++;
    if(S[2] == T[2])
        count++;
    cout << count << endl;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
int compare(const void *a,const void *b){
    if(*(long long*)a>*(long long *)b){
        return 1;
    }
    return -1;
}

int main()
{   int i,a,b,k,n,m,x,y,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    printf("%d",(a-c)*(b-d));
    
    return 0;
}


Measured memory_bytes: 128
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] d1 = new int[n];
    int[] d2 = new int[n];
    int count = 0;
    for (int i = 0; i < n; i++) {
      d1[i] = sc.nextInt();
      d2[i] = sc.nextInt();
    }
    for (int i = 0; i < n - 2; i++) {
      if (d1[i] == d2[i] && d1[i + 1] == d2[i + 1] && d1[i + 2] == d2[i + 2]) {
        count++;
      }
    }
    if (count > 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << endl;}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}

ll f(ll x, ll A, ll B) {
    return (A*x)/B - A*(x/B);
}

signed main() {
    //my-code
    ll A, B, N; cin >> A >> B >> N;
    ll g = gcd(A, B);

    if (N >= B) {
        print(f(B-1,A,B));
    } else {
        print(f(N,A,B));
    }

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

Measured memory_bytes: 3612
#include <iostream>

int main(){
	int n, m, max;
	char s;

	while(std::cin >> n >> m, n&&m){
		max = n + m, s = 'A';
		for(int i=0;i<4;i++){
			std::cin >> n >> m;
			if(n + m > max)max = n + m, s = 'B' + i;
		}

		std::cout << s << " " << max << '\n';
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; n>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll ans=0, N;
    ll Mod = 1e9+7;
    cin >> N;
    vector<ll> a(N+1);
    rep1(i,N) cin >> a[i];
    vector<ll> p = a;
    for (int i=N; i > 1; --i) {
        p[i-1] += p[i];
        p[i-1] %= Mod;
    }
    for (int i=1; i<=N-1; ++i) {
        ans += a[i]*p[i+1];
        ans %= Mod;
    }
    cout << ans << endl;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// a^b mod M
long myPow(long a,long b,int M) {
    long ret = 1;
    long tmp = a;
    while(b>0) {
        if((b&1)==1) ret = (ret * tmp) % M;
        tmp = (tmp * tmp) % M;
        b = b>>1;
    }
    return ret;
}

 // nCk mod M
int nCk(int n,int k,int M) {
    long ret = 1;
    int mi = min(k, n-k);
    for(int i=1;i<=mi;i++) {
        ret = (ret * myPow(i,M-2,M)) % M;
    }
    for(int i=n-mi+1;i<=n;i++) {
        ret = (ret * i) % M;
    }
    return (int)ret;
};

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}


int main() {
    int M, D;
    cin >> M >> D;

    int ans = 0;
    for(int m = 1; m <= M; m++) for(int d = 1; d <= D; d++) {
        int d1 = d / 10;
        int d2 = d % 10;

        if(d1 < 2 || d2 < 2) continue;

        if (d1 * d2 == m) ans++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

long long a, b;

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

std::vector<long long> getFactors(long long num)
{
	std::vector<long long> factors;
	factors.push_back(1);
	
	if (num % 2 == 0)
	{
		factors.push_back(2);
		while (num % 2 == 0)
			num = num / 2;
	}
	
	long long d = 3;
	while ((d * d) <= num)
	{
//		printf("%d\n", d);
		if (num % d == 0)
		{
			factors.push_back(d);
			while (num % d == 0)
				num = num / d;
		}
		d = d + 2;
	}
	
	if (num > 1)
		factors.push_back(num);
		
	return factors;
}

int main()
{
	scanf("%lld%lld", &a, &b);
	if (a < b)
	{
		long long temp = a;
		a = b;
		b = temp;
	}
	
	long long g;
	g = gcd(a, b);
	
	std::vector<long long> factors;
	factors = getFactors(g);
	printf("%d\n", factors.size());
	
	return 0;
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, ans=0;
	cin >>n;
	VI h(n);
	rep(i, n) cin >>h[i];
	bool ok=true;
	h[0]--;
	rep2(i, 1, n){
		if(h[i-1]  < h[i] ) h[i]--;
	}
	rep2(i, 1, n){
		if(h[i-1] > h[i]) ok=false;
	}
	cout <<(ok?"Yes":"No") <<"\n";
	return 0;
}


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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

vector<ll> fact, fact_inv;

template <typename T> T mpow(T x, T n) {
    T ret = 1;
    while(n > 0) {
        if(n & 1) (ret *= x) %= mod;
        (x *= x) %= mod;
        n = n >> 1;
    }
    return ret;
}

void COMinit(ll MAX) {
    fact.resize(MAX + 1);
    fact_inv.resize(MAX + 1);
    fact[0] = fact_inv[0] = 1;
    rep(i, MAX) {
        fact[i + 1] = fact[i] * (i + 1) % mod;
        fact_inv[i + 1] = mpow(fact[i + 1], mod - 2);
    }
}

ll COM(ll n, ll k) {
    if(n < k || k < 0) return 0;
    return (fact[n] * fact_inv[k] % mod) * fact_inv[n - k] % mod;
}

template <int M> class ModInt {
    int x;

  public:
    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % M : (M - (-y) % M) % M) {}
    ModInt &operator+=(const ModInt &p) {
        if((x += p.x) >= M) x -= M;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if((x += M - p.x) >= M) x -= M;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = M, u = 1, v = 0, t;
        while(b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while(n > 0) {
            if(n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt(t);
        return (is);
    }
};

using modint = ModInt<mod>;

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

    ll n, a, b;
    cin >> n >> a >> b;

    modint ans(mpow(2ll, n)), x(1), y(1);

    rep(i, a) {
        x *= modint(n - i);
        x /= modint(a - i);
    }
    rep(i, b) {
        y *= modint(n - i);
        y /= modint(b - i);
    }
    cout << ans - x - y - modint(1) << endl;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for i in range(N)]
ans = [0] * 4
for i in range(N):
  if S[i] == "AC":
    ans[0] += 1
  elif S[i] == "WA":
    ans[1] += 1
  elif S[i] == "TLE":
    ans[2] += 1
  elif S[i] == "RE":
    ans[3] += 1    
print("AC x " + str(ans[0]))    
print("WA x " + str(ans[1])) 
print("TLE x " + str(ans[2]))  
print("RE x " + str(ans[3])) 

Measured memory_bytes: 16188
#include <cstdio>
#include <cstring>
using namespace std;

const int MAX_N = 10;
const double B_TO_J = 380000.0;
double x[MAX_N];
char u[MAX_N][4];
int N;


int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lf %s", &x[i], u[i]);
	}
	double ans = 0.0;
	for (int i = 0; i < N; i++) {
		if (strcmp(u[i], "BTC") == 0) {
			ans += B_TO_J * x[i];
		}
		else {
			ans += x[i];
		}
	}

	printf("%lf\n", ans);

	return 0;
}

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

int N;

void solve(){
  bool prime=true;
  for(ll i=2;i*i<=N;i++){
    if(N%i==0){
      prime=false;
      break;
    }
  }
  if(prime){
    cout<<0<<endl;
    return;
  }

  int ans=2;
  for(int k=N-1;k>1;k--){
    bool prime=true;
    for(ll i=2;i*i<=k;i++){
      if(k%i==0){
        prime=false;
        break;
      }
    }
    if(prime) break;
    ans++;
  }
  for(int k=N+1;;k++){
    bool prime=true;
    for(ll i=2;i*i<=k;i++){
      if(k%i==0){
        prime=false;
        break;
      }
    }
    if(prime) break;
    ans++;
  }

  cout<<ans<<endl;
}

int main(){
  while(1){
    cin>>N;
    if(N==0) break;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int h,w;
string fie[11];
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
map<string,int> cnt;
bool used[11][21];
vector<string> index2;

void dfs(int y,int x,int k,string str){
	if(used[y][x])return;
	used[y][x]=true;
	str+=fie[y][x];
	cnt[str]++;
	index2.push_back(str);
	dfs((y+dy[k]+h)%h,(x+dx[k]+w)%w,k,str);
}

int main(void){
	while(1){
		scanf("%d %d",&h,&w);
		if(h+w==0)break;
		cnt.clear();
		index2.clear();
		for(int i=0;i<h;i++){
			cin >> fie[i];
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				for(int k=0;k<8;k++){
					memset(used,false,sizeof(used));
					dfs(i,j,k,"");
				}
			}
		}
		sort(index2.begin(),index2.end());
		index2.erase(unique(index2.begin(),index2.end()),index2.end());
		string res="0";
		for(int i=0;i<index2.size();i++){
			if(cnt[index2[i]]>=2 && index2[i].size()>=2){
				if(res.size()<index2[i].size() || (res.size()==index2[i].size() && index2[i]<res)){
					res=index2[i];
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 37712
/*
Author: Hrujul Thumar
*/
#include <bits/stdc++.h>
#define int         long long
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define whilet()    int t; scanf("%d",&t); while(t--)
#define vp          vector<pair<int,int>,int>
#define pb          push_back
#define mii         map<int,int>
#define pii         pair<int,int>
#define msi         map<string,int>
#define psi         pair<string,int>
#define mpi         map<pair<int,int>,int>
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define ef          else if
#define MOD         1000000007
#define endl        '\n'
#define fastio       ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define pi          3.141592653589793238
const long long MAX_SIZE = 1000000000;
using namespace std;

signed main()
{
    fastio
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    int cnt=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            if(a[i]!=a[j])
            {for(int k=j+1;k<n;k++)
            {
                if(a[k]!=a[j])
                {
                    if(a[i]+a[j]>a[k])cnt++;
                    else break;
                }
            }}
        }
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3656
N=int(input())
A=[int(i) for i in input().split()]
L=[[A[0]]]
k=0
for i in range(1,N):
    if A[i-1]==A[i]:
        L[k].append(A[i])
    else:
        L.append([])
        k+=1
        L[k].append(A[i])
ans=0
for p in L:
    ans+=len(p)//2
print(ans)


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

void solve() {
  int n;
  cin >> n;
  cout << pow(n,2) << endl;
}

int main() {
  solve();
  return 0;
}



Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(i) i.begin(),i.end()
template<typename T=ll> using v =vector<T>;
template<typename T=ll> using vv = vector<v<T>>;
template<typename T=ll,typename U=ll> using p = pair<T,U>;
const ll INF = (ll)1e9;
template<typename T> T chmin(T &a,T b){a=min(a,b);}
template<typename T> T chmax(T &a,T b){a=max(a,b);}

int main(){
    ll n; cin >> n;
    auto a = v<>(n,0);
    rep(i,n) cin >> a[i];
    ll up=0;
    ll dn=0;
    ll ans=1;
    rep(i,n-1){
        if(a[i]<a[i+1]) up++;
        if(a[i]>a[i+1]) dn++;
        if(up&&dn){
            up=0;
            dn=0;
            ans++;
        }
    }

    cout << ans << endl;
}

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


int main(){
  string str1,str2;
  cin>>str1>>str2;
  bool a=true;
  for(int i=0;i<3;i++){
    if(str1[i]!=str2[2-i]){
      a=false;
      break;
    }
  }
  string ans="NO";
       if(a)ans="YES";
  cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 256
a = input()
i = 0
v = 0
for i in range(int(a)):
    if ((int(i)+1) % 3) == 0:
        print(' {}'.format(int(i)+1),end='')
    elif((int(i)+1) % 10) == 3:
        print(' {}'.format(int(i)+1),end='')
    else:
        x = int(i) + 1
        while v == 0:
            
            x = int(x) // 10
            if (int(x) > 10) and (not(int(x) % 10) == 3):
                pass
            elif (int(x) % 10) == 3:
                print(' {}'.format(int(i)+1),end='')
                v = 1
            else:
                v = 1
    v = 0
    
print('')


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    string s = to_string(n);
    bool flag = false;
    for (int i = 0; i < 3; ++i) {
        if(s[i] == '7') flag = true;
     }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B, H, M;
    ld cord1[2], cord2[2];
    ld temp1, temp2;
    ld unit;
    cin >> A >> B >> H >> M;
    unit = 2.0 * M_PI / 12.0L / 60.0L;
    cord1[0] = A * cos(2.0 * M_PI * H / 12.0L + unit * M);
    cord1[1] = A * sin(2.0 * M_PI * H / 12.0L + unit * M);
    cord2[0] = B * cos(2.0 * M_PI * M / 60.0L);
    cord2[1] = B * sin(2.0 * M_PI * M / 60.0L);
    temp1 = cord1[0] - cord2[0];
    temp2 = cord1[1] - cord2[1];
    cout << fixed << setprecision(9) << sqrt(temp1 * temp1 + temp2 * temp2) << endl;
    return 0;
}


Measured memory_bytes: 4160
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define endl '\n'
using namespace std;
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll parent[100005];
ll find(ll a)
{
    std::vector<ll> v;
    while(parent[a]>0)
    {
        v.push_back(a);
        a = parent[a];
    }
    for(ll i=0;i<v.size();i++)
        parent[v[i]] = a;
    return a;
}
bool prime[100005];
void SieveOfEratosthenes(int n) 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}  
void union1(ll a, ll b)
{
    a = find(a);
    b = find(b);
    if(a!=b)
    {
        parent[a] = min(parent[a],parent[b]);
        parent[b] = a;
    }
}  
ll n,w;
std::vector<ll> weight(100005),value(100005);
ll dp[102][100005];
ll solve(ll i,ll w)
{
    if(i==n||w<=0)
        return 0;
    if(dp[i][w]!=-1)
        return dp[i][w];
    ll a = 0;
    if(weight[i]<=w)
        a = value[i]+solve(i+1,w-weight[i]);
    ll b = solve(i+1,w);
    return dp[i][w] = max(a,b);
}
int main()
{
    memset(dp,-1,sizeof(dp));
    //fastio();
    cin >> n >> w;
    for(ll i=0;i<n;i++)
    {
        cin >> weight[i] >> value[i];
    }
    cout << solve(0,w) << endl;
}

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

int main() {
  string s;
  cin >> s;
  vector<char> ans;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '0') {
      ans.push_back(s.at(i));
    } else if (s.at(i) == '1') {
      ans.push_back(s.at(i));
    } else {
      if (ans.size() != 0) {
        ans.pop_back();
      }
    }
  }
  for (int i = 0; i < ans.size(); i++) {
    cout << ans.at(i);
  }
  return 0;
}

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

using namespace std;

int h,w;
int f[202][202];
int a[202][202];

void init(int y,int x){
    if(f[y][x]) return;
}

void solve(){
    int i,j,k;
    string str;
    cin >> h >> w;
    for(i = 0;i < h;i++){
        cin >> str;
        for(j = 0;j < w;j++){
            if(str[j] == '#') f[i+1][j+1] = 1;
            else f[i+1][j+1] = 0;
        }
    }
    memset(a,-1,sizeof(a));
    a[0][1] = 0;
    for(int c = 0;a[h][w] == -1;c++){
        k = c%2;
        for(i = 1;i <= h;i++){
            for(j = 1;j <= w;j++){
                if(a[i][j] == -1 && f[i][j] == k && (a[i][j-1] > -1 || a[i-1][j] > -1)){
                    a[i][j] = c;
                }
            }
        }
    }
    cout << (a[h][w]+1)/2 << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 512
// Practice AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(usize));
    }
    
    let n = get!();
    let m = get!();
    let mut graph = vec![vec![]; n];
    for _ in 0 .. m {
        let u = get!() - 1;
        let v = get!() - 1;
        graph[u].push(v);
    }
    let s = get!() - 1;
    let t = get!() - 1;
    let mut vis = vec![vec![0; n]; 3];
    let mut tmp = vec![];
    tmp.push(s);
    let mut cnt = 1;
    let mut next = 0;
    while tmp.len() > 0 {
        let mut tmp2 = vec![];
        for &u in tmp.iter() {
            for &v in graph[u].iter() {
                if vis[next][v] > 0 {
                    continue;
                }
                vis[next][v] = cnt;
                tmp2.push(v);
            }
        }
        next += 1;
        if next > 2 {
            next = 0;
            cnt += 1;
        }
        tmp = tmp2;
    }
    if vis[2][t] == 0 {
        println!("-1");
    } else {
        println!("{}", vis[2][t]);
    }
}

Measured memory_bytes: 14588
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

# 大きい数字から追加していく。そのときの連結成分の大きさだけ足される。
# union findっぽく。各成分の左端を根として持つ

N = int(input())
A = [int(x) for x in input().split()]

x_to_i = {x:i for i,x in enumerate(A)}

V = set()
root = dict()
size = dict()

def find_root(x):
    y = root[x]
    if x == y:
        return y
    ry = find_root(y)
    root[x] = ry
    return ry

def merge(x,y):
    rx = find_root(x)
    ry = find_root(y)
    sx = size[rx]
    sy = size[ry]
    if sx > sy:
        rx,ry = ry,rx
        sx,sy = sy,sx
    root[rx] = ry
    size[ry] += sx

answer = 0
for x in range(N,0,-1):
    i = x_to_i[x]
    V.add(i)
    size[i] = 1
    root[i] = i
    left = 0
    right = 0
    if i-1 in V:
        left = size[find_root(i-1)]
        merge(i-1,i)
    if i+1 in V:
        right = size[find_root(i+1)]
        merge(i+1,i)
    cnt = (left+1) * (right+1)
    answer += x * cnt

print(answer)

Measured memory_bytes: 73072
H,W = map(int,input().split())
cost = [[0 for x in range(10)] for y in range(10)]
for i in range(10):
  tmp = input().split()
  for j in range(10):
  	cost[i][j] = int(tmp[j])
flg = False    
number = [0]*10
for k in range(H):
  tmp = input().split()
  for l in range(W):
    if int(tmp[l]) > -1:
      number[int(tmp[l])] +=1
      flg = True

def wf():
  for k in range(10):
    for i in range(10):
      for j in range(10):
        cost[i][j] = min(cost[i][j],cost[i][k]+cost[k][j])
if flg:
	wf()
sum = 0
for z in range(10):
	sum += number[z]*cost[z][1]
print(sum)    

Measured memory_bytes: 3064
#include <iostream>
#include <bitset>
#include <vector>
#include <array>
#include <cmath>
#include <string>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {

  int N, M; std::cin >> N >> M;

  std::vector<std::vector<int>> denkyu(M);

  for(int i=0; i<M; i++){
    int k; std::cin >> k;
    for(int j=0; j<k; j++){
      int s; std::cin >> s;
      denkyu[i].push_back(s-1);
    }
  }

  std::vector<int> cond(M);
  for(int i=0; i<M; i++) std::cin >> cond[i];

  int ans = 0;
  for(int i=0; i<(1LL<<(N)); i++){
    bool flag = true;
    for(int j=0; j<M; j++){
      int num_s = 0;
      for(int k=0; k<denkyu[j].size(); k++) if ( ((1LL<<denkyu[j][k]) & i) != 0 ) num_s++;
      if ( num_s % 2 != cond[j] ) flag = false;
      if ( !flag ) break;
    }
    if ( flag ) ans++;
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
from math import gcd

k = int(input())

cnt = [0 for _ in range(k + 1)]

for i in range(1, k + 1):
    for j in range(1, k + 1):
        cnt[gcd(i, j)] += 1
ans = [0 for _ in range(k + 1)]
for i in range(1, k + 1):
    for j in range(1, k + 1):
        d = gcd(i, j)
        ans[d] += d * cnt[i]
print(sum(ans))

Measured memory_bytes: 65140
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>

using namespace std;


int main(){

    int N,K;
    cin >> N >> K;
    int h[100010];
    int ans=0;
    for(int i=0;i<N;i++){
        cin >> h[i];
        if(h[i]>=K) ans++;
    }
    cout <<ans<<endl;
}


Measured memory_bytes: 640
import itertools

n, m, r = map(int, input().split())
rlist = list(map(int, input().split()))
dist = [[-1 for _ in range(n)] for _ in range(n)]
for i in range(n):
  dist[i][i] = 0
abcl = []
for _ in range(m):
  a, b, c = map(int, input().split())
  dist[a-1][b-1] = c
  dist[b-1][a-1] = c

for k in range(0, n):
  for i in range(0, n):
    for j in range(0, n):
      if dist[i][k] != -1 and dist[k][j] != -1:
        if dist[i][j] == -1:
          dist[i][j] = dist[i][k] + dist[k][j]
        elif dist[i][j] > dist[i][k] + dist[k][j]:
          dist[i][j] = dist[i][k] + dist[k][j]

ans = pow(10, 15)
minp = None
for rperm in itertools.permutations(rlist):
  tmp = 0
  tmpp = [rperm[0]-1]
  for pr, nr in zip(rperm, rperm[1:]):
    tmp += dist[pr-1][nr-1]
    tmpp.append(nr-1)
  if ans > tmp:
    ans = tmp
    minp = tmpp
print(ans)


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

const int MAX = 2e5+10;

int N;
vii lr;

ll solve() {
    ll mx = 0, mn = 1e10;
    ll ans = 0;
    FORE (x, lr) {
        CHMAX(mx, x.first);  // 最も右にある左端, X
        CHMIN(mn, x.second); // 最も左にある右端, Y
        CHMAX(ans, x.second - x.first); // 最長の区間
    }
    ans += max(0ll, mn - mx); // 最長以外を反対にした場合

    vii t;
    FORE (x, lr) {
        ll a = max(0ll, x.second - mx); // Xと同じグループにした時の範囲
        ll b = max(0ll, mn - x.first);  // Yと同じグループにした時の範囲
        t.push_back(make_pair(a, -b));
    }
    sort(ALL(t));
    REP (i, N) t[i].second *= -1;
    ll w = t[0].second;
    FOR (i, 1, N) {
        CHMAX(ans, w + t[i].first);
        CHMIN(w, t[i].second);
    }

    return ans;
}

int main() {
    cin >> N;
    REP (i, N) {
        int l, r;
        cin >> l >> r;
        lr.push_back(make_pair(l, r+1));
    }
    cout << solve() << endl;
}

Measured memory_bytes: 4848
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
using namespace std;

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

int main()
{
    int N, ans = 0;
    cin >> N;
    vector<vector<int>> dp(N, vector<int>(3)), a(N, vector<int>(3));
    // A = 0, B = 1, C = 2
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            cin >> a.at(i).at(j);
            dp.at(i).at(j) = 0;
        }
    }
    for(int i = 0; i < 3; i++)
    {
        chmax(dp.at(0).at(i), a.at(0).at(i));
    }
    for(int i = 1; i < N; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            for(int k = 0; k < 3; k++)
            {
                if(j == k) continue;
                else chmax(dp.at(i).at(k), dp.at(i - 1).at(j) + a.at(i).at(k));
            }
        }
    }
    for(int j = 0; j < 3; j++) chmax(ans, dp.at(N - 1).at(j));
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 11136
n = -1
x = -1
while n != 0 || x != 0
n,x = gets.split.map(&:to_i)
ans = 0
  if  n == 0 && x == 0
  elsif
    for a in 1..n do
      for b in 1..n do
        for c in 1..n do
          if a + b + c == x && a != b && b != c && c != a
            ans += 1
          end
        end
      end    
    end
    p ans/6
  end  
end


Measured memory_bytes: 8872
package main

import (
	"fmt"
)

func main() {
	var n, q int
	var s string
	fmt.Scan(&n, &q, &s)

	a := make([]int, n+1)
	for i := 1; i < n; i++ {
		x := 0
		if s[i-1] == 'A' && s[i] == 'C' {
			x = 1
		}
		a[i+1] = a[i] + x
	}

	var l, r int
	for i := 0; i < q; i++ {
		fmt.Scan(&l, &r)
		fmt.Println(a[r] - a[l])
	}
}

Measured memory_bytes: 6016
#include <stdio.h>
#include <math.h>

int min(int,int);
int abs(int);
int main()
{
	int N;
	scanf("%d",&N);
	int h[N];
	int cost[N];
	
	for(int i=0;i<N;++i)
	{
		scanf("%d",&h[i]);
	}
		cost[1]=abs(h[1]-h[0]);
		cost[0]=0;	
		
		for(int i=2;i<N;i++)
		{
			cost[i]=min(cost[i-1]+abs(h[i]-h[i-1]),cost[i-2]+abs(h[i]-h[i-2]));
		}	
	printf("%d\n",cost[N-1]);
}
int min(int a,int b)
{
	if(a>b)
	{
		return b;
	}
	else 
	{
		return a;
	}
}

int abs(int a)
{
	if(a<0)
	{
		return -a;
	}	
	else 
	{
		return a;
	}
}			


Measured memory_bytes: 896
import java.util.Scanner;

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

        if (n % 2 == 0) {
            System.out.println(n);
        } else {
            System.out.println(n*2);
        }
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<string>
#include <iostream>

using namespace std;

int main() {
	int a,b;
	string s;
	cin >> a >> b >> s;
	for(int i=0;i<a;i++){
	if(s[i]>='0' && s[i]<='9'){
		i++;
	}
	else{
		cout << "No" << endl;
		return 0;
	}
  }
	if(s[a] == '-'){
		for(int j=a+1;j<a+b;j++){
		if(s[j]>='0'&& s[j]<='9'){
			j++;
		}
		else{
			cout << "No" << endl;
			return 0;
		}
	  }
		cout << "Yes" << endl;
		return 0;
	}
	else{
		cout << "No" << endl;
		return 0;
	}

}


Measured memory_bytes: 256