akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <math.h> 
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
	ll ch[10][10];
int main() {
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++){
		ll now=i;
		ll mi=now%10;
		while(now/10!=0){
			now/=10;
		}
		ch[now][mi]++;
	}
	ll ans=0;
	for(ll i=1;i<=9;i++){
		for(ll j=1;j<=9;j++){
			ans+=ch[i][j]*ch[j][i];
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3644
n = input()
sl = input()
ans = 0
for i in range(1000):
    i_zero = str(i)
    i_zero = i_zero.zfill(3)
    if i_zero[0] in sl:
        a = sl.index(i_zero[0])+1
        if i_zero[1] in sl[a:]:
            a = sl[a:].index(i_zero[1])+a+1
            if i_zero[2] in sl[a:]:
                ans += 1
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

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

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}


signed main(void) {
    int h,w;
    cin >> h >> w;
    vector<vi> dp(h,vi(w));
    rep(i,h)rep(j,w)cin >> dp[i][j], dp[i][j] = 1 - dp[i][j];
    loop(i,1,h)loop(j,1,w)if(dp[i][j] == 1){
        dp[i][j] = min(min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1])+1;
    }
    int ans = 0;
    rep(i,h)rep(j,w)ans = max(ans,dp[i][j]);
    cout << ans*ans << endl;
}



Measured memory_bytes: 18108
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, m: usize, mut a: [usize; m]);
    let b = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6];
    a.sort();
    a.reverse();
    let mut dp = vec![None; n + 1];
    dp[0] = Some(0);
    let mut prev = vec![0; n + 1];
    for i in 0..(n + 1) {
        if let Some(dpi) = dp[i] {
            for &ai in a.iter() {
                let j = b[ai];
                if i + j > n {
                    continue;
                }
                dp[i + j] = match dp[i + j] {
                    Some(dpij) if (dpi + 1 <= dpij) => dp[i + j],
                    _ => {
                        prev[i + j] = i;
                        Some(dpi + 1)
                    }
                };
            }
        }
    }
    let mut ret = vec![];
    let mut cur = n;
    loop {
        for &ai in &a {
            if cur < b[ai] {
                continue;
            }
            if let Some(dpnext) = dp[cur - b[ai]] {
                if cur >= b[ai] && dpnext == dp[cur].unwrap() - 1 {
                    ret.push(ai);
                    cur = cur - b[ai];
                    break;
                }
            }
        }
        if cur == 0 {
            break;
        }
    }
    println!(
        "{}",
        ret.iter()
            .map(|&i| i.to_string())
            .collect::<Vec<_>>()
            .join("")
    );
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int MOD = 1000000007;
int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	vector<int> res(N);
	if (N % 2 == 0) {
		for (int i = 0; i < N; i++) {
			if (i % 2 == 0) {
				res[(N / 2) + i / 2] = a[i];
			}
			else {
				res[(N / 2) - (i+1) / 2] = a[i];
			}
		}
	}else{
		for (int i = 0; i < N; i++) {
			if (i % 2 == 0) {
				res[(N / 2) - i / 2] = a[i];
			}
			else {
				res[(N / 2) + (i + 1) / 2] = a[i];
			}
		}
	}
	for (int i = 0; i < N; i++) {
		if (i > 0) cout << " ";
		cout << res[i];
	}
	cout << endl;
	return 0;
	
}

Measured memory_bytes: 3712
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int n, key, A[100], j;

void print_table() {
	for (int i = 0; i < n; i++) {
		if (i)cout << ' ';
		cout << A[i];
	}
	cout << endl;
}

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)cin >> A[i];
	print_table();

	for (int i = 1; i < n; i++) {
		key = A[i];
		j = i - 1;

		while (j >= 0 && A[j] > key) {
			A[j + 1] = A[j];
			j--;
		}

		A[j + 1] = key;
		print_table();

	}
}


Measured memory_bytes: 3136
def resolve():
    n, m = map(int, input().split())
    xy = list(list(map(int, input().split())) for _ in range(m))
    ans = [0] * n
    for x, y in xy:
        ans[x - 1] += 1
        ans[y - 1] += 1
    for a in ans:
        print(a)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 38256
#include <iostream>
#include <string.h>

using namespace std;

int main()
{
    char s1[1001],s2[1001];
    int m[1001][1001],i,j;
    cin.getline(s1,1001);
    cin.getline(s2,1001);

    int x=strlen(s1);
    int y=strlen(s2);

    for(i=0;i<=x;++i)
    for(j=0;j<=y;++j)
       {
        if(i==0) m[i][j]=j;
        else if(j==0) m[i][j]=i;
        else if(s1[i-1]==s2[j-1]) m[i][j]=m[i-1][j-1];
        else m[i][j]=1+min(min(m[i][j-1],m[i-1][j]),m[i-1][j-1]);
       }

    cout<<m[x][y]<<'\n';

    return 0;
}

Measured memory_bytes: 5044
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <cassert>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'
#define FIR first
#define SEC second
#define PB push_back
#define SZ(x) ((int)x.size())

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

void solveSingleCase(int caseNo)
{
    string A, B;
    cin >> A >> B;
    int comp = 0;
    if (SZ(A) != SZ(B))
        comp = SZ(A) < SZ(B) ? -1 : 1;
    else if (A != B)
        comp = A < B ? -1 : 1;
    comp++;
    VEC(string) msg {"LESS", "EQUAL", "GREATER"};
    cout << msg[comp] << endl;
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int T = 1;
    // cin >> T;
    FOR(tcase, 1, T + 1) {
        solveSingleCase(tcase);
    }
    return 0;
};


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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 (b<a) { a=b; return 1;} return 0;}
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
/*----------------------------------------------------------------------------------*/


int main() {
    int h, w, n; cin >> h >> w >> n;
    cout << min((n+h-1)/h, (n+w-1)/w) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (isPrime(sc.nextInt())) {
                ans++;
            }
        }
        System.out.println(ans);
    }

    private static boolean isPrime(int num) {
        if (num < 2) {
            return false;
        } else if (num == 2) {
            return true;
        } else if (num % 2 == 0) {
            return false;
        }
        double sqrtNum = Math.sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2) {
            if (num % i == 0) {
                return false;
            }
        }
        return true;
    }

}



Measured memory_bytes: 41360
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String  str = scan.next();
		boolean flag = false;

		if(str.charAt(0)=='7')flag=true;
		if(str.charAt(1)=='7')flag=true;
		if(str.charAt(2)=='7')flag=true;

		System.out.println((flag)?"Yes":"No");
	}
}

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

s = input()

# print(s)
# brute force
rs = 0
gs = 0
bs = 0
for x in s:
    if x == 'R':
        rs += 1
    if x == 'G':
        gs += 1
    if x == 'B':
        bs += 1

i = 0
d = 1
count = 0
for i in range(0, n):
    d = 1
    while (i + 2*d < n):
        ok = s[i] != s[i+d] and s[i+d] != s[i+2*d] and s[i] != s[i+2*d]
        if ok:
            count += 1
        d += 1


print(rs * gs * bs - count)
# print(rs, gs, bs)

# count = 0
# for i in range(len(s)):
#     for j in range(i, len(s)):
#         for k in range(j, len(s)):
#             if (s[i] != s[j] and s[j] != s[k] and s[i] != s[k]):
#                 if j - i != k - j:
#                     count += 1
#                     # print(s[i], s[j], s[k])

# print(count)


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r, D;
  cin >> r >> D;
  vector<int> x(11);
  cin >> x.at(0);
  
  for (int i = 0; i < 10; i++) {
    x.at(i+1) = r * x.at(i) - D;
    cout << x.at(i+1) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

ll bigmod(ll a, ll p, ll m){
    ll res=1,x=a;
    while(p){
        if(p&1) res=(res*x)%m;
        x=(x*x)%m;
        p=p>>1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll n,sum=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i],sum+=a[i];
    ll ans=0;
    for(int i=0;i<n;i++){
        ll rem=(sum-a[i])%mod;
        rem=(rem*a[i])%mod;
        ans=(ans+rem)%mod;
    }
    ans=(ans*bigmod(2,mod-2,mod))%mod;
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;

const int N=2e5+100;
typedef pair<int,int>pa;
map<pa,int>mp;
ll ans[10];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n;cin>>n;
    ll x,y;
    cin>>x>>y;
    for(int i=2;i<=n;i++){
        ll a,b;
        cin>>a>>b;
        ll p=max((x/a+(x%a!=0)),(y/b+(y%b!=0)));
        x=a*p,y=b*p;
     //   cout<<x<<" "<<y<<endl;
    }
    cout<<x+y<<endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

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

    int n;
    while(cin>>n,n){
        vector<int> v(n);
        REP(i,n){
            string s; cin>>s;
            v[i]=s.size();
        }

        REP(i,n){
            int pos=i;
            int A[]={5,7,5,7,7};
            REP(j,5){
                int cnt=0;
                while(pos<n && cnt<A[j]) cnt+=v[pos++];
                if(cnt!=A[j]) goto g;
            }
            cout<<i+1<<endl;
            break;
        g:;
        }
    }
}



Measured memory_bytes: 3116
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
using namespace std;
using Data = pair<long long, vector<int> >;

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef pair<int,int> P_ii;
typedef pair<double,double> P_dd;
typedef long long int ll;
const int mod = 1e9+7;

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

    int a1 = stoi(s.substr(0,2));
    int a2 = stoi(s.substr(2,2));

    if ((a1 == 0 || a1 > 12) && (a2 == 0 || a2 > 12)) pl("NA")
    else if( (a1 >= 1 && a1 <= 12) && (a2 == 0 || a2 > 12)) pl("MMYY")
    else if( (a1 >= 1 && a1 <= 12) && (a2 >= 1 && a2 <= 12)) pl("AMBIGUOUS")
    else if( (a1 == 0 || a1 > 12)  && (a2 >= 1 && a2 <= 12)) pl("YYMM")
}

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

void Main()
{
  ll n; cin >> n;
  vector<ll> ans(n+1);
  for(ll x = 1; x*x <= n; x++) {
    for(ll y = 1; y*y <= n; y++) {
      for(ll z = 1; z*z <= n; z++) {
        ll incre = x*x + y*y + z*z + x*y + y*z + z*x;
        if (incre <=n) ans[incre]++;
      }
    }
  }
  for(int i = 1; i <= n; i++) {
    cout << ans[i] << endl;
  }
}

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


Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    ll N;
    cin >> N;
    map<ll,ll> M;
    
    for (ll i = 2; i*i <= N; i++) {
        while (N%i == 0) {
            M[i]++;
            N /= i;
        }
    }
    
    ll ans = 0;
    
    if(N != 1) M[N] = 1;
    
    for (pll p : M) {
        //cout << p.fi csp p.se << endl;
        ll a = 1;
        while (p.se >= a) {
            ans++;
            p.se -= a;
            a++;
        }
    }
    
    cout << ans << endl;
    

    return 0;
}


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

using namespace std;

string S;
int dp[512][512];

bool solve(int l, int r)
{
  if(~dp[l][r]) return dp[l][r];
  if(l == r) return dp[l][r] = 1;
  if(S[l] != 'm' || S[r-1] != 'w') return dp[l][r] = 0;
  int ret = 0;
  for(int m = l+1; m < r-1; m++){
    if(S[m] == 'e'){
      ret |= solve(l+1, m) & solve(m+1, r-1);
    }
  }
  return dp[l][r] = ret;
}

int main()
{
  cin >> S;
  fill(dp[0], dp[512], -1);
  if(solve(0, S.size())) cout << "Cat" << endl;
  else cout << "Rabbit" << endl;
  return 0;
}

Measured memory_bytes: 2220
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int n; cin >> n;
    vector<string> s(n); rep(i,n) cin >> s[i];
    int m; cin >> m;
    vector<string> t(m); rep(i,m) cin >> t[i];

    int ans = 0;

    rep(i,n){
        int point = 0;
        string tmp = s[i];

        rep(j,n){
            if(s[i] == s[j]) point++;
        }

        rep(j,m){
            if(s[i] == t[j]) point--;
        }

        ans = max(ans,point);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()

R = s.count('R')
G = s.count('G')
B = s.count('B')

ans = R*G*B

for i in range(n-2):
    for j in range(i+1,n-1):
        k = j*2-i
        if k<n:
            if s[i]!=s[j]!=s[k]!=s[i]:
                ans -=1
print(ans)

Measured memory_bytes: 68204
m = int(input())
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
x = make_divisors(360)

#最大公約数
def gcd(a,b):
    if(b>a):
        a,b=b,a
    i=b
    while i>0:
        if(a%i==0 and b%i==0):
            return i
        i-=1

#最小公倍数
def lcm(a,b):
    return int(a*b/gcd(a,b))

y = lcm(m,360)

if m in x:
    print(360//m)
else:
    print(y//m)

Measured memory_bytes: 9024
#include <stdio.h>

int main() {
	int X, Y;
	scanf("%d%d", &X, &Y);
	if (Y % 2 != 0) {
		printf("No\n");
	} else if (Y < 2 * X || 4 * X < Y) {
		printf("No\n");
	} else {
		printf("Yes\n");
	}
	return 0;
}


Measured memory_bytes: 1660
#include <cassert>
    #include <iostream>
     
    using namespace std;
     
    const int pows[] = {1, 10, 100, 1000, 10000, 100000, 1000000,
                        10000000, 100000000, 1000000000};
     
    const int MOD = 1000000007;
    const int THRESHOLD = 8;
     
    int main() {
        ios::sync_with_stdio(false);
     
        int S;
        cin >> S;
     
        int start = 1, end = 1;
        int s_idx = 1, e_idx = 1;
        
        long long sum = 0;
        long long ans = 0;
        
        while (start < pows[THRESHOLD-1]) {
            while (sum < S) {
                sum += e_idx;
                end++;
                if (end == pows[e_idx])
                    e_idx++;
            }
            
            if (sum == S)
                ans++;
            
            sum -= s_idx;
            start++;
            if (start == pows[s_idx])
                s_idx++;
        }
     
        long long num = 9LL * pows[THRESHOLD-1];
        
        for (int digits = THRESHOLD; digits <= S; digits++) {
            // All f(x) = digits
            if (S % digits == 0) {
                int select = S/digits;
                ans += num - select + 1;
                if (ans >= MOD)
                    ans -= MOD;
            }        
            num = num * 10 % MOD;
     
            // Some f(x) = digits and some f(x) = digits+1
            int ell = S % digits;
            if (ell == 0)
                ell = digits;
            
            long long val = S - (long long)ell*(digits+1);
            assert(val % digits == 0);
     
            if (val > 0) {
                ans += 1 + (val-1)/(digits*(long long)(digits+1));
                if (ans >= MOD)
                    ans -= MOD;
            }
        }
     
        cout << ans << endl;
    }

Measured memory_bytes: 256
#!/usr/bin/env python3
N, M, X, Y = [int(str) for str in input().strip().split()]
xs = [int(str) for str in input().strip().split()]
ys = [int(str) for str in input().strip().split()]

ans = False

for z in range(max(xs) + 1, min(ys) + 1):
    if X < z <= Y:
        ans = True

print('No War' if ans else 'War')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,k;
bool a[maxn];
string s;
int main()
{
	int i,j,num=0;
	ios::sync_with_stdio(0);
	cin>>n>>k>>s;
	int len=s.length();
	for(i=1;i<=len;i++){a[i]=s[i-1]=='R';}
	a[0]=1;a[len+1]=0;
	for(i=1;i<=n;i++){
		if(a[i]==0&&a[i-1]==1){continue;}
		if(a[i]==1&&a[i+1]==0){continue;}
		num++;
		//cout<<i<<endl;
	}
	//cout<<num<<endl;
	cout<<min(num+2*k,n-1)<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

struct Data
{
	int ty, tx, ky, kx, c;
	Data(int ty, int tx, int ky, int kx, int c) : ty(ty), tx(tx), ky(ky), kx(kx), c(c){}
};

bool visited[50][50][50][50];
int main()
{
	int w, h;
	while(scanf("%d%d", &w, &h), w){
		rep(i, h) rep(j, w) rep(k, h) rep(l, w)
			visited[i][j][k][l] = false;
		
		int ty, tx, ky, kx;
		scanf("%d%d%d%d", &tx, &ty, &kx, &ky);
		int depart[50][50];
		rep(i, h) rep(j, w)
			scanf("%d", &depart[i][j]);
		
		queue<Data> Q;
		Q.push(Data(ty-1, tx-1, ky-1, kx-1, 0));
		int ans = -1;
		while(!Q.empty()){
			Data d = Q.front();
			Q.pop();
			if(d.ty==d.ky && d.tx==d.kx){
				ans = d.c;
				break;
			}
			if(visited[d.ty][d.tx][d.ky][d.kx])
				continue;
			visited[d.ty][d.tx][d.ky][d.kx] = true;
			
			const int dy[] = {-1, 0, 1, 0};
			const int dx[] = {0, -1, 0, 1};
			rep(i, 4){
				int pty = d.ty + dy[i];
				int ptx = d.tx + dx[i];
				if(pty<0 || h<=pty || ptx<0 || w<=ptx || depart[pty][ptx]){
					pty = d.ty;
					ptx = d.tx;
				}
				int pky = d.ky - dy[i];
				int pkx = d.kx - dx[i];
				if(pky<0 || h<=pky || pkx<0 || w<=pkx || depart[pky][pkx]){
					pky = d.ky;
					pkx = d.kx;
				}
				if(d.c+1 < 100)
					Q.push(Data(pty, ptx, pky, pkx, d.c+1));
			}
		}
		if(ans == -1)
			puts("NA");
		else
			printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 8396
#include <stdio.h>
#include <string.h>
int main(void){
  char s[11];
  scanf("%s",s);
  if(strcmp("hi", s) == 0 || strcmp("hihi", s) == 0 || strcmp("hihihi", s) == 0 || strcmp("hihihihi", s) == 0 || strcmp("hihihihihi", s) == 0)puts("Yes");
  else puts("No");
  return 0;
}

Measured memory_bytes: 128
import math

N, D = list(map(int, input().split()))
location = []
for i in range(N):
	location.append(list(map(int, input().split())))

count = 0

for i in range(N):
	distance = math.sqrt(location[i][0]*location[i][0] + location[i][1]*location[i][1])
	if distance <= D:
		count += 1
print(count)

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

int main(){
  int c[3][3];
  rep(i,3)rep(j,3) cin>>c[i][j];
  bool flag=true;
  rep(i,2){
    if(!((c[i+1][0]-c[i][0])==(c[i+1][1]-c[i][1])&&(c[i+1][1]-c[i][1])==(c[i+1][2]-c[i][2]))) flag=false;
  }
  rep(i,2){
    if(!((c[0][i+1]-c[0][i])==(c[1][i+1]-c[1][i])&&(c[1][i+1]-c[1][i])==(c[2][i+1]-c[2][i]))) flag=false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cerr<<#x<<" = "<<x<<endl;
#define pb push_back
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define bump cout<<"bleh\n"
#define all(v) (v).begin(),(v).end()

//#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>

using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;
const ll infll=1e15;


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

    int n,sum=0;
    cin>>n;
    int ara[n];
    for(int i=0;i<n;i++){
        cin>>ara[i];
        sum+=ara[i];
    }



    int x=(sum+n-1)/n;

    //cout<<x<<"\n";

    ll ans1=0, ans2=0;

    for(int i=0;i<n;i++){

        int y=abs(ara[i]-x);
        ans1+= y*y;

        y=abs(ara[i]-(x-1));
        ans2+= y*y;
    }



    cout<<min(ans1,ans2)<<"\n";

    return 0;
}


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

using namespace std;

int main(){
        int H, W;
        string str[100];
        cin>>H>>W;
        for(int i=0;i<H;i++){
                cin>>str[i];
        }
        for(int i=0;i<H;i++){
                cout<<str[i]<<endl<<str[i]<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 
#define digits(n) (int)(log10(n) + 1)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/********** TEMPLATE ENDS HERE ***********/

#define int long long

main()
{
	IOS
	
	int n, k;
	cin >> n >> k;
	
	int nr = 0;
	
	for(int i = k + 1; i <= n; i++)
	{
		int r = n % i;
		
		if(r >= k)
		{
			nr += (i - k) * (n - r) / i + r - k + 1;
			
			if(k == 0)
				nr--;
        }
		else
		{
			nr += (i - k) * (n - r) / i;
		}
	}
	
	cout << nr;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/agc014_a.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll a, b, c;
  cin >> a >> b >> c;

  ll cnt = 0;
  while ((a % 2 == 0 && b % 2 == 0 && c % 2 == 0) && cnt < 100) {
    ll _a = (b + c) / 2;
    ll _b = (a + c) / 2;
    ll _c = (b + c) / 2;
    a = _a;
    b = _b;
    c = _c;
    cnt++;
  }

  cout << (a % 2 == 0 && b % 2 == 0 && c % 2 == 0 ? -1 : cnt) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int N = 100010;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
typedef pair<int,int> P;
typedef long long ll;
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(auto &t:a)cin>>t;return i;}
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T> void prArr(T a,string s=" "){int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  int n;
  cin>>n;
  vector<int>A(n);
  cin>>A;

  auto calcCost=[](vector<int> A,int num){
    int n = A.size();
    int res = 0;
    for(int i=0;i<n;i++) res += (num - A[i]) * (num - A[i]);
    return res;
  };
  
  int ans = INF;
  for(int i=-300;i<300;i++) Min(ans,calcCost(A,i));
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int main()
{
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
	//printf((a<=c&&c<=b) ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';
 
typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

inline ll add(ll a, ll b){
  return ((a % mod) + (b % mod)) % mod;
}
inline ll sub(ll a, ll b){
  return ((a % mod) - (b % mod) + mod) % mod;
}
inline ll mul(ll a, ll b){
  return ((a % mod) * (b % mod)) % mod;
}
inline ll modexpo(ll a, ll b){
  ll res = 1;
  while(b){
    if(b & 1){
      res = mul(res, a);
    }
    a = mul(a, a);b /= 2;
  }
  return res;
}
inline ll divide(ll a, ll b){
  return mul(a, modexpo(b, mod - 2));
}
 
clock_t time_p = clock();
 
void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}
  
int main(){
  fastio
  ll n, m;
  cin >> n;
  cout << (n * (n - 1)) / 2 << '\n';
  ktj();
}

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

using namespace std;

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

    int x = 0, x_max = 0;
    for (int i = 0; i < n; i++) {
        x += (s[i] == 'I' ? 1 : -1);
        x_max = max(x_max, x);
    }

    cout << x_max << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
    int a, b, c, d, i, j, n;
    int count = 0;
    scanf("%d100000", &a);
    if(a == 100000){
        count = 90909;
    }else if(a >= 10000){
        count += a - 9999;
        count += 900;
        count += 9;
    }else if(a >= 1000){
        count += 900;
        count += 9;
    }else if(a >= 100){
        count += a - 99;
        count += 9;
    }else if(a >= 10){
        count += 9;
    }else{
        count = a;
    }
    
    printf("%d\n", count);
    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define D_SIZE_BUFF 200

int main()
{
    char s[D_SIZE_BUFF];
    char *hare = "Sunny", *kumo = "Cloudy",*ame = "Rainy"; 

    scanf("%s", s);
    if(s[0] == 'S') printf("%s\n",kumo);
    if(s[0] == 'C') printf("%s\n",ame);
    if(s[0] == 'R') printf("%s\n",hare);

    return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    auto cswap = [] (int& x, int& y) { if (x > y) { int tmp = x; x = y;  y = tmp; } };
    cswap(a, b);
    cswap(b, c);
    cswap(a, b);
    cout << a << " " << b << " " << c << endl; 
}

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

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

using namespace std;

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

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

  int result = 0;
  rep(i, n) {
    while (a[i] % 2 == 0) {
      a[i] /= 2;
      result++;
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#define SIZE 100001
#define INF INT_MAX >> 1

using namespace std;

int dp[SIZE][3];

int main(void){
	int n; cin >> n;
	static int abc[SIZE][3];
	for(int i=0; i<n; i++){
		cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
	}

	fill(dp[0], dp[SIZE], 0);
	//配るDP
	for(int i=0; i<n; i++){
		for(int from=0; from<3; from++){
			for(int to=0; to<3; to++){
				if(from != to){
					dp[i+1][to] = max(dp[i+1][to], dp[i][from]+abc[i][to]);
				}
			}
		}
	}

	int ans = -1;
	for(int j=0; j<3; j++){
		ans = max(ans, dp[n][j]);
	}
	cout << ans << endl;
}

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

int main() {
    int n, c;
    int d[35][35];
    int t[5][35];

    cin >> n >> c;
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < c; j++) {
            cin >> d[i][j];
        }
    }

    int x;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            //色の入力
            cin >> x;
            //初期の色を数える
            t[(i + j) % 3][x - 1]++;
        }
    }

    int res = 1 << 30;
    for (int i = 0; i < c; i++) {
        for (int j = 0; j < c; j++) {
            if (i != j) {
                for (int k = 0; k < c; k++) {
                    if (i != k && j != k) {
                        int tt = 0;
                        for (int l = 0; l < c; l++) tt += d[l][i] * t[0][l];
                        for (int l = 0; l < c; l++) tt += d[l][j] * t[1][l];
                        for (int l = 0; l < c; l++) tt += d[l][k] * t[2][l];
                        if (tt < res) res = tt;
                    }
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

inline int main1();

int main() {

	main1();

	return 0;
}

inline int main1() {

	string s;

	cin >> s;

	cout << s.substr(0,s.length()-8);

	return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
from heapq import heapify, heappop, heappush
import math
import random
import string
from copy import deepcopy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 998244353

#############
# Main Code #
#############

T1, T2 = getNM()
A1, A2 = getNM()
B1, B2 = getNM()

# グラフにして考える
# 周期は同じT1, T2
# T1の時とT2の時とで順位が入れ替わっているなら出会っている
t1_diff = (A1 - B1) * T1
t2_diff = (A1 - B1) * T1 + (A2 - B2) * T2
if t1_diff == 0 or t2_diff == 0: # 無限に出会う
    print('infinity')
    exit()
if t1_diff * t2_diff > 0: # ずっとどちらかが前にいる
    print(0)
    exit()

# t2_diff分ずつずれていく

# 順位が逆転する場合
# クロスする時とちょうど接する時を考える
if abs(t1_diff) % abs(t2_diff) == 0:
    # 最後の１回は１回しかクロスしない
    print((abs(t1_diff) // abs(t2_diff)) * 2)
else:
    print((abs(t1_diff) // abs(t2_diff)) * 2 + 1)

Measured memory_bytes: 77996
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>


int main(void)
{
	int N;
	scanf("%d", &N);
	N = 1000 - (N % 1000);
	if ((N % 1000) == 0)
	{
		N = 0;
	}
	printf("%d",N);
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int main() {
  string S, A;
  cin >> S >> A;
  int ans = 0;
  for (int  i = 0; i < 3; i++){
    if (S[i] == A[i]) {
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>

#define inf 1000000007

using namespace std;

vector<vector<int> > connect;
vector<int> visited;
int n;

void dfs(int start,int c){
	stack<int> st;
	st.push(start);
	while(!st.empty()){
		int k = st.top();
		visited[k] = c;
		st.pop();
		for(int i=0;i<connect[k].size();++i){
			int tmp = connect[k][i];
			if(visited[tmp]==-1){
				st.push(tmp);
			}
		}
	}
}

int main(){
	int m,q;
	cin >> n >> m;
	connect.resize(n);
	visited.resize(n);
	for(int i=0;i<m;++i){
		int s,t;
		cin >> s >> t;
		connect[s].push_back(t);
		connect[t].push_back(s);
	}
	int c = 0;
	for(int i=0;i<n;++i)visited[i] = -1;
	for(int i=0;i<n;++i){
		if(visited[i] == -1){
			dfs(i,c);
			c++;
		}
	}
	cin >> q;
	vector<bool> res(q);
	for(int i=0;i<q;++i){
		int from,to;
		cin >> from >> to;
		if(visited[from] == visited[to]){
			res[i] = true;
		}else{
			res[i] = false;
		}
	}
	for(int i=0;i<q;++i){
		if(res[i])cout << "yes" << "\n";
		else cout << "no" << "\n";
	}
}


Measured memory_bytes: 8696
#include<bits/stdc++.h>
#include<cmath>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1000000007;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
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 (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) cout << (x) << endl;
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

const int INF = 1e9;
const ll LLINF = 1e16;
 
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
 
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

// 割り算の切り上げ処理
template<typename T>
T round_up(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

ll dp[10100][10100];
int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    ll n,k;
    cin >> n >> k;
    vector<ll> p(n);
    vector<double> s(n+1, 0);
    rep(i,n) cin >> p[i];
    rep(i,n) s[i+1] = s[i] + (1.5 + ((p[i] - 2) * 0.5));
    double ans = 0.0;
    rep(i,n){
      if(k+i > n) break;
      double val = s[k+i] - s[i];
      chmax(ans, val);
    }
    print(ans);

}


Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n;
llong t[128];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> t[i];

    llong mul = 1;
    for (int i = 0; i < n; i++) {
        mul = mul / __gcd(mul, t[i]) * t[i];
    }

    cout << mul << endl;

    return 0;
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input =new BufferedReader(new InputStreamReader(System.in));
        String[] firstLine = input.readLine().split(" ");
        int H = Integer.parseInt(firstLine[0]);
        int W = Integer.parseInt(firstLine[1]);

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < H; i++) {
            String line = input.readLine();
            if (i == 0) {
                builder.append(line);
                builder.append("\n");
                builder.append(line);
            } else {
                builder.append("\n");
                builder.append(line);
                builder.append("\n");
                builder.append(line);
            }

        }

        System.out.println(builder.toString());

    }
}


Measured memory_bytes: 21076
#include <stdio.h>
#include <string.h>
 
int main(void) {
	char taro[101], hanako[101];
	int n, tp = 0, hp = 0;
	int tlen, hlen, i;
	
	scanf("%d", &n);
	
	while (n--){
		scanf("%s %s", taro, hanako);
		if (strcmp(taro, hanako) == 0){
			tp++;
			hp++;
		}
		else {
			tlen = strlen(taro);
			hlen = strlen(hanako);
			
			if (tlen > hlen){
				for (i = 0; i < tlen; i++){
					if (taro[i] > hanako[i]){
						tp += 3;
						break;
					}
					if (hanako[i] > taro[i]){
						hp += 3;
						break;
					}
				}
			}
			else {
				for (i = 0; i < hlen; i++){
					if (taro[i] > hanako[i]){
						tp += 3;
						break;
					}
					if (hanako[i] > taro[i]){
						hp += 3;
						break;
					
					}
				}
			}
		}
	}
	
	printf("%d %d\n", tp, hp);
	
	return 0;
}

Measured memory_bytes: 604
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func read() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(read())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(read())
	}
	sort.Sort(sort.IntSlice(a))
	mid := n / 2
	fmt.Println(a[mid] - a[mid-1])
}

Measured memory_bytes: 2048
n = int(input())
a = list(map(int,input().split()))
a.append(0)
sm = 0
for i in range(n+1):
  sm += abs(a[i] - a[i-1])
for i in range(n):
  print(sm + abs(a[i+1] - a[i-1]) - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]))

Measured memory_bytes: 20576