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



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

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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; }

const long long INF = 1LL<<60;

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}

struct edge{int from, to,cost;};

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));

int h1,h2,m1,m2,k;


int main()
{
    cin>>h1>>m1>>h2>>m2>>k;
    int hour=h2-h1;
    int minu=0;
    if(m2>=m1){ // m2=50 ,m1=10 なら +40
        minu=m2-m1;
    }else{ //m2=10 ,m1=30なら
        hour--;
        minu=60+(m2-m1);
    }

    int span=60*hour+minu;
    if(k>=span){
        cout<<0<<endl;
    }else{
        cout<<span-k<<endl;
    }

    return 0;

}




Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;

const int MAX_PRIME = 10001;

vector<int> is_prime(MAX_PRIME,1);

void calcPrime(){
	is_prime[0]=is_prime[1]=0;
	for(int i=2; i<MAX_PRIME; i++){
		if(is_prime[i]==1){
			for(int j=i*2; j<MAX_PRIME; j+=i){
				is_prime[j]=0;
			}
		}
	}
}



int main(){
	vi v;
	calcPrime();
	for(int i = 2; i < MAX_PRIME; i++){
		if(is_prime[i]) v.pb(i);
	}

	int n, ans;
	while(cin>>n && n > 0){
		ans = 0;
		for(int i = 0; i < v.size(); i++){
			int sum = 0;
			for(int j = i; j < v.size(); j++){
				sum+=v[j];
				if(sum >= n) break;
			}
			if(sum == n) ans++;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1268
#include<bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std;
//using ll = long long;
using ll = mp::cpp_int;

/*long long modPow(long long a, long long r, int mod) {
    if (r == 0) return 1;
    if (r % 2 == 0) {
        int t = modPow(a, r / 2, mod);
        return t * t % mod;
    }
    return a * modPow(a, r - 1, mod);
}
*/

ll modPow(ll a, ll r, ll mod) {
    ll ret = 1;
    for (ll i = 0;i < r;++i) {
        ret *= a;
        ret %= mod;
    }
    return ret;
}

ll Mod(ll a, ll m) {
    return (a % m + m) % m;
}

int main() {
    const int mod = 1e9 + 7;
    ll n;
    cin >> n;
    ll ans = 0;
    ans += modPow(10, n, mod);
    ans = Mod(ans, mod);
    ans -= modPow(9, n, mod);
    ans = Mod(ans, mod);
    ans -= modPow(9, n, mod);
    ans = Mod(ans, mod);
    ans += modPow(8, n, mod);
    cout << Mod(ans, mod) << endl;
}


Measured memory_bytes: 3648
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
  int n;
  scanf("%d", &n);
  int i;
  int a[n];
  int b[n];
  memset(b, 0, sizeof(b));
  b[n] = 0;
  for (i = 2; i <= n; i++)
  {
    scanf("%d", &a[i]);
    b[a[i]]++;
  }
  
  for (i = 1; i <= n; i++)
    printf("%d\n", b[i]);
  
  return 0;
}

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

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

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

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

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

int main(){
    vi a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(all(a));
    int ans=0;
    ans+=a[1]-a[0]+a[2]-a[1];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    class Store {
        int i;
        String s;
        int p;
        public Store(int i, String s, int p) {
            this.i = i;
            this.s = s;
            this.p = p;
        }

        @Override
        public String toString() {
            return this.i + " " + this.s + " " + this.p;
        }

    }
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        Store[] sArr = new Store[n];

        for (int i = 0; i < n; i++) {
            String s = sc.next();
            int p = sc.nextInt();
            sArr[i] = new Store(i + 1, s, p);
        }

        Arrays.sort(sArr, (a, b) -> a.s.compareTo(b.s));


        String cur = "";
        List<Store> s2 = new ArrayList<>();
        for (Store s : sArr) {
            if (!cur.equals(s.s)) {
//                debug("1b ", s2);
                s2.sort((a, b) -> (b.p - a.p));
//                debug("1a", s2);
                for (Store ss : s2) {
                    System.out.println(ss.i);
                }
                s2 = new ArrayList<>();
            }
            cur = s.s;
            s2.add(s);
        }
        s2.sort((a, b) -> b.p - a.p);
        for (Store ss : s2) {
            System.out.println(ss.i);
        }



//        for (int i = 0; i < n; i++) {
////            debug(sArr[i]);
//            System.out.println(sArr[i].i);
//        }
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


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

using namespace std;

class range {
private:
  struct Iterator {
    int val;
    int operator*() {return val;}
    bool operator!=(Iterator &itr) {return val < itr.val;}
    void operator++() {++val;}
  };
  Iterator i, n;
public:
  range(int n) : i({0}), n({n}) {}
  range(int i, int n) : i({i}), n({n}) {}
  Iterator &begin() {return i;}
  Iterator &end() {return n;}
};

template<class T> T at(vector<T> v, int i) {return v[(i % (int)v.size() + v.size()) % v.size()];}

int main() {
  int n, res = 0;
  cin >> n;
  for (int i : range(n)) {
    long long a;
    cin >> a;
    bool ok = false;
    for (long long x = 1, y = 1e9; x < y; ++x) {
      y = (a - x) / (2 * x + 1);
      if (2 * x * y + x + y == a) {
        ok = true;
        break;
      }
    }
    if (!ok) ++res;
  }
  cout << res << endl;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
#define ll          long long int
#define ld          double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         1000000000000000000
#define MAXN        200005
#define LOG         20
#define mod         1000000007
using namespace std;
 
ll dp[MAXN];
ll a[MAXN];
 
ll solve(ll n){
    if(n==0){
        return 0;
    }
    if(dp[n]!=-1){
        return dp[n];
    }
    if(n>=2){
        dp[n]=min(abs(a[n]-a[n-1])+solve(n-1),abs(a[n]-a[n-2])+solve(n-2));
    }
    else{
        dp[n]=abs(a[n]-a[n-1])+solve(n-1);
    }
    return dp[n];
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    memset(dp,-1,sizeof(dp));
    ll n,i;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    solve(n-1);
    // for(i=0;i<=n;i++){
    //     cout<<dp[i]<<" ";
    // }
    cout<<dp[n-1];
}

Measured memory_bytes: 4224
n = int(input())
listA = list(map(int, input().split()))
a = 0
b =  100000000
for i in range(min(listA), max(listA)+1):
  for j in range(n):
    a = a + (listA[j]-i)**2
  if a<b:
    b=a
  a=0
print(b)
    

Measured memory_bytes: 2940
#include<stdio.h>
int main(){
    int a,b;
    int i,j,flag = 0;
    int tmp,tmp1,tmp2;
    int min;
    
    scanf("%d %d",&a,&b);
    
    for(i = 0 ; ; i++){
        tmp = i;
        tmp1 = tmp*0.08;
        tmp2 = tmp*0.10;
        if(tmp1 == a && tmp2 == b){
            min = tmp;
            break;
        }
        if(tmp1 > a || tmp2 > b){
            flag = 1;
            break;
        }
    }
    if(flag == 0) printf("%d\n",min);
    else printf("-1\n");
    return 0;
}


Measured memory_bytes: 128
# https://atcoder.jp/contests/abc108/tasks/abc108_b
x1, y1, x2, y2 = map(int, input().split())
x = x2 - x1
y = y2 - y1

x3, y3 = x2 - y, y2 + x 
x4, y4 = x1 - y, y1 + x
print(x3, y3, x4, y4)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,string> P;
typedef pair<int,P > PP;

int main(){
  int n,q;
  while(cin>>n>>q,n+q){
    PP pr[1010];
    for(int i=0;i<n;i++){
      string s;
      int a,b;
      cin>>s>>a>>b;
      pr[i]=PP(b,P(a,s));
    }
    pr[n]=PP(1e9+1,P(0,"a"));
    sort(pr,pr+n+1);
    for(int i=0;i<q;i++){
      int x;
      cin>>x;
      int ok=n,ng=-1,mid;
      while(ok-ng>1){
	mid=(ok+ng)/2;
	if(pr[mid].first>=x)ok=mid;
	else ng=mid;
      }
      int t=pr[ok].first-x;
      int k=pr[ok].second.first;
      if(t<k)cout<<pr[ok].second.second<<" "<<k-t<<endl;
      else cout<<"Unknown"<<endl;
    }
  }
    return 0;
}



Measured memory_bytes: 3160
#!/usr/bin/env python
# coding: utf-8

def readInt():
    return int(input())

def readList():
    return list(input().split())

def readListI():
    return list(map(int, input().split()))

def main():
    n, k = readListI()
    lv = readListI()
    ret = 0
    for l in range(min(n, k)+1):
        for r in range(min(n, k)+1-l):
            jewel = sorted(lv[:l] + lv[n-r:])
            for p in range(l+r):
                if l+r+p > k:
                    continue
                ret = max(ret, sum(jewel[p:]))
    print(ret)


if __name__ == '__main__':
    main()


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

typedef long long ll;

class BIT{
    ll bit[1<<19] = {};
public:
    void insert(int id, ll num) {
        int tmp = id;
        while (tmp < (1 << 19)) {
            bit[tmp] += num;
            tmp += -tmp & tmp;
        }
    }
    ll find(int id) {
        int tmp = id;
        ll ret = 0;
        while (tmp > 0) {
            ret += bit[tmp];
            tmp -= -tmp & tmp;
        }
        return ret;
    }
    ll find(int left, int right) {
        return find(right) - find(left - 1);
    }
};

ll n,d,a,ans;
pair<ll,ll> p[200010];

int main() {
    cin >> n >> d >> a;
    for (int i = 0; i < n; i++) cin >> p[i].first >> p[i].second;
    sort(p,p+n);

    queue<pair<ll,ll>> v;
    ll sum = 0;
    for (int i = 0; i < n; i++) {
        while (!v.empty() && v.front().first < p[i].first) {
            sum -= v.front().second;
            v.pop();
        }
        p[i].second -= sum;
        if (p[i].second <= 0) continue;
        ll times = (p[i].second + a - 1) / a;
        v.push({p[i].first + d * 2, times * a});
        sum += times * a;
        ans += times;
    }

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

Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<math.h>

#define long long ll

using namespace std;

main()
{
	int n;
	cin>>n;
	
	int i,j;
	int a[n];
	int dp[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	
	for(i=2;i<n;i++)
	{
		dp[i] = min(abs(a[i] - a[i-1]) + dp[i-1]  ,  abs(a[i] - a[i-2]) + dp[i-2]);
	}
	cout<<dp[n-1];
	
	
}



Measured memory_bytes: 1024
use std::io;
use std::cmp;
use std::cmp::Ordering;


// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
struct State {
    cost     : i32,
    node     : i32,
    vismask  : i32
}

impl Ord for State {
    fn cmp(&self, other: &State) -> Ordering {
        other.cost.cmp(&self.cost)
    }
}

impl PartialOrd for State {
    fn partial_cmp(&self, other : &State) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}


fn main() {
    
    let n = read_t_in_line::<i32>()[0];
    let a = read_t_in_line::<i32>();
    let mut f = vec![0 ; 101000];

    for i in 0..n {
        let ai = a[i as usize];
        let v = vec![ai, ai + 1, ai - 1];
        for j in v {
            f[(j + 1) as usize] += 1;
        }
    }
    
    let mut res = -1;
    for i in 0..f.len() {
        res = max(res, f[i]);
    }

    println!("{}", res);


}


Measured memory_bytes: 10492
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<int> Slist() { return ReadLine().Split().Select(int.Parse).ToList(); }

        static int N;
        static int[,] Move;
        static int[,] dp;
        static void Main(string[] args)
        {
            var NW = Sarray();
            var N = NW[0];
            var W = NW[1];
            var v = new long[N];
            var w = new long[N];
            for(var i=0;i<N;++i)
            {
                var t = Sarray();
                w[i] = t[0];
                v[i] = t[1];
            }
            var nw = new Dictionary<long, long>[N];
            for (var i = 0; i < N; ++i)
                nw[i] = new Dictionary<long, long>(10000);
            nw[0][w[0]] = v[0];
            for (var i = 1; i < N; ++i)
            {
                foreach (var wv in nw[i-1])
                {
                    chmax(nw[i], wv.Key, wv.Value);
                    if (wv.Key + w[i] <= W)
                        chmax(nw[i], wv.Key + w[i], wv.Value + v[i]);
                }
                chmax(nw[i], w[i], v[i]);
            }
            WriteLine(nw[N - 1].Values.Max());
        }
        static void chmax(Dictionary<long,long> dic, long key, long val)
        {
            if (dic.ContainsKey(key))
                dic[key] = Max(dic[key], val);
            else
                dic[key] = val;
        }
    }
}


Measured memory_bytes: 396804
#include <stdio.h>

const int MAX_N = 3005;
const int MOD = 1000000007;

int n,dp[MAX_N][MAX_N],sum[MAX_N];
char s[MAX_N];

int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	dp[1][1]=1;
	for (int i=2; i<=n; i++)
	{
		for (int j=1; j<i; j++)
			sum[j]=(sum[j-1]+dp[i-1][j])%MOD;
		for (int j=1; j<=i; j++)
			if (s[i-2]=='<')
				dp[i][j]=sum[j-1];
			else
				dp[i][j]=(sum[i-1]-sum[j-1]+MOD)%MOD;
	}
	int ans=0;
	for (int i=1; i<=n; i++)
		ans=(ans+dp[n][i])%MOD;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 34176
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

struct unionfind {
    vector<int> d;
    unionfind(int n=0): d(n,-1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    vi x(m), y(m), z(m);
    rep(i, m) cin >> x[i] >> y[i] >> z[i];
    rep(i, m) {
        x[i]--;
        y[i]--;
    }
    unionfind uf(n);
    rep(i, m) uf.unite(x[i], y[i]);
    int ans = 0;
    rep(i, n) if (uf.find(i) == i) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        System.out.println((a+b) % 2 == 0 ? (a+b)/2 : "IMPOSSIBLE");
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int n,m,a[100005],b[100005],c[100005];
struct A{
	int b,c;
	bool operator <(const A &nt) const{
		return c>nt.c;
	}
}oh[100005];
signed main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	for(int i=1;i<=m;i++) scanf("%d%d",&oh[i].b,&oh[i].c);
	sort(oh+1,oh+1+m);
	int i=1,j=1;
	while(oh[i].c>a[j]&&i<=m&&j<=n){
		a[j]=oh[i].c;
		j++;
		oh[i].b--;
		if(!oh[i].b) i++;
	}
	long long ans=0;
	for(int i=1;i<=n;i++) ans+=a[i];
	printf("%lld",ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef set<ll> sl;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second

const int MAX_N = 100050;
const ll INF = 1e18;
int n, m;
ll x[MAX_N];
bool vis[MAX_N];
vector<pair<int, ll> > adj[MAX_N];


bool dfs(int here) {
	vis[here] = true;

	if(x[here] == INF) {
		x[here] = 0;
	}

	for (auto it : adj[here]) {
		int there = it.F;
		ll d = it.S;

		if(vis[there]) {
			if(x[there] != x[here] + d) {
				return false;
			}
		} else {
			x[there] = x[here] + d;
			if(!dfs(there)) {
				return false;
			}
		}
	}

	return true;
}

void dfsAll() {
	rep(i,1,n+1) {
		if(!vis[i] && !dfs(i)) {
			cout << "No" << '\n';
			return;
		} 
	}
	cout << "Yes" << '\n';
	return;
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n >> m;
	rep(i,0,MAX_N) {
		x[i] = INF;
		vis[i] = false;
	}
	rep(i,0,m) {
		int L, R;
		ll D;
		cin >> L >> R >> D;
		adj[L].pb(mp(R,D));
		adj[R].pb(mp(L,-D));
	}
	dfsAll();
	return 0;
}


Measured memory_bytes: 15616
#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(ll)n;++i)
using P = pair<ll,ll>;

P f( int x ){
  int a = x%10; // 末尾の桁
  int b = 0; // 先頭の桁
  while( x ){
    b = x;
    x /= 10;
  }
  return make_pair(a,b);
}

int main(){
  int n;cin >> n;
  map<P,int> freq;
  for(int i=1;i<=n;++i){
    P p = f(i);
    freq[p]++;
  }

  ll ans = 0;
  // 先頭と末尾の要素を反転させて
  // 一致する( = 条件を満たす )
  // ような数字の組の数を足す
  for(int i=1;i<=n;++i){
    P p = f(i);
    P q(p.second,p.first);
    ans += freq[q];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder09
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] z = Console.ReadLine().Split(' ');
            int a = int.Parse(z[0]);
            int b = int.Parse(z[1]);
            Console.WriteLine(a+(b/2));
        }
    }
}


Measured memory_bytes: 11092
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
	ll a,b;
	cin>>a>>b;
	ll c,d;
	cin>>c>>d;
	cout << (a-c)*(b-d) << endl;
	return 0;	
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

#############
# Libraries #
#############
import random
import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache

D = int(input().strip())
C = list(map(int,input().split()))
S = [list(map(int, input().split())) for _ in range(D)]

schedule = []


for d in range(D):
  MAX = -10**20
  temp = None
  last = [-1 for i in range(26)]
  for j in range(26):
    s = 0
    for i in range(26):
      if i == j:
        last[i] = d
        s += S[d][i]
      else:
        s -= C[i]*(d-last[i])
    if s > MAX:
      MAX = s
      temp = j
  schedule.append(temp)
  
score = 0
last = [[-1] for i in range(26)]  

for d in range(D):
  t = schedule[d]
  last[t].append(d)
  score += S[d][t]
  

for i in range(26):
  last[i].append(D)
  for k in range(len(last[i])-1):
    g = last[i][k+1]-last[i][k]-1
    score -= C[i]*g*(g+1)//2

count = 0

while count:
  count -= 1
  prev = score
  d,q = random.choice(range(D)),random.choice(range(26))
  p = schedule[d]
  schedule[d] = q
  score -= S[d][p]
  score += S[d][q]
  
  pos = last[p].index(d)
  score -= C[p]*(last[p][pos]-last[p][pos-1])*(last[p][pos+1]-last[p][pos])
  last[p].remove(d)
  
  pos = bisect.bisect(last[q],d)
  score += C[q]*(d-last[q][pos-1])*(last[q][pos]-d)
  bisect.insort(last[q],d)
  if score<prev:
    score = prev
    bisect.insort(last[p],d)
    last[q].remove(d)
    schedule[d] = p
    
for i in schedule:
  print(i+1)


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

int main(){
  int N;
  cin >> N;
  vector<vector<int>> F(N,vector<int>(10));
  vector<vector<int>> P(N,vector<int>(11));
  for (int i=0;i<N;i++){
    for (int j=0;j<10;j++){
      cin >> F[i][j];
    }
  }
  for (int i=0;i<N;i++){
    for (int j=0;j<11;j++){
      cin >> P[i][j];
    }
  }
  int ans=-1000000007;
  for (int bit=1;bit<(1<<10);bit++){
    int pro=0;
    for (int j=0;j<N;j++){
      int c=0;
      for (int k=0;k<10;k++){
        if (F[j][k]==1&&bit&(1<<k)){
          c++;
        }
      }
      pro+=P[j][c];
    }
    ans=max(ans,pro);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = gets.to_i
neighbors = Array.new(N+1){Array.new}
(N-1).times do |i|
    a, b = gets.split.map(&:to_i)
    neighbors[a].push(b)
    neighbors[b].push(a)
end

d1 = Array.new(N+1)
visited = Array.new(N+1)
d1[1] = 0
visited[1] = true
stack = [1]
while stack.length > 0 do
    v = stack[-1]
    updated = false
    neighbors[v].each do |u|
        next if visited[u]
        visited[u] = true
        updated = true
        d1[u] = stack.length
        stack.push(u)
        break
    end
    stack.pop unless updated
end

dN = Array.new(N+1)
visited = Array.new(N+1)
dN[N] = 0
visited[N] = true
stack = [N]
while stack.length > 0 do
    v = stack[-1]
    updated = false
    neighbors[v].each do |u|
        next if visited[u]
        visited[u] = true
        updated = true
        dN[u] = stack.length
        stack.push(u)
        break
    end
    stack.pop unless updated
end

bn = (1..N).count{|i| d1[i] <= dN[i]}
wn = N - bn

puts bn > wn ? 'Fennec' : 'Snuke'

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

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int main() {

	int h, w; cin >> h >> w;
	vector<vector<int>> a(h, vector<int>(w, 0)); for (int i = 0; i <= h - 1; i++) for (int j = 0; j <= w - 1; j++) cin >> a[i][j];
	vector<vector<int>> b(h, vector<int>(w, 0)); for (int i = 0; i <= h - 1; i++) for (int j = 0; j <= w - 1; j++) cin >> b[i][j];

	const int maxv = (h + w) * 80;
	vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(maxv + 1, false)));

	dp[0][0][abs(a[0][0] - b[0][0])] = true;

	for (int i = 0; i <= h - 1; i++) {
		for (int j = 0; j <= w - 1; j++) {
			for (int k = 0; k <= maxv; k++) {
				if (i > 0) {
					dp[i][j][k] = dp[i - 1][j][k + abs(a[i][j] - b[i][j])]  or
					              dp[i - 1][j][abs(k - abs(a[i][j] - b[i][j]))];
				}
				if (j > 0) {
					dp[i][j][k] = dp[i][j][k] or
					              dp[i][j - 1][k + abs(a[i][j] - b[i][j])]  or
					              dp[i][j - 1][abs(k - abs(a[i][j] - b[i][j]))];
				}
			}
		}
	}

	for (int k = 0; k <= maxv; k++) {
		if (dp[h - 1][w - 1][k] == true) {
			cout << k;
			exit(0);
		}
	}

	return 0;
}

Measured memory_bytes: 14136
from bisect import bisect_left
n = int(input())
sides = list(map(int, input().split()))
sides.sort()
ans = 0
for a in range(len(sides)):
    for b in range(a+1,len(sides)):
        bound = bisect_left(sides, sides[a]+sides[b], b+1)
        if bound >= n:
            ans += bound - b - 1
        elif sides[bound] < sides[b]:
            ans += bound - b
        elif bound > b+1:
            ans += bound - b - 1

print(ans)
           

Measured memory_bytes: 3188
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int C = scanner.nextInt();
    int[] B = new int[M];
    for (int i = 0; i < M; i++) B[i] = scanner.nextInt();
    int tot = 0;
    for (int i = 0; i < N; i++) {
      int r = C;
      for (int j = 0; j < M; j++) r += scanner.nextInt() * B[j];
      if (r > 0) tot++;
    }
    System.out.println(tot);
  }
}


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

int main(){
    int A, B, K;
    cin >> A >> B >> K;

    for(int i=A;i<A+K;i++){
        if( i <= B )    cout << i << " ";
    }
    for(int i=B-K+1;i<=B;i++){
        if( A+K <= i )    cout << i << " ";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main(void){
   char n;
   
   while(1){
       scanf("%c", &n);
       if(isupper(n) != 0){
           n = tolower(n);
           printf("%c", n);
       }else if(islower(n) != 0){
           n = toupper(n);
           printf("%c", n);
       }else{
           printf("%c", n);
       }
       if(n=='\n') break;
    
   }

   return 0;
    
}



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

int main(void) {
	int N;
	cin >> N;
	vector<int> H(N);
	int ans = 0;
	int lowerCount = 0;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	for (int i = 1; i < N; i++) {
		if (H[i - 1] >= H[i]) {
			lowerCount++;
		} else {
			lowerCount = 0;
		}
		ans = max(ans, lowerCount);
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<climits>
#include<cassert>
#include<map>

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(a) a.begin(),a.end()

using namespace std;

#define IINF INT_MAX

struct Data {
  int v,ID;
  bool operator < ( const Data &data ) const {
    if( v != data.v ) return v > data.v;
    return ID < data.ID;
  }
};

int calc(vector<vector<int>> a,vector<int> &r) {
  int n = r.size();
  vector<vector<int>> score(3,vector<int>(n));
  rep(i,n) rep(j,3) score[j][i] = a[i][j];
  rep(i,3) sort(ALL(score[i]),greater<int>());

  vector<Data> vec;
  rep(i,n) {
    int v = 0;
    rep(j,3) {
      int rank = -1;
      rep(k,n) if( score[j][k] == a[i][j] ) { rank = k; break; }
      assert( rank != -1 );
      v += r[rank];
    }
    vec.push_back((Data){v,i});
  }
  sort(ALL(vec));
  rep(i,n) if( vec[i].ID == 0 ) return i+1;
  assert(false);
}

int main() {
  int n;
  cin >> n;
  vector<int> r(n);
  rep(i,n) cin >> r[i];
  vector<vector<int>> a(n,vector<int>(3));
  rep(i,n) rep(j,3) {
    cin >> a[i][j];
    assert(  1 <= a[i][j] && a[i][j] <= 100 );
  }
  assert( calc(a,r) == 9 );
  int mini = IINF;
  REP(i,1,103) rep(j,3) {
    a[0][j] += i;
    if( calc(a,r) <= 8 ) { mini = i; goto Skip; }
    a[0][j] -= i;
  }
 Skip:;

  if( mini == IINF ) {
    puts("Saiko");
  } else {
    cout << mini << endl;
  }
  return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>
int main(void)
{
  int a;
  
  scanf("%d",&a);
  
  if(a==25)
    printf("Christmas");
  else if(a==24)
    printf("Christmas Eve");
  else if(a==23)
    printf("Christmas Eve Eve");
  else if(a==22)
    printf("Christmas Eve Eve Eve");
  return 0;
}

Measured memory_bytes: 128
import sys
x, n = map(int, input().split())
arr = list(map(int, input().split()))

arr.sort()

if x not in arr:
    print(x)
    sys.exit()

ans = 1000
cnt = 0
while True:
    lower = x - cnt
    upper = x + cnt
    if lower not in arr:
        ans = min(ans, lower)
    if upper not in arr:
        ans = min(ans, upper)
    if ans != 1000:
        break
    cnt += 1

print(ans)

Measured memory_bytes: 9204
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[1])
arr=sorted(arr,key=lambda x:x[0])
ans=n
for i in range(n):
  for j in range(i+1,n):
    p,q=arr[j][0]-arr[i][0],arr[j][1]-arr[i][1]
    cnt=0
    flag=[0]*n
    for k in range(n):
      if flag[k]==1:
        continue
      flag[k]=1
      a,b=arr[k][0],arr[k][1]
      while 1:
        for l in range(n):
          if flag[l]==1:
            continue
          if a+p==arr[l][0] and b+q==arr[l][1]:
            flag[l]=1
            a=arr[l][0]
            b=arr[l][1]
            break
        else:
          break
      cnt+=1
    ans=min(ans,cnt)
print(ans)

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

int main(){
  int i,j,n,k,a[100000],b[100000],s,max;
  while(1){
    cin >> n >> k;
    if(n == 0 && k == 0) break;
    max = 0;
    s = 0;
    for(i=0;i<n;i++){
      cin >> a[i];

      s += a[i];
      b[i] = a[i];
      if(i >= k-1){
	if(max < s) max = s;
	s -= b[i-(k-1)];
      }
    }
    cout << max << endl;
  }
  return 0;
}

Measured memory_bytes: 1512
#include <iostream>
                                using namespace std;
                                #define ll long long
                                int main()
                                {
                                  int N;
                                  cin>>N;
                                  ll sum=0;
                                  ll arr[N];
                                  for (ll i=0;i<N;i++)
                                  {
                                    cin>>arr[i];
                                  }
                                  for (int i=1;i<N;i++)
                                  {
                                
                                    if (arr[i]<arr[i-1])
                                    {
                                     sum+=arr[i-1]-arr[i];
                                      arr[i]=arr[i-1];
                                    }
                       
                                  } 
                                  
                                  cout<<sum<<endl;
                         
                                }

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

int main() {
	int A, B, K;

	cin >> A >> B >> K;

	vector<int> cd;

	int minimum = min(A, B);


	for (int i = 1; i <= minimum; i++) {
		if (A % i == 0 && B % i == 0) {
			cd.push_back(i);
		}
	}

	cout << cd[cd.size() - K] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << endl
typedef unsigned long long ull;
typedef long long ll;
using namespace std;
const int N=100000;
int a,b,c;
int main()
{
	cin >>a>>b>>c;
	if(a+b+c==17)
	cout<<"YES";
	else
	cout << "NO";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FIN         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii          pair<int,int>
#define F           first
#define S           second
#define pb          push_back
#define all(x)      (x).begin(),(x).end()
#define rall(x)     (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a)   for(int i = a; i >= 0; i--)
#define fori(i,m)   for(auto i = m.begin(); i != m.end(); i++) 
#define w(t)        while(t--)
#define sz(s)       int(s.size())
#define cls(a,car)  memset(a,car,sizeof (a))
#define db(x)       cerr << #x << " is " << x << '\n'
#define FI          freopen("input.txt", "r", stdin)
#define FO          freopen("output.txt", "w", stdout)
#define EjecuteTime cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
#define angle(x)    double(x * acos(-1) / 180.0)
using namespace std;
typedef long long   ll;
typedef vector<int> vi;
typedef vector<ii>  vii;
const int N = 1e3 + 5;
const ll mod = 1e9 + 7;
const double E = 1e-6;
//int dx[] = {0, -1}, dy[] = {-1, 0};
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
//int dx[] = {2, 1, -1, -2, -2, -1, 1, 2}, dy[] = {1, 2, 2, 1, -1, -2, -2, -1};
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
char v[N][N];
int dis[N][N];
int n, m;
void bfs(int a, int b){
    deque<ii> q;
    dis[a][b] = 0;
    q.push_back({a, b});
    while(sz(q)){
        int x = q.front().F;
        int y = q.front().S;
        q.pop_front();
        for(int i = x - 2; i <= x + 2; i++)
            for(int j = y - 2; j <= y + 2; j++){
                if(v[i][j] == '.' && i >= 0 && i < n && j >= 0 && j < m){
                    int cost = abs(x - i) + abs(y - j);
                    if(cost == 1 && dis[x][y] < dis[i][j]){
                        q.push_front({i, j});
                        dis[i][j] = dis[x][y];
                    }else if(dis[x][y] + 1 < dis[i][j]){
                        q.push_back({i, j});
                        dis[i][j] = dis[x][y] + 1;
                    }
                }
            }
    }

}
void solve(){
    cin >> n >> m;
    int x, y, a, b;
    cin >> x >> y >> a >> b;
    x--;y--;a--;b--;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++){
            cin >> v[i][j];
            dis[i][j] = 1e9;
        }

    bfs(x, y);
    int ans = dis[a][b];
    if(ans == 1e9)
        ans = -1;
    cout << ans << '\n';
}
int main(){
    FIN;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    //EjecuteTime;
    return 0;
}       


Measured memory_bytes: 8580
a = list(input())
b = list(input())
c = list(input())

ia, ib, ic = -1, -1, -1
current = 'a'

while True:
    if current == 'a':
        ia += 1
        if ia == len(a):
            print('A')
            exit()
        current = a[ia]
    elif current == 'b':
        ib += 1
        if ib == len(b):
            print('B')
            exit()
        current = b[ib]
    elif current == 'c':
        ic += 1
        if ic == len(c):
            print('C')
            exit()
        current = c[ic]

Measured memory_bytes: 3064
n = int(input())

def digit(a):
    return sum(map(int,list(str(a))))

n2 = list(str(n))
ln = len(n2)
for i in range(ln-1,-1,-1):
    if n2[i] != "0":
        b = i
        break
if b == 0 and n2[0] == "1":
    print(10)
else:
    print(digit(n))
    


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

using namespace std;

bool isevenstring(string s){
	if(s.size()%2 == 0){
		string left = s.substr(0, s.size()/2);
		string right = s.substr(s.size()/2, s.size()/2);
		if(left == right) return true;
		else return false;
	}else{
		return false;
	}
}

int main(){
	string s; cin >> s;
	s.erase(s.size()-1);
	while(1){
		if(isevenstring(s)){
			cout << s.size() << endl;
			break;
		}else{
			s.erase(s.size()-1);
		}
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

/**
 * Main2
 */
public class Main {

    public static void main(String[] args) {


        Scanner input = new Scanner(System.in);
        String[] output = input.nextLine().split("");

        for (int i = 0; i < output.length - 1; i++) {
            if (output[i].equals(output[i + 1])) {
                System.out.println("Bad");
                System.exit(0);
            }
        }
        System.out.println("Good");
    }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Text;


namespace ConsoleApplication7
{
    class Program
    {
        static void Main(string[] args)
        {
           
                string[] s = Console.ReadLine().Split(' ');

                int a = int.Parse(s[0]);
                int b = int.Parse(s[1]);
                int c = int.Parse(s[2]);

                int n = 0;
                for(int x = a; x<=b; x++)
                {
                     if(c%x==0)
                    {
                       n++;
                     }
               
                 }

                Console.WriteLine(n);
                
            
        }
    }
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


li n, m;
string s, t;

map<li, char> mm[2];

inline li lcm(li x, li y) {
    return (x / __gcd(x, y)) * y;
}

int main() {
    cin >> n >> m;
    cin >> s >> t;

    li res = lcm(n, m);
    li step_n = res / n;
    rep(i, n) {
        mm[0][1 + i * step_n] = s[i];
    }
    li step_m = res / m;
    rep(i, m) {
        mm[1][1 + i * step_m] = t[i];
    }
    foreach (it, mm[0]) {
        if (mm[1][it->F] > 0) {
            if (mm[1][it->F] != it->S) {
                puts("-1");
                return 0;
            }
        }
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 15616
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        
        for (int i = 1; i < s.length() / 2 + 1; i++) {
            String s1 = s.substring(0, i);
            String s2 = s.substring(i, i + i);
            if(s1.equals(s2)){
                if(!s.equals(s1 + s2)) {
                    ans = i * 2;
                }
            }
        }
        
        System.out.println(ans);
        
    }
}


Measured memory_bytes: 39500
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

int main() {
    string S;
    cin >> S;

    int Q;
    cin >> Q;

    int cnt = 0;
    for (int i = 0; i < Q; ++i) {
        int t, f;
        string c;
        cin >> t;

        if (t == 1) {
            cnt++;
            continue;
        }

        if (t == 2) {
            cin >> f >> c;

            if (cnt % 2 == 1) {
                if (f == 1) {
                    S.append(c);
                }
                else {
                    S.insert(0, c);
                }
            }
            else {
                if (f == 1) {
                    S.insert(0, c);
                }
                else {
                    S.append(c);
                }
            }
        }
    }

    if (cnt % 2 == 1) reverse(S.begin(), S.end());
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 1028
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    N,K = LMIIS()
    H = LMIIS()
    count = 0
    for i in range(N):
        if H[i] >= K:
            count += 1
    print(count)

if __name__ == '__main__':
    main()

Measured memory_bytes: 51440
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  string w;
  cin >> w;

  vector<int> count(26);

  for (int i = 0; i < w.size(); ++i) {
    ++count[w[i] - 'a'];
  }

  for (int i = 0; i < 26; ++i) {
    if (count[i] % 2 != 0) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}

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

odd, four = 0, 0 
for x in a:
    if x % 2 == 1:
        odd += 1
    if x % 4 == 0:
        four += 1

two = n - odd - four
if two > 0:
    odd += 1
    
if four + 1 >= odd:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 19924
n = int(input())
a = list(map(int,(input().split())))
ans = 'APPROVED'
for i in a:
  if i%2==0:
    if i%3==0 or i%5==0:
      ans = 'APPROVED'
    else:
      ans = 'DENIED'
      break
    
print(ans)    

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

int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if ((abs(a - b) <= d && abs(b - c) <= d) || abs(a - c) <= d)cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
ary = m.times.map { |i| gets.split.map(&:to_i) + [i] }.sort
ans = Array.new(m)
prev_pref = nil
count = nil
ary.each do |pref, year, index|
  if pref != prev_pref
    count = 1
  end
  ans[index] = "%06d%06d" % [pref, count]
  prev_pref = pref
  count += 1
end
puts ans


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

int main() {
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  vector<int> x(N);
  for (int i=0; i<N; i++) {
    cin >> x.at(i);
  }
  vector<int> y(M);
  for (int j=0; j<M; j++) {
    cin >> y.at(j);
  }
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  if (x.at(N-1)<y.at(0) && x.at(N-1)<Y && X<y.at(0)) {
    cout << "No War" << endl;
  }
  else {
    cout << "War" << endl;
  }
}

Measured memory_bytes: 3556
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll [[maybe_unused]] = long long;
using ull [[maybe_unused]] = unsigned long long;
using ld [[maybe_unused]] = long double;

[[maybe_unused]] static constexpr int mod = (int)1e9 + 7;
[[maybe_unused]] static constexpr int inf = 100100100;
[[maybe_unused]] static constexpr ll linf = 1e18;
[[maybe_unused]] static constexpr double eps = 1e-9;
[[maybe_unused]] static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, a) for (ll i = a; i >= 0; --i)
#define all(obj) begin(obj), end(obj)
#define rall(obj) rbegin(obj), rend(obj)
#define pb push_back
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    if (N % K == 0) {
        cout << 0 << endl;
    } else {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include <algorithm>
using namespace::std;
int main(){

  int N;
  int X;
  cin>>N;
  cin>>X;
  int *L = new int[N];
  for(int i=0;i<N;i++){
    cin>>L[i];
  }
  int A=0;
  int count=1;
  for(int i=0;i<N;i++){
    A=A+L[i];
    if(A<X+1){
      count++;
    }
  }
    cout<<count;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int w[3],k[3],i,j;
	for(i=0; i<3; i++){
		scanf("%d",&w[i]);
	}
	if(w[0]<w[1]){
		j=w[0];
		w[0]=w[1];
		w[1]=j;
	}
	if(w[0]<w[2]){
		j=w[0];
		w[0]=w[2];
		w[2]=j;
	}
	if(w[1]<w[2]){
		j=w[1];
		w[1]=w[2];
		w[2]=j;
	}
	for(i=0; i<7; i++){
		scanf("%d",&j);
		if(j>w[0]){
			w[2]=w[1];
			w[1]=w[0];
			w[0]=j;
		}else if(j>w[1]){
			w[2]=w[1];
			w[1]=j;
		}else if(j>w[2]){
			w[2]=j;
		}
	}
	for(i=0; i<3; i++){
		scanf("%d",&k[i]);
	}
	if(k[0]<k[1]){
		j=k[0];
		k[0]=k[1];
		k[1]=j;
	}
	if(k[0]<k[2]){
		j=k[0];
		k[0]=k[2];
		k[2]=j;
	}
	if(k[1]<k[2]){
		j=k[1];
		k[1]=k[2];
		k[2]=j;
	}
	for(i=0; i<7; i++){
		scanf("%d",&j);
		if(j>k[0]){
			k[2]=k[1];
			k[1]=k[0];
			k[0]=j;
		}else if(j>k[1]){
			k[2]=k[1];
			k[1]=j;
		}else if(j>k[2]){
			k[2]=j;
		}
	}
	printf("%d %d\n",w[0]+w[1]+w[2],k[0]+k[1]+k[2]);
	return 0;
}

Measured memory_bytes: 596