akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

fn main() {
    input!{
        N: usize,
        Q: usize,
        S: chars,
        lr: [(usize1, usize1); Q],
    }
    let mut cnts = vec![0; S.len()];
    for i in 1..S.len() {
        cnts[i] = cnts[i-1] + match (S[i-1], S[i]) {
            ('A', 'C') => 1,
            _ => 0,
        };
    }
    for &(l, r) in lr.iter() {
        println!("{}", cnts[r] - cnts[l]);
    }

}



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

void Main() {
  int n;
  std::cin >> n;
  int d[n];
  for (int i = 0; i < n; i++) {
    std::cin >> d[i];
  }

  long int r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      r += d[i] * d[j];
    }
  }

  std::cout << r << std::endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <map>
using namespace std;
#define ll  long long int
 
int main() {
	//freopen("test.txt", "r", stdin);
	int a,b,c; cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
	return 0;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf=1e9;
const int64_t inf64=1e18;
const double eps=1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

using i64=int64_t;

void solve(){
    int N;
    cin >> N;
    vector<set<int>> graph(N);
    vector<int> deg(N);
    rep(i,0,N-1){
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        graph[a].insert(b);
        graph[b].insert(a);
    }
    queue<int> que;
    rep(i,0,N) if(graph[i].size()==1) que.push(i);
    vector<bool> done(N);
    while(!que.empty()){
        int u=que.front();
        que.pop();
        if(done[u]) continue;
        done[u]=true;
        if(graph[u].empty()){
            cout << "First" << endl;
            return;
        }
        int v=*graph[u].begin();
        done[v]=true;
        graph[u].erase(v);
        graph[v].erase(u);
        for(int w:graph[v]){
            graph[w].erase(v);
            if(graph[w].size()==1) que.push(w);
        }
    }
    cout << "Second" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(10);
    solve();
    return 0;
}


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

int main() {
    int a = 0, b = 0, ans;
    string str;
    cin >> str;
    rep(i, str.length()) {
        if(str.at(i) == '0') {
            if(i % 2) a++;
            else b++;
        } else {
            if(i % 2) b++;
            else a++;
        }
    }
    ans = min(a, b);
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
	int x,a,b;
	scanf("%d%d%d",&x,&a,&b);
	if(b<=a)
		printf("delicious\n");
	else if((x+a)>=b)
		printf("safe\n");
	else if((x+a)<=b)
		printf("dangerous\n");
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;

	static int MAX = 10000000;
	static	ArrayList<TreeNode> tree;
	static HashSet<Integer> set;
	static long ans;

	static HashSet<Integer> memo;
	static HashMap<Integer, TreeNode> map;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		String ss = sc.next();
		int ans = 0;
		for(int i = 0;i < ss.length()/2;i++){
			if(ss.charAt(i) != ss.charAt(ss.length()-1-i)){
				ans++;
			}
		}
		System.out.println(ans);



	}
















static long fac[] = new long[MAX];
static long finv[] = new long[MAX];
static long inv[] = new long[MAX];



//テーブルの作成
static void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
static	long COM(int n, int k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}








static int upperbond(int k,ArrayList<Integer> data){		//k以下で最大の値をdataの中から探し、返す二分探索
	if(data == null){
		return -1;
	}
	int max = data.size();
	int min = -1;
	while(max-min > 1){
		int mid = (max+min)/2;
		if(data.get(mid) <= k){
			min = mid;
		}else{
			max = mid;
		}
	}


	//		if(min != -1){
	//			min = data.get(min);
	//		}

	//		System.out.println(max);
	return min;					//indexを返している
}

static int lowerbond(int k,ArrayList<Integer> data){		//k以上で最小の値をdataの中から探し、返す二分探索
	if(data == null){
		return -1;
	}
	//		System.out.println("lo");
	//		System.out.println("lo");
	int max = data.size();
	int min = -1;

	while(max-min > 1){
		int mid = (max+min)/2;
		if(data.get(mid) >= k){
			max = mid;
		}else{
			min = mid;
		}
	}

	return max;			//indexを返している
}



static int gcd(int a,int b){				//最大公約数を返す
	if(b == 0){
		return a;
	}else{
		return gcd(b, a%b);
	}
}
static long gcd(long a,long b){
	if(b == 0){
		return a;
	}else{
		return gcd(b, a%b);
	}
}



static long lcm (long a, long b) {
	long g = gcd(a,b);
	return a/g*b;
}
}



class TreeNode{
	int value;
	ArrayList<TreeNode> children;
	boolean root;
	boolean fchild;

	public TreeNode(int value,ArrayList<TreeNode> children,boolean root) {
		this.value = value;
		this.children = children;
		this.root = root;
	}


}

class Pair implements Comparable{
	int from;
	int end;
	public Pair(int from,int end) {
		this.from = from;
		this.end = end;
		// TODO 自動生成されたコンストラクター・スタブ
	}

	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return  from - otherpair.from;
	}








}






Measured memory_bytes: 258388
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define INF INT_MAX/2

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef string Node;
typedef pair<Node, int> pni;

struct Comp {
	bool operator() (pni a, pni b) {
		return a.second > b.second;
	}
};

string rot(string a, int from, int to, int n)
{
	rep(i, from, to + 1)
	{
		int j = a[i] - '0';
		j = (j + n + 10) % 10;
		a[i] = '0' + j;
	}

	return a;
}

int solve(int k)
{
	string start, end;
	cin >> start >> end;

	priority_queue<pni, vector<pni>, Comp> que;
	map<Node, int> dist;
	set<Node> done;

	que.push(pni(start, 0));
	while (!que.empty())
	{
		Node n = que.top().first;
		int c = que.top().second;
		que.pop();

		if (done.find(n) != done.end()) continue;
		done.insert(n);

		if (n == end) return c;

		int from = 0;
		while (n[from] == end[from]) from++;
		int delta = (end[from] - '0') - (n[from] - '0');
		rep(to, from, k)
		{
			Node nnode = rot(n, from, to, delta);
			int nc = c + 1;
			if (dist.find(nnode) == dist.end()) dist[nnode] = INF;
			if (nc < dist[nnode])
			{
				dist[nnode] = nc;
				que.push(pni(nnode, nc));
			}
		}
	}
}

int main()
{
	while (1)
	{
		int k; cin >> k;
		if (k == 0) return 0;
		cout << solve(k) << endl;
	}
}

Measured memory_bytes: 4772
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  int N, K; cin >> N >> K;
  vector<int> V(N); REP(i, N) cin >> V[i];

  ll ans = 0;
  for (int i = 0; i <= K; ++i) {
    for (int j = 0;  j <= K-i; ++j) {
      if (i+j > N) continue;

      vector<int> vv;
      for (int l = 0; l < i; ++l) {
        vv.push_back(V[l]);
      }

      for (int l = 0; l < j; ++l) {
        vv.push_back(V[N-1-l]);
      }

      // K-i-j 取り除ける
      sort(ALL(vv));
      ll sum = accumulate(ALL(vv), 0LL);

      for (int l = 0; l < K-i-j; ++l) {
        if (l >= vv.size()) break;
        if (vv[l] >= 0) break;
        sum -= vv[l];
      }

      ans = max(ans, sum);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "3 3 3" ].parse.expand.solve == 9 );
	assert( [ "2 2 4" ].parse.expand.solve == 0 );
	assert( [ "5 3 5" ].parse.expand.solve == 15 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	auto ans = long.max;
	ans = min( ans, ( a * b * ( c * 0.5 ).ceil.to!long ) - ( a * b * ( c * 0.5 ).floor.to!long ) );
	ans = min( ans, ( a * c * ( b * 0.5 ).ceil.to!long ) - ( a * c * ( b * 0.5 ).floor.to!long ) );
	ans = min( ans, ( b * c * ( a * 0.5 ).ceil.to!long ) - ( b * c * ( a * 0.5 ).floor.to!long ) );
	return ans;
}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
#define int long long
using ll = long long;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b+a); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#pragma endregion

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

  int n,m;
  cin >> n >> m;

  int sum = 0;
  rep(i,m) {
    int a;
    cin >> a;
    sum += a;
  }

  cout << max(-1ll, n-sum) << endl;

  return 0;
}


Measured memory_bytes: 3640
def solve():
    n, k = map(int, input().split())
    s = []
    for i in range(n):
        s.append(int(input()))
    s.sort()
    res = 10 ** 10
    for i in range(n + 1 - k):
        tmp = s[i + k - 1] - s[i]
        res = min(res, tmp)
    print(res)

solve()

Measured memory_bytes: 13300
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back             
#define se second                
#define fi first  
#define be begin()
#define en end()
#define all(v) v.be, v.en
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
template<typename... T> void po(T... args) { ((cout << args << " "), ...); cout<<""; }

 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
     int test=1;
     //cin>>test;
     for(int tt=1; tt<=test; tt++){
       string s,t;
       cin>>s;
       cin>>t;
       ll n=s.size(),ans=0;
       for(ll i=0; i<n; i++){
           if(s[i]!=t[i])ans++;
       }
       pp(ans);
     //cout<<"Case #"<<tt<<": ";  
     }
 
    return 0;
}

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

typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;

typedef long long ll;

#define F first
#define S second

#define ERR 1e-9

#if !ONLINE_JUDGE && !EVAL
    #define dbg_var(x) cerr << #x << ": " << x << "\n";
    #define dbg_iter(x, y) cerr  << #x << ": " << print_iterable(x, y) << "\n";
#else
    #define dbg_var(x)
    #define dbg_iter(x, y)
#endif // ONLINE_JUDGE

template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
    bool first = true;
    stringstream res;
    res << "[ ";
    for(; begin_iter != end_iter; ++begin_iter){
        if(!first) res << ", ";
        first = false;
        res << *begin_iter;
    }
    res << " ]";
    return res.str();
}

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

// constraints
#define MAXN 1000000

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);

    string s;
    cin >> s;

    /*int anno = stoi(s.substr(0,4)), mese = stoi(s.substr(5, 2)), giorno = stoi(s.substr(8, 2));

    if(anno != 2019){
        cout << (anno < 2019 ? "Heisei" : "TBD");
    }else if(mese != 4){
        cout << (mese < 4 ? "Heisei" : "TBD");
    }else{
        cout << (giorno <= 30 ? "Heisei" : "TBD");
    }

    cout << "\n";*/

    cout << ( s <= "2019/04/30" ? "Heisei\n" : "TBD\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9+7;
//const long long MOD = 998244353;
const long long INF_LL = 1e18+11; const int INF_int = 1e9+11;
#define ll long long
#define mp std::make_pair
#define rep(i,n) for(int i = 0;i<n;i++)
#define lrep(i,n) for(long long i = 0;i<n;i++)
#define All(a) a.begin(),a.end()
#define Debug_Output_ALL(a) for(auto x:a) cout << x << " ";cout << endl;
int main(){
    int l,r,d;
    cin >> l >> r >> d;
    int ans = r/d;
    ans-=((l-1)/d);
    cout << ans << endl;
}

Measured memory_bytes: 3636
// 5/14
// 過去問ガリガリ
#include <bits/stdc++.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int dp[10][10];

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

    memset(dp, 0, sizeof(dp));

    // for (int i = 1; i < 10; i++) {
    //     for (int j = 1; j < 10; j++) {
    //         dp[i][j] = 0;
    //         for (int k = 1; k <= N; k++) {
    //             string str = to_string(k);
    //             if (str[0] - '0' == i && str[str.size() - 1] - '0' == j) {
    //                 dp[i][j] += 1;
    //             }
    //         }
    //     }
    // }

    for (int k = 1; k <= N; k++) {
        string str = to_string(k);
        int i = str[0] - '0';
        int j = str[str.size() - 1] - '0';
        dp[i][j]++;
    }

    int ans = 0;

    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            ans += dp[i][j] * dp[j][i];
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dd(x) cout<<#x<<" = "<<x<<" "
#define de(x) cout<<#x<<" = "<<x<<"\n"
#define sz(x) int(x.size())
#define All(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef priority_queue<int> BQ;
typedef priority_queue<int,vector<int>,greater<int> > SQ;
const int maxn=3e5+10,mod=1e9+7,INF=0x3f3f3f3f;

int main()
{
	int k,a,b;
  cin>>k>>a>>b;
  vector<int> v;
  for (int i=a;i<=b;++i)
    v.pb(i);
 	sort(All(v),[&](int x,int y){return x>y;});
  for (auto i:v)
    if (i%k==0){
      cout<<"OK";
      return 0;
    }
 	cout<<"NG";
	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
   int s; cin>>s;
   int a=s/100;
   int b=s%100;
   if(1<=a && a<=12){
      if(1<=b && b<=12) cout<<"AMBIGUOUS"<<endl;
      else cout<<"MMYY"<<endl;
   }
   else{
      if(1<=b && b<=12) cout<<"YYMM"<<endl;
      else cout<<"NA"<<endl;
   }
   return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			char[] s = in.nextString().toCharArray();
			char[] t = in.nextString().toCharArray();

			if (s.length != t.length) {
				out.println("No");
				return;
			}

			int len = s.length;

			for (int i = 0; i < len; i++) {
				boolean ok = true;
				for (int j = 0; j < len; j++) {
					if (s[(i+j)%len] == t[j]) {
						continue;
					} else {
						ok = false;
						break;
					}
				}
				if (ok) {
					out.println("Yes");
					return;
				}
			}
			out.println("No");

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 23252
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, H, W; cin >> N >> H >> W;
    vector<int>A(N);
    vector<int>B(N);
    int ans = 0;
    rep(i, N) {
        cin >> A[i] >> B[i];
        if (A[i] >= H && B[i] >= W)ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3648
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<class T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<class T,class Size=typename vector<T>::size_type>inline auto vector_2d(Size h,Size w,T v){return vector<vector<T>>(h,vector<T>(w,v));}
template<class RandomAccessIterator,class Pair=typename iterator_traits<RandomAccessIterator>::value_type>inline void sort_pairs_by_second(RandomAccessIterator first,RandomAccessIterator last){sort(first,last,[](const Pair&p1,const Pair&p2){return p1.second<p2.second||(p1.second==p2.second&&p1.first<p2.first);});}

int main()
{
    constexpr ll mod=1e9+7;
    ll n=in();
    vector<ll>a(n);
    ll sum=0;
    for(ll i=0;i<n;++i){
        a[i]=in();
        sum=(sum+a[i])%mod;
    }
    ll ans=0;
    for(ll i=0;i<n;++i){
        sum=(mod+sum-a[i])%mod;
        ans=(ans+a[i]*sum)%mod;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4788
#include <string>
#include <iostream>
#include <algorithm>
#define mod 1000000007
using namespace std;
int a[3][10007], l[3], f1, f2, power[10007];
int calc(int g) {
	int ret = 0, rng = l[g] - l[2] - f2;
	for (int i = 0; i <= rng; i++) {
		int comp = 0;
		for (int j = l[2] - 1; j >= 0; j--) {
			if (a[g][i + j] > a[2][j]) { comp = 1; break; }
			if (a[g][i + j] < a[2][j]) { comp = -1; break; }
		}
		int res = 0;
		for (int j = i + l[2]; j < l[1]; j++) res = (res + 1LL * a[g][j] * power[j - i - l[2]]) % mod;
		res = 1LL * res * power[i] % mod;
		switch (comp) {
		case 1:
			res = (res + power[i]) % mod; break;
		case 0:
			for (int j = 0; j < i; j++) res = (res + a[g][j] * power[j]) % mod;
			res = (res + 1) % mod; break;
		}
		ret = (ret + res) % mod;
	}
	if (f2) for (int i = 0; i < l[g] - 1; i++) ret = (ret - power[i] + mod) % mod;
	if (f1 && f2) ret = (ret + 1) % mod;
	return ret;
}
int main() {
	string s; power[0] = 1;
	for (int i = 1; i <= 10000; i++) power[i] = 10LL * power[i - 1] % mod;
	for (int i = 0; i < 3; i++) {
		cin >> s;
		reverse(s.begin(), s.end());
		for (int j = 0; j < s.size(); j++) a[i][l[i]++] = s[j] - 48;
	}
	if (l[0] == 1 && !a[0][0]) f1 = 1;
	if (l[2] == 1 && !a[2][0]) f2 = 1;
	if (!f1) {
		for (int j = 0; ; j++) {
			if (a[0][j] == 0) a[0][j] = 9;
			else { a[0][j]--; break; }
		}
	}
	cout << (calc(1) - (!f1 ? calc(0) : 0) + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 3300
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int work = x - a;
		System.out.println(work % b);
	}
}

Measured memory_bytes: 21716
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			int N = scan.nextInt();
			int []A = new int[N];
			int []B = new int[N];
			long nowtime = 0;
			
			Map<Integer,PriorityQueue<Integer>>map = new TreeMap<Integer,PriorityQueue<Integer>>();
			
			
			
			for(int i = 0;i<N;i++) {
				A[i] = scan.nextInt();
				B[i] = scan.nextInt();
				
				if(!map.containsKey(B[i])) {
					map.put(B[i], new PriorityQueue<Integer>());
					map.get(B[i]).add(A[i]);
				}else {
					map.get(B[i]).add(A[i]);
				}
			}
			
			for(Integer key:map.keySet()) {
				//Collections.sort(map.get(key));
				//System.out.println(map.get(key).size());
				int size = map.get(key).size();
				for(int i = 0;i<size;i++) {
					nowtime+=map.get(key).poll();
					//System.out.print(nowtime);
					//System.out.print(" ");
					//System.out.println(key);
					if(nowtime>key) {
						System.out.println("No");
						System.exit(0);
					}
					//System.out.print(map.get(key).get(i));
					//System.out.print(" ");
				}
				//System.out.println();
			}
			
			
			
			System.out.println("Yes");
			
			
			
			
			
			
			
			
			
		}
	}
	
	 
	
}


Measured memory_bytes: 153384
#include<stdio.h>

int main(){
  int n,Y;
  scanf("%d%d",&n,&Y);
  
  int x,y,z,count=0;
  int xa=-1,ya= -1,za=-1;
  
  for(x=0;x<=n;x++){
    for(y=0;y<=n;y++){
      z=n-x-y;
      if(10000*x+5000*y+1000*z==Y&&z>=0){
        xa=x;ya=y;za=z;
      }
    }
  }
  printf("%d %d %d",xa,ya,za);
  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);
		String s = sc.next();
		String s1 = s.substring(0, 2);
		String s2 = s.substring(2, 4);
		int ss1 = Integer.valueOf(s1);
		int ss2 = Integer.valueOf(s2);
		sc.close();

		if (ss1 != 0 && ss2 != 0) {
			if (ss1 <= 12) {
				if (ss2 <= 12) {
					System.out.println("AMBIGUOUS");
				}
				else {
					System.out.println("MMYY");
				}
			}
			else {
				if(ss2<=12) {
					System.out.println("YYMM");
				}
				else {
					System.out.println("NA");
				}
			}
		}
		else {
			if(ss2!=0&&ss2<=12) {
				System.out.println("YYMM");
			}
			else if(ss1!=0&&ss1<=12) {
				System.out.println("MMYY");
			}
			else {
				System.out.println("NA");
			}
		}
	}
}


Measured memory_bytes: 21332
var fs = require('fs');
var inn = parseInt(fs.readFileSync(0).toString());
function isPrime(n) {
    if(n <= 3) return n > 1;
    else if (n % 2 === 0 || n % 3 === 0) return false;
    var i = 5;
    while (Math.pow(i, 2) <= n) {
        if (n % i === 0 || n % (i + 2) === 0) return false;
        i += 6;
    }
    return true;
}
while (!isPrime(inn)) {
inn++;
}
console.log(inn);

Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <complex>
#include <cmath>
using namespace std;
using D = double;
using P = complex<D>;
constexpr D pi = acos(-1);

D cross(const P &a, const P &b){ return a.real()*b.imag()-a.imag()*b.real();}

int main(){
  int n, m;
  while(cin >> n >> m, n){
    vector<D> A(n);
    for(int i = 0; i < n; ++i){
      cin >> A[i];
    }
    D ans = 0;
    for(int i = 0; i < n; ++i){
      vector<vector<D>> dp(n,vector<D>(m+1,0));
      for(int j = i+1; j < n; ++j){
        for(int k = i+1; k < j; ++k){
          for(int l = 2; l < m; ++l){
            P a = polar(1.,2*pi*A[i]), b = polar(1.,2*pi*A[k]), c = polar(1.,2*pi*A[j]);
            D s = abs(cross(b-a,c-a))/2;
            dp[j][l+1] = max(dp[k][l] + s, dp[j][l+1]);
            if(l+1 == m) ans = max(ans,dp[j][l+1]);
          }
        }
      }
    }
    printf("%.6f\n",ans);
  }
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>
#include <sstream>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) x.begin(),x.end()
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

int main(){
    int N;
    cin >> N;
    vector<int>W(N);

    for(int i = 0;i < N;i++)
        cin >> W.at(i);

    vector<ll>rui(N+1);
    rui.at(0) = 0;

    for(int i = 0;i < N;i++){
        rui.at(i+1) = W.at(i) + rui.at(i);
    }

    ll sa1 = 0,sa2,min = INF;

    for(int i = 0;i < N;i++){
        sa1 = abs(rui.at(N) - rui.at(i));
        sa2 = rui.at(i);

        if(min > abs(sa1-sa2))
            min = abs(sa1-sa2);

    }     

    cout << min << endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int n;
string s[500];
bool g[26][26];
int h[26];

bool cycle(int i){
	h[i] = 1;
	rep(j, 26){
		if(!g[i][j]){
			continue;
		}
		if(h[j] == 0 && cycle(j) || h[j] == 1){
			return true;
		}
	}
	h[i] = 2;
	return false;
}

bool solve(){
	rep(i, n - 1){
		int p = s[i].size();
		int q = s[i + 1].size();

		bool same = true;
		rep(j, min(p, q)){
			char k = s[i][j];
			char l = s[i + 1][j];
			if(k != l){
				same = false;
				g[k - 'a'][l - 'a'] = true;
				break;
			}
		}
		if(same && p > q){
			return false;
		}
	}

	rep(i, 26){
		fill_n(h, 26, 0);
		if(cycle(i)){
			return false;
		}
	}
	return true;
}

int main(){
	while(cin >> n, n){
		rep(i, n){
			cin >> s[i];
		}

		cout << (solve() ? "yes" : "no") << endl;
		
		rep(i, 26){
			fill_n(g[i], 26, false);
		}
	}
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
int main()
{    
    
	string n;
	
	int k;
	cin >> k >> n;
	if(k<n.size())
	{
		n.erase(n.begin() + k, n.end());
        cout << n;
        cout << "...";
	}
	else
    cout << n;
	return 0;
}


Measured memory_bytes: 3584
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {

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

		final String s = sc.next();

		sc.close();

		final String s1 = s.substring(0, 2);
		final String s2 = s.substring(2);

		final List<String> mmList = new ArrayList<>(Arrays.asList("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"));

		if (!mmList.contains(s1) && !mmList.contains(s2)) {
			System.out.print("NA");
			return;
		}
		if (mmList.contains(s1) && mmList.contains(s2)) {
			System.out.print("AMBIGUOUS");
			return;
		}
		if (mmList.contains(s2)) {
			System.out.print("YYMM");
			return;
		}
		if (mmList.contains(s1)) {
			System.out.print("MMYY");
			return;
		}

	}

}


Measured memory_bytes: 21844
n=int(input())
al=list(map(int,input().split()))
s=1000
k=0
for i,j in zip(al,al[1:]):
    if i==j:
        continue
    if i<j:
        m=s//i
        k+=m
        s-=m*i
    else:
        s+=k*i
        k=0
s+=k*al[-1]
print(s)


Measured memory_bytes: 9184
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e5+100;
LL a[N];
int main()
{
	int n,m;
	while(cin>>n>>m)
	{
		for(int i=1;i<=n;i++)cin>>a[i];
		LL ans=0;
		for(int i=1;i<=n-1;i++)
		{
			if(a[i]+a[i+1]>m)
			{
				LL tmp=a[i]+a[i+1]-m;
				a[i+1]-=tmp;
				ans+=tmp;
				if(a[i+1]<0)
				{
					a[i]+=a[i+1];
					a[i+1]=0;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
 } 

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
    int s,m,temp,x=0;
    char a[101];
    int b[100]= {0};
    cin>>s;
    if((s>=1)&&(s<=100))
        for(int i=0; i<s; i++)
            {
                cin>>a[i];
                if(a[i]=='I')
                    {
                        ++x;
                        b[i]=x;
                    }
                else if(a[i]=='D')
                    {
                        --x;
                        b[i]=x;
                    }
                else
                    m=x;
            }

    for(int c=0; c<s-1; c++)
        {
            if(b[c]>b[c+1]){
                temp=b[c];
            b[c]=b[c+1];
            b[c+1]=temp;}
        }

if(b[s-1] >0)
    cout<<b[s-1];
    else
        cout<<"0";
        return 0;
    }


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string n;
    cin >> n;

    vector<char> c = {
            'p', 'p', 'h', 'b', 'h', 'h', 'p', 'h', 'p', 'h'
    };

    cout << c[n[n.size() - 1] - '0'] << "on" << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#include <unistd.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    vector<int> out;
    while(true){
        int a, b;
        cin >> a >> b;
        if(a == 0) break;
        vector<vector<int>> dp(a + 1, vector<int>(b + 1));
        vector<vector<bool>> bl(a + 1, vector<bool>(b + 1));
        int n;
        cin >> n;
        for(int i = 0; i < n; i++){
            int c, d;
            cin >> c >> d;
            bl[c][d] = 1;
        }
        dp[1][1] = 1;
        for(int i = 1; i <= a; i++){
            for(int j = 1; j <= b; j++){
                if(i == 1 && j == 1) continue;
                if(!bl[i][j]) dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
            }
        }
        /*sleep(1);
        for(int i = 1; i <= a; i++){
            cout << "\n";
            for(int j = 1; j <= b; j++){
                cout << dp[i][j];
            }
        }*/
        out.push_back(dp[a][b]);
    }
    for(int i = 0; i < out.size(); i++) cout << out[i] << "\n";
}


Measured memory_bytes: 3008
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
//AtCoderC++.cpp

using namespace std;


inline int ceileing(int a, int b) {return a % b == 0 ? a / b : a / b + 1;}
int main() {
	int x;cin>>x;
	cout << (x<1200?"ABC":"ARC")<< endl;
}

Measured memory_bytes: 256
//                        Bismillahir Rahmanir Rahim
    //ALGO:
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize ("unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include<bits/stdc++.h>
    #define pb push_back
    #define F first
    #define S second
    #define all(v) v.begin(), v.end()
    #define FILL(a, x) memset(a, x, sizeof(a))
    #define ll long long
    #define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
    #define INF INT_MAX
    /*
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
    #define ordered_multiset tree<pair<int, int>, null_type,less<pair<int, int> >, rb_tree_tag,tree_order_statistics_node_update>
    */
    const double Pi=acos(-1);
    using namespace std;
    int debug=01;
    ll cost[110], value[110], n, mx, dp[110][100010], ans, sum;
    ll solve(ll i, ll x, ll y){
        if(i>n) return 0;
        if(~dp[i][x]) return dp[i][x];
        ans=max(ans, x);
        ll ret=solve(i+1, x, y);
        if(cost[i]+y<=mx) ret=min(ret, solve(i+1, x+value[i], y+cost[i])+cost[i]);
        return dp[i][x]=ret;
    }
    ll solve(int i, ll val){
        if(val<=0) return 0;
        if(i==n) return mx+mx;
        if(~dp[i][val]) return dp[i][val];
        return dp[i][val]=min(solve(i+1, val), solve(i+1, val-value[i])+cost[i]);
    }
    int main() {
        cin>>n>>mx;
        FILL(dp, -1);
        for(int i=0; i<n; i++) scanf("%lld%lld", &cost[i], &value[i]), sum+=value[i];
        while(sum--) if(solve(0, sum+1)<=mx) {cout<<sum+1; return 0;}
        cout<<0;
    }



Measured memory_bytes: 86272
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//mint型にキャスト
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(ll n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
    mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
int main(){
  int n;
  cin>>n;
  V<ll> a(n+1);
  int l=0,r=0;
  V<bool> used(n,false);
  V<int> id(n,-1);
  for(int i=0;i<n+1;i++){
    cin>>a[i];
    if(!used[a[i]-1]){
      used[a[i]-1]=1;
      id[a[i]-1]=i;
    }else{
      l=id[a[i]-1];
      r=i;
    }
  }
  mint ans;
  init();
  for(int i=1;i<=n+1;i++){
    ans=COM(n+1,i);
    ans-=COM(l+n-r,i-1);
    cout<<ans<<"\n";
  }
}


Measured memory_bytes: 51120
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;
typedef pair<ll,ll> P;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return 1;
    }
    return 0;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return 1;
    }
    return 0;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};
// v.front() = -BOUND;
// v.back() = BOUND;

struct edge{
    int cost, to;

    edge(int in_cost, int in_to){
        cost=in_cost;
        to=in_to;
    }
    bool operator<(const edge &a) const
    {
        return cost > a.cost;
    }
};

#define MAX_N 100010
int par[MAX_N];
int rank_u[MAX_N];

void init(int n){
    for(int i=0; i<n; i++){
        par[i]=i;
        rank_u[i]=0;
    }
}

int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}

void unite(int x, int y){
    x=find(x);
    y=find(y);
    if(x==y) return;

    if(rank_u[x]<rank_u[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(rank_u[x]==rank_u[y]) rank_u[x]++;
    }
}

bool same(int x, int y){
    return find(x)==find(y);
}

int main() {
    int N,M;
    cin >> N >> M;
    init(N);

    map<int,int>mp;
    rep(i,N){
        int p;
        cin >> p;
        p--;
        mp[p]=i;
    }
    rep(i,M){
        int x,y;
        cin >> x >> y;
        x--, y--;
        unite(x,y);
    }

    int ans=0;
    rep(i,N){
        if(same(i,mp[i])){
            ans++;
        }
    }

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


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

using namespace std;

#define ll long long
#define mod 1000000007

const ll INF = 1e11;

void solve(){

    ll n, d; cin >> n >> d;
    d *= d;
    ll count = 0;

    while(n--){
        ll x, y; cin >> x >> y;
        if(x*x + y*y <= d) ++count;
    }
    cout << count << "\n";

    return;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    //int test; cin >> test;
    //for(int t = 1; t <= test; ++t){
        solve();    
    //}

	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)

int main() {
	string n;
	cin >> n;
	if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	return(0);
}

Measured memory_bytes: 3576
#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++){
        
        bool can=true;

        int tmp=i;
        int keta=0;
        int ketanum[5]={0};
        int j=0;
        while(tmp>0){
            keta++;
            ketanum[j]=tmp%10;
            tmp/=10;
            j++;
        }
        
        for(int k=0;k<keta/2;k++){        
            if(ketanum[k]!=ketanum[keta-1-k]){
                can=false;
            }
        }
        if(can) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque
H,W=map(int,input().split())
wnum=0
field=[input() for _ in range(H)]
for i in range(H):
    for j in range(W):
        if field[i][j]=='.':
            wnum+=1
# スタートからゴールまでの最短経路をBFSで求め、wnumからその分を引けば、最大スコアが得られる。
dist=[[-1]*W for _ in range(H)]
dist[0][0]=0
que=deque()
que.append([0,0])
while que:
    s_h,s_w=que.popleft()
    for dh,dw in [[-1,0],[1,0],[0,-1],[0,1]]:
        nh=s_h+dh
        nw=s_w+dw
        if nh<0 or nh>=H or nw<0 or nw>=W:continue
        if field[nh][nw]=='#':continue
        if dist[nh][nw]!=-1:continue
        dist[nh][nw]=dist[s_h][s_w]+1
        que.append([nh,nw])
    
if dist[H-1][W-1]==-1:
    print(-1)
else:
    print(wnum-dist[H-1][W-1]-1)


Measured memory_bytes: 3316
import sys
input=sys.stdin.readline
import collections

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    A.sort()
    q = collections.deque(A)
    ans = 0
    while q:
        q.popleft()
        q.pop()
        ans += q.pop()
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 41820
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define mod 1000000007
#define endl "\n"

int power(int a,int b,int m=mod)
{
	if(b==0)	return 1;
	if(b==1)	return a;
	int res=power(a,b/2,m);
	res=(res*res)%m;
	if(b&1)	res=(res*a)%m;
	return res;
}
int modinv(int a,int m=mod){ return power(a,m-2,m);}
int add(int a,int b,int m=mod){	int c=(a%m+b%m);	if(c>=m)	c-=m;	return c;}
int sub(int a,int b,int m=mod){	int c=(a%m-b%m);	if(c<0)		c+=m;	return c;}
int mul(int a,int b,int m=mod){	return (a*b)%m;}
//	x<<1 => x*2		x>>1 => x/2;	cout<<flush;
//	cout<<fixed<<setprecision(10)<<ans<<endl;


void solve()
{
	int a;
	cin>>a;
	cout<<(a+a*a+a*a*a)<<endl;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
int pa[111111],id[111111],cnt,rk[111111];
bool used[333333];
int n,m,x,y,z;
vector<pair<int,int> > g[1111111];
vector<int> gra[333333];
void Init(int i)
{
	pa[i]=i;
	used[i]=0;
	id[i]=-1;	
	rk[i]=1;
}
int root(int x)
{
	if (pa[x]!=x) pa[x]=root(pa[x]);
	return pa[x];
}
void Union(int x,int y)
{
	int rx=root(x),ry=root(y);
	if (rx==ry) return;
	if (rk[rx]>rk[ry]) 
	{
		pa[ry]=rx;
		rk[rx]+=rk[ry];
	}
	else 
	{
		pa[rx]=ry;
		rk[ry]+=rk[rx];
	}
}
queue<int> q;
int dist[333333];
int main()
{
	while(scanf("%d%d",&n,&m)==2)
	{
		for (int i=1;i<=1000000;i++) g[i].clear();
		for (int i=1;i<=300000;i++) gra[i].clear();
		for (int i=1;i<=m;i++)
		{
			scanf("%d%d%d",&x,&y,&z);
			g[z].push_back(make_pair(x,y)); 
		}
		cnt=n;
		for (int i=1;i<=1000000;i++)
		{
			for (int j=0;j<g[i].size();j++)
			{
				Init(g[i][j].first);
				Init(g[i][j].second);
			}
			for (int j=0;j<g[i].size();j++)
			{
				Union(g[i][j].first,g[i][j].second);
			}
			for (int j=0;j<g[i].size();j++)
			{
				x=g[i][j].first;y=g[i][j].second;
				if (!used[x])
				{
					int r=root(x);
					if (!~id[r]) id[r]=++cnt;
					used[x]=1;
					gra[x].push_back(id[r]);
					gra[id[r]].push_back(x); 
				}
				if (!used[y])
				{
					int r=root(y);
					if (!~id[r]) id[r]=++cnt;
					used[y]=1;
					gra[y].push_back(id[r]);
					gra[id[r]].push_back(y);  
				}
			}
		}
		memset(dist,-1,sizeof(dist));
		q.push(1);dist[1]=0;
		while(!q.empty())
		{
			x=q.front();q.pop();
			for (int i=0;i<gra[x].size();i++)
			{
				int to=gra[x][i];
				if (!~dist[to])
				{
					dist[to]=dist[x]+1;
					q.push(to); 
				}
			}
		}
		if (!~dist[n]) printf("-1\n");
		else printf("%d\n",dist[n]/2);
	}
	return 0;
}

Measured memory_bytes: 52736