akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n;
  cin >> n;
  vector<ll> vec(n);
  rep(i, n) cin >> vec[i];
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  vector<ll> seq;
  ll ans = vec[0];
  for(int i = 1; i < n; i++) {
    seq.push_back(vec[i]);
    seq.push_back(vec[i]);
  }
  rep(i, n-2) {
    ans += seq[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9020
import sys
l = sys.stdin.readline().strip()
N = int(l)
l = sys.stdin.readline().strip()
nums = list(map(int, l.split()))
a = sum(nums) / len(nums)
a1 = int(a)
a2 = int(a) + 1
def count(p):
    d = 0
    for n in nums:
        d += (n-p)**2
    return d
print(min(count(a1), count(a2)))


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

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

    std::vector<int> alpha(26, 0);
    std::string input;
    while(std::cin >> input){
        for(auto& c : input){
            if(c>='A' && c<='Z') c+='a'-'A';
            if(c>='a' && c<='z') ++alpha[c-'a'];
        }
    }
    for(int i=0; i<26; ++i){
        std::cout << static_cast<char>('a'+i) << " : " << alpha[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3152
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N, M, Count[int(1e5 + 5)];
int A, B;

int main(){
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++){
    scanf("%d%d", &A, &B);
    Count[A]++; Count[B]++;
  }
  
  for (int i = 2; i <= N; i++){
    if (Count[i] % 2 != 0){
      NO(); return 0;
    }
  }
  YES();

  return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s;
	cin >> s;

	ll ans = 0, bCnt = 0;
	for (int i = 0; i < (int)s.size(); i++) {
		if (s[i] == 'B') {
			bCnt++;
			continue;
		}

		ans += bCnt;
	}

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


Measured memory_bytes: 720
#include <stdio.h>
#include <stdlib.h>

#define MAX_N 101000
#define SWAP( a, b ) do { int tmp; tmp = a; a = b; b = tmp; } while( 0 )

int isPrime[ MAX_N + 1 ] = { 0, 0, 1 };

void quickSort( int *, int, int );
int median( int, int, int );
void insertionSort( int *, int );

int main( void ) {
	int i, j, N, P, cnt, p[ 22 ], sum[ 253 ];

	for ( i = 3; i <= MAX_N; i += 2 )
		isPrime[ i ] = 1;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	for ( ; scanf( "%d %d", &N, &P ), N != -1; printf( "%d\n", sum[ P - 1 ] ) ) {
		cnt = 0;
		for ( i = N + 1; cnt < 22; i++ )
			if ( isPrime[ i ] )
				p[ cnt++ ] = i;

		cnt = 0;
		for ( i = 0; i < 22; i++ )
			for ( j = i; j < 22; j++ )
				sum[ cnt++ ] = p[ i ] + p[ j ];

		quickSort( sum, 0, 252 );
	}

	return 0;
}

void quickSort( int *data, int l, int r ) {
	if ( l < r ) {
		int i = l, j = r, pivot = median( data[ i ], data[ ( i + j ) / 2 ], data[ j ] );

		while ( 1 ) {
			for ( ; data[ i ] < pivot; i++ ) ;
			for ( ; pivot < data [ j ]; j-- ) ;
			if ( i >= j )
				break;

			SWAP( data[ i ], data[ j ] );

			i++;
			j--;
		}

		if ( i - l < 20 )
			insertionSort( data + l, i - l );
		else
			quickSort( data, l, i - 1 );

		if ( r - j < 20 )
			insertionSort( data + j + 1, r - j );
		else
			quickSort( data, j + 1, r );
	}
}

int median( int x, int y, int z ) {
	if ( x < y )
		if ( y < z )
			return y;
		else if ( z < x )
			return x;
		else
			return z;
	else if ( z < y )
		return y;
	else if ( x < z )
		return x;
	else
		return z;
}

void insertionSort( int *data, int n ) {
	int i, j, tmp;

	for ( i = 1; i < n; i++ ) {
		tmp = data[ i ];

		for ( j = i; j && data[ j - 1 ] > tmp; j-- )
			data[ j ] = data[ j - 1 ];

		data[ j ] = tmp;
	}
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b,c,d;
int main() {
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while (a&&c) {
		c-=b;
		if (c<=0) {
			puts("Yes");
			return 0;
		}
		a-=d;
		if (a<=0) {
			puts("No");
			return 0;
		}
	}
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,t,x,y;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t>>x>>y;
        if(!(x+y<=t&&(t-x-y)%2==0)){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cmath>
#include<tuple>
#include<string>
typedef unsigned long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define F first
#define S second
using namespace std;
const ll INF = 1e12;
const int i_INF = 2147483647;

int main() {
  char s;
  cin>>s;
  if(s=='A')cout<<"T";
  else if(s=='T')cout<<"A";
  else if(s=='G')cout<<"C";
  else cout<<"G";
}

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

int main()
{
	string s;

	cin >> s;

	//4文字
	char c1 = s[0];
	char c2 = 'a';
	int cnt1 = 0;
	int cnt2 = 0;
	for (int i = 0; i < 4; i++) {

		if (c1 != s[i] && c2 == 'a') {
			c2 = s[i];
			cnt2++;

		}else if (c1 == s[i]) {
			cnt1++;
		}
		else if (c2 == s[i]) {

			cnt2++;
		}

	}

	if (cnt1 == 2 && cnt2 == 2) {
		cout << "Yes";
	}
	else {

		cout << "No";
	}


}

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

int main(){
    int k;
    int n;
    int pivot;
    int *array;
    int i;
    int tmp;

    scanf("%d",&n);
    array=malloc(sizeof(int)*n);
    for(int i=0;i<n;i++){
        scanf("%d",&array[i]);
    }

    pivot=array[n-1];
    i=-1;
    for(int j=0;j<n-1;j++){
        if(array[j]<=pivot){
            i=i+1;
            tmp=array[i];
            array[i]=array[j];
            array[j]=tmp;
        }
    }
    tmp=array[i+1];
    array[i+1]=array[n-1];
    array[n-1]=tmp;

    for(k=0;k<n-1;k++){
        if(k==i+1)
            printf("[%d] ",array[k]);
        else
            printf("%d ",array[k]);
    }
    printf("%d\n",array[k]);

    return 0;

}



Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007LL;
vector<ll> f,fi;
ll mpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1){
			res*=x;
			res%=MOD;
		}
		x=x*x%MOD;
		n>>=1;
	}
	return res;
}
void init(int n){
	f.resize(n+1);
	fi.resize(n+1);
	f[0]=1;
	for(ll i=1;i<=n;i++){
		f[i]=f[i-1]*i;
		f[i]%=MOD;
	}
	fi[n]=mpow(f[n],MOD-2);
	for(ll i=n-1;i>=0;i--){
		fi[i]=fi[i+1]*(i+1LL);
		fi[i]%=MOD;
	}
}
ll ncr(ll n,ll r){
	if(n<r){
		return 0;
	}
	if(r==0){
		return 1;
	}
	return f[n]*fi[r]%MOD*fi[n-r]%MOD;
}
int main(){
	ll n,A,B,C;cin>>n>>A>>B>>C;
	if(B%2){
		cout<<0<<endl;
		return 0;
	}
	init(3*n+10);
	ll ans=0;
	for(ll b=0;b<=n/2;b++){
		for(ll d=0;d<=n/3;d++){
			ll c=B/2;
			ll a=A-b;
			ll x=C-b-3*d;
			if(x<0||a<0){
				continue;
			}
		//	cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<x<<endl;
			ll sum=a+b+c+d;
			ll s=ncr(sum,a)*ncr(sum-a,b)%MOD*ncr(sum-a-b,c)%MOD;
			if(c>0){
				s*=ncr(x+c-1,x);
				s%=MOD;
			}else if(x>0){
				s=0;
			}
			ans+=s;
			ans%=MOD;
		}
	}
	cout<<ans<<endl;	
}


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

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

    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= N; j++) {
            if (i + j > N) continue;
            int k = N - i - j;
                if ((10000 * i + 5000 * j + 1000 * k) == Y) {
                    cout << i << ' ' << j << ' ' << k;
                    return 0;
                }
        }
    }
    cout << "-1 -1 -1";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=1e5+5;
int32_t main()
{
	IOS;
	int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1]<<endl;



	



	
}

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

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

    for (int i = k; i < n; ++i) {
        if (a[i] > a[i - k])
            cout << "Yes";
        else
            cout << "No";
        cout << "\n";
    }

    return 0;
}

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

int main() {
  int n, a[100001] = {}, cnt = 0, t;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> t;
    a[i] = t;
    if (a[t] == i) ++cnt;
  }
  cout << cnt << '\n';
  return 0;
}

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

using System.Collections;

class Program
{
    static void Main()
    {
        int[] nx = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

        int N = nx[0];
        int X = nx[1];

        long[] x = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();

        //スタート地点から各都市への距離のリスト
        long[] a = x.Select(n => (long)(Math.Abs(n - X))).ToArray();

        //各都市への距離の最大公約数を求めれば良い
        long ans = a[0];
        foreach(var itm in a)
        {
            ans = calcGCD(ans, itm);
        }

        Console.WriteLine(ans);
    }

    static long calcGCD(long num1, long num2)
    {
        if(num1 < num2)
        {
            var tmp = num1;
            num1 = num2;
            num2 = tmp;
        }

        while(true)
        {
            long res;
            long div = Math.DivRem(num1, num2, out res);

            if (res == 0)
            {
                return num2;
            }
            else
            {
                num1 = num2;
                num2 = res;
            }
        }
    }
}


static class MathUtil
{
    public static T Max<T>(params T[] datas)
    {
        return datas.Max();
    }

    public static T Min<T>(params T[] datas)
    {
        return datas.Min();
    }

    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}




Measured memory_bytes: 23520
#include <stdio.h>
int main(void){
    char S[11],T[11],U[11];
    int A=0,B=0;
    scanf("%s %s",S,T);
    scanf("%d %d",&A,&B);
    scanf("%s",U);
    for(int i=0; ; i++){
        if(*S+i!=*U+i){
            B--;
            break;
        }
        if(*T+i!=*U+i){
            A--;
            break;
        }
    }
    printf("%d %d",A,B);
    return 0;
}

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

int main(){
    int n,k;cin >>n>>k;
  cout << n-k+1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

// based on: https://codeforces.com/blog/entry/3107

// z(s) = x is max s.t. T[0..x] = T[n - x..]
fn z(T: &[char]) -> Option<usize> {
    let n = T.len();

    // z[i] = z (i > 0) where
    //   z is max s.t. T[0..z] = T[i..i + z]
    let mut z = vec![0; n];

    // z-algorithm
    let mut l = 0;
    let mut r = 0;
    for i in 1..n {
        if i >= r {
            l = i;
            r = l;
            while r < n && T[r - l] == T[r] {
                r += 1;
            }
            z[i] = r - l;
            continue;
        }

        let k = i - l;
        if z[k] < r - i {
            z[i] = z[k];
            continue;
        }

        l = i;
        while r < n && T[r - l] == T[r] {
            r += 1
        }
        z[i] = r - l;
    }

    // debug!(z);

    (1..n).map(|k| min(k, z[k])).max()
}

fn main() {
    read!(usize);
    let S = rl().chars().collect::<Vec<_>>();

    let mut m = 0_usize;

    for i in 0..S.len() {
        m = max(m, z(&S[i..]).unwrap_or(m));
    }

    println!("{}", m)
}


Measured memory_bytes: 4476
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	ll N; int K;
	cin >> N >> K;
	int res = 0;
	while (N) {
		++res; N /= K;
	}
	cout << res << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

const ll MOD = 1e9 + 7;

ll a, b;

ll get(ll x, ll y) {
  ll res = 1LL;
  while(y) {
    if(y & 1) res = (res * x) % MOD;
    y >>= 1;
    x = (x * x) % MOD;
  }
  return res;
}

ll ncr(ll n, ll r) {
  ll cur = 1LL;
  for(ll i = 1; i <= r; i++) {
    cur = (cur * (n + 1 - i)) % MOD;
    cur = (cur * get(i, MOD - 2)) % MOD;
  }
  return cur;
}

int main() {
  ll n; read(n);
  read(a, b);
  ll cur = (get(2LL, n) - 1) % MOD;
  if(cur < 0) cur += MOD;
  cur = (cur - ncr(n, a)) % MOD;
  if(cur < 0) cur += MOD;
  cur = (cur - ncr(n, b)) % MOD;
  if(cur < 0) cur += MOD;
  print(cur);
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
		
		String[] a = new String[sc.nextInt()];
		for(int i = 0; i < a.length; i++)
			a[i] = sc.next();
		
		Arrays.sort(a);
		
		int n = 0;
		for(int i = 0; i < a.length; i++)
			if(i == a.length - 1 || !a[i].equals(a[i + 1]))
				n++;
		System.out.println(n);
		
		sc.close();
    }
}

Measured memory_bytes: 70308
//NEW SOLUTION
#include <iostream>
#include <vector>
#include <cmath>
#include <set>
#include <queue>
#include <map>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <algorithm>
#include <limits.h>
#include <bits/stdc++.h>
#define fw(x) freopen("x.txt","w",stdout)
#define For(i,a,b,c) for(int i = a;i < b;i+=c)
#define REP(i,n) for(int i = 0;i < n;++i)
#define REP1(i,n) for(int i = 1; i<=n;i++)
#define mem(a,s) memset(a,s,sizeof a)
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define pf printf
#define sc scanf
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define vii vector<int>
#define vll vector<ll>
#define vss vector<string>
#define debug(x)  cout<<#x"="<<(x)<<endl
#define pb push_back


using namespace std;


// moves

//int dx[]= {0,0,1,-1};/*4 side move*/
//int dy[]= {-1,1,0,0};/*4 side move*/
//int dx[]= {1,1,0,-1,-1,-1,0,1};/*8 side move*/
//int dy[]= {0,1,1,1,0,-1,-1,-1};/*8 side move*/
//int dx[]={1,1,2,2,-1,-1,-2,-2};/*knight move*/
//int dy[]={2,-2,1,-1,2,-2,1,-1};/*knight move*/


//big_mod

//ll bigmod(ll a,ll b,ll m)
//{if(b == 0) return 1%m;ll x = bigmod(a,b/2,m);x = (x * x) % m;if(b % 2 == 1) x = (x * a)% m;return x;}
//ll BigMod(ll B,ll P,ll M){ ll R=1%M; while(P>0) {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return R;} /// (B^P)%M

//ll getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1ll;}
//ll setBit1(ll num, int idx) {return num or (1ll<<idx);}
//ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
//ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}

const int mod = 1000000007;
char grid[1001][1001];
int ans[1001][1001];
int h, w;
void run(int i, int j){
  if(i==h && j==w) {
    return;
  }
  ans[i][j] = 0;
  if(i<h){
    if(grid[i+1][j] == '.' && ans[i+1][j] == -1) run(i+1, j);
    if(ans[i+1][j] == -1) ans[i+1][j] = 0;
    ans[i][j] = ans[i+1][j];
  }
  if(j<w){
    if(grid[i][j+1] == '.' && ans[i][j+1] == -1) run(i, j+1);
    if(ans[i][j+1] == -1) ans[i][j+1] = 0;
    ans[i][j] += ans[i][j+1];
    ans[i][j] %= mod;
  }


  //cout<<"i+1: "<<ans[i+1][j] <<"\n";
  //cout<<"j+1: "<<ans[i][j+1] <<"\n";
  //if(grid[i][j]!='.' && grid[i][j]!='#') cout<<"YES\n";
}
int main()
{
    fast;
    cin>>h>>w;
    REP1(i, h){
      REP1(j, w){
        cin>>grid[i][j];
        ans[i][j] = -1;
      }
    }
    ans[h][w] = 1;
    run(1,1);
    cout<<ans[1][1]<<'\n';
    return 0;
}


Measured memory_bytes: 8612
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int maxn = 310;
int n,e,l;
int q;

int mat[maxn][maxn];
int mat2[maxn][maxn];

int32_t main() {
	FAST
	cin >> n >> e >> l;
	
	for (int i =1;i<=n;i++) {
		for (int j =1;j<=n;j++) {
			if (i == j) continue;
			mat[i][j] = LLONG_MAX/2;
		}
	}
	
	for (int i =0;i<e;i++) {
		int a,b,c; cin >> a >> b >> c;
		mat[a][b] = min(mat[a][b],c);
		mat[b][a] = min(mat[b][a],c);
	}
	
	for (int k=1;k<=n;k++) {
		for (int i =1;i<=n;i++) {
			for (int j =1;j<=n;j++) {
				mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
			}
		}
	}
	
	for (int i =1;i<=n;i++) {
		for (int j =1;j <= n; j++) {
			if (i == j) continue;
			mat2[i][j] = (mat[i][j] <= l ? 1 : LLONG_MAX/2);
		}
	}
	
	for (int k=1;k<=n;k++) {
		for (int i =1;i<=n;i++) {
			for (int j =1;j<=n;j++) {
				mat2[i][j] = min(mat2[i][j], mat2[i][k] + mat2[k][j]);
			}
		}
	}
	
	cin >> q;
	for (int i =0;i<q;i++) {
		int a,b; cin >> a >> b;
		if (mat2[a][b] == LLONG_MAX/2) cout << "-1\n";
		else cout << mat2[a][b]-1 << "\n";
	}
	
	
}



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

using namespace std;

typedef long long int ll;

const ll mod = 1e9 + 7;
const ll MAXN = 1e5 + 5;

vector < vector < pair < ll, ll > > > adj(MAXN, vector < pair < ll, ll > >());
vector < ll > c(MAXN);

void dfs(ll u, ll p){
  for(auto edge : adj[u]){
    ll to = edge.first;
    ll len = edge.second;
    if(to != p){
      if(len % 2 == 0) c[to] = c[u];
      else c[to] = 1 - c[u];
      dfs(to, u);
    }
  }
}

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

  ll n;
  cin >> n;
  for(int i = 0; i < n - 1; i++){
    ll u, v, wt;
    cin >> u >> v >> wt;
    adj[u].push_back({v, wt});
    adj[v].push_back({u, wt});
  }

  c[1] = 0;
  dfs(1, -1);

  for(int i = 1; i <= n; i++) cout << c[i] << '\n';
}


Measured memory_bytes: 11008
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <cmath>

typedef long long ll;
using namespace std;

int main(void){
    ll H;
    cin >> H;
    ll tmp = 1;
    ll ans = 1;
    
    ll now = H;
    
    while(now != 1){
        tmp *= 2;
        ans += tmp;
        now = now / 2;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ll long long

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string s,t;
    ll ans=0;

    cin>>s;
    cin>>t;

    for(int i=0; i<s.length(); i++){
        if(s[i] != t[i])ans++;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back
#define debug(x) cerr << #x << " = " << x << " "

deque<ll> v;
deque<ll> buf;
ll anti_inversion(int l, int r)
{
  if (l == r) return 0;
  int mid = (l+r)>>1;
  ll ret = anti_inversion(l, mid) + anti_inversion(mid+1, r);
  int tl = l, tr = mid+1, ptr = l;
  while (tl <= mid && tr <= r)
    if (v[tl] <= v[tr]) ret += r-tr+1, buf[ptr++] = v[tl++];
    else buf[ptr++] = v[tr++];
  while (tl <= mid) buf[ptr++] = v[tl++];
  while (tr <= r) buf[ptr++] = v[tr++];
  assert(ptr == r+1);
  for (int i = l; i <= r; ++i) v[i] = buf[i];
  return ret;
}
int main()
{
  int n, k;
  while (~scanf("%d %d", &n, &k))
    {
      v.resize(n);
      for (auto & e : v) scanf("%lld", &e), e -= k;
      v.push_front(0ll);
      buf.resize(v.size());
      for (int i = 1; i <= n; ++i) v[i] += v[i-1];
      printf("%lld\n", anti_inversion(0, n));
    }
}


Measured memory_bytes: 3456
import Data.Char
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

readInt :: BS.ByteString -> Int
readInt s = case BS.readInt s of
              Just (x, _) -> x

main = do
  n <- readInt <$> BS.getLine
  xs <- U.unfoldrN n (fmap (BS.dropWhile (== ' ') <$>) . BS.readInt) <$> BS.getLine
  let ls = U.scanl gcd 0 xs
      rs = U.scanr gcd 0 xs
  print $ U.maximum $ U.zipWith gcd ls (U.tail rs)


Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a, b;
  	cin >> a >> b;
 	int l = a + b ;
  	int k = a - b ;
  	int m = a * b ;
 
  	if(l > k && l > m){
		cout << l <<endl ;      
    }
  	else if(k > m){
		cout << k <<endl ;       		  
    }
  	else{
		cout << m <<endl ;       	
    }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>city(n);
  rep(i,n)cin>>city[i];
  int l,q;
  cin>>l>>q;
  vector<vector<int>>db(n,vector<int>(20,n));
  int r=0;
  rep(i,n)
  {
    while(r+1<n&&city[r+1]<=city[i]+l)r++;
    db[i][0]=r;
  }
  rep(i,19)
  {
    rep(j,n)
    {
      db[j][i+1]=db[db[j][i]][i];
    }
  }
  rep(i,q)
  {
    int a,b;
    cin>>a>>b;
    a--;b--;
    if(a>b)swap(a,b);
    int cnt=0;
    while(1)
    {
      auto itr=lower_bound(all(db[a]),b);
      if(itr==db[a].begin()){cnt++;break;}
      cnt+=(1<<(itr-db[a].begin()-1));
      a=*(itr-1);
    }
    cout<<cnt<<"\n";

  }
  cout<<flush;


  return 0;

}


Measured memory_bytes: 13056
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
// #define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair<int,int>
// #define pii pair< int, pi >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)
using namespace std;
using namespace std::chrono;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
vector<vector<int>> vis;
int h,w,ch,cw,dh,dw;
int X[]={1,0,0,-1};
int Y[]={0,1,-1,0};
bool safe(int x,int y){
  return x>=0 && x<h && y>=0 && y<w;
}
void solve(){
	int h,w,m;
	cin>>h>>w>>m;
	vector<pii> v1(m);
	map<int,int> r,c;
	map<pii,int> mp;
	set<pii,greater<pii>> st;
	map<int,set<int>> mp2;
	rep(i,0,m){
		cin>>v1[i].f>>v1[i].s;
		r[v1[i].f]++;
		c[v1[i].s]++;
		mp2[v1[i].f].insert(v1[i].s);
		mp[{v1[i].f,v1[i].s}]++;
	}
	int mx1=0,mx2=0;
	for(auto i:r){
		mx1=max(i.second,mx1);
	}
	for(auto i:c){
		mx2=max(i.second,mx2);
	}
	vector<int> r1; set<int> c1;
	for(auto i:r){
		if(i.s==mx1) r1.push_back(i.f);
	}
	for(auto i:c){
		if(i.s==mx2) c1.insert(i.f);
	}
	int ans=mx1+mx2-1;
	rep(i,0,r1.size()){
		int cnt=0;
		set<int> st2=mp2[r1[i]];
		for(auto j:st2) if(c1.find(j)!=c1.end()) cnt++;
		if(cnt!=c1.size()){
			cout<<ans+1<<endl;
			return;
		}
	}
	cout<<ans<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}

Measured memory_bytes: 109788
H, W = map(int, input().split())
A = []
for i in range(H):
  A.append(list(input()))

cnt = 0
for i in range(H):
  for j in range(W):
    if A[i][j] == "#":
      cnt += 1
      
if cnt == H+W-1:
  print("Possible")
else:
  print("Impossible")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <random>

struct Func {
	long long int coefficient{ 1 }, constant{ 0 };
	Func() {};
	Func(const long long int e, const long long int c) :coefficient{ e }, constant{ c }{};
	Func operator*(const int x) const {
		return Func( coefficient * x, constant * x );
	}
	Func operator*=(const int x) { return *this = *this * x; }
	Func operator+(const int x) const {
		return Func( coefficient, constant + x );
	}
	Func operator+=(const int x) { return *this = *this + x; }
	Func operator-(const int x) const {
		return Func( coefficient, constant - x );
	}
	Func operator-=(const int x) { return *this = *this - x; }
};
int main() {
	Func func;
	int n; std::cin >> n;
	for (auto _i = 0; _i < n; ++_i) {
		int q, x; std::cin >> q >> x;
		switch (q) {
		case 1:
			func *= x;
			break;
		case 2:
			func += x;
			break;
		case 3:
			func -= x;
			break;
		default: throw "???";
		}
	}
	std::cout << -func.constant << ' ' << func.coefficient << '\n';
}



Measured memory_bytes: 3120
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,ll> type;
typedef pair<ll,type> event;
main()
{
    int n,q;
    scanf("%d%d",&n,&q);
    vector<event> v;
    for(int i=0;i<n;i++)
    {
        int s,t,x;
        scanf("%d%d%d",&s,&t,&x);
        v.emplace_back(event(s-x,type(-1,x)));
        v.emplace_back(event(t-x,type(0,x)));
    }
    for(int i=0;i<q;i++)
    {
        int d;
        scanf("%d",&d);
        v.emplace_back(event(d,type(1,i)));
    }
    sort(begin(v),end(v));

    vector<ll> res(q);
    multiset<ll> se;
    for(auto p:v)
    {
        ll x=p.first;
        int type = p.second.first;
        ll val=p.second.second;
        if(type == -1)se.insert(val);
        else if(type == 0)se.erase(se.lower_bound(val));
        else res[val]=se.empty()?-1:*begin(se);
    }
    for(auto v:res)printf("%d\n",v);
    return 0;
}

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

int main()
{
    int a,b,c;
    cin >>a>>b>>c;
   
    int d1=b-a , d2=c-b;
  
    if(d1==d2)
      cout<<"YES";
    else
      cout << "NO";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define ENDL '\n'
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << ENDL;
#define all(a) begin(a),end(a)
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

int main()
{   _
    lli n, u, v, prev = 0;
    bool b = false;
    cin >> n;
    fore(i, 0, n) {
        cin >> u >> v;
        if(u == v) {
            ++prev;
            if(prev == 3) b = true;
        }
        else prev = 0;
    }
    cout << (b ? "Yes" : "No") << ENDL;
    return 0;
}


Measured memory_bytes: 3648
class Union_Find():
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.siz = [1] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            #親を検索
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def same_checker(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.siz[y] += self.siz[x]
        else:
            self.par[y] = x
            self.siz[x] += self.siz[y]
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        return self.siz[self.find(x)]


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

bridge.reverse()
island = Union_Find(N)
confort = [0]
for i in range(M):
    if island.same_checker(bridge[i][0], bridge[i][1]):
        confort.append(confort[i])
    else:
        confort.append(confort[i]+island.size(bridge[i][0])*island.size(bridge[i][1]))
        island.union(bridge[i][0], bridge[i][1])
confort.reverse()
for i in range(M):
    print(confort[0] - confort[i+1])


Measured memory_bytes: 37052
#include <bits/stdc++.h>
using namespace std;
int main(void){
   int K,S,ans,count,x,y;
   cin >> K >> S;
   count=0;
   for(x=0;x<=K;x++){
       for(y=0;y<=S-x;y++){
           if(S-x-y<=K && y<=K)count++;
       }
   }
   ans=count;
   cout << count <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll n,ans=0;
  cin >>n;
  string s[n];
  ll aa=0,bb=0,k=0,fl=0;
  for(ll i=0;i<n;i++) {
    cin >>s[i];
    ll ss=s[i].size();
    if(s[i][ss-1]=='A'&&s[i][0]=='B') fl++;
    if(s[i][ss-1]=='A') aa++;
    if(s[i][0]=='B') bb++;
    for(ll j=0;j<ss-1;j++){
      if(s[i][j]=='A'&&s[i][j+1]=='B'){
            k++;
            j++;
      }
    }
  }
  if(aa==bb&&fl==aa) {
    if(aa==0) cout <<k<<endl;
    else cout <<k+aa-1<<endl;
  }
  else cout <<k+min(aa,bb)<<endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
// #include "lib.h"
using namespace std;
#define LLINF 1234567890987654321
#define INF 1234567890
#define pb push_back
#define ins insert
#define f first
#define s second
#define db 0
#define rep(kk, l1, l2)for(ll kk = l1; kk < l2; kk++)
typedef long long ll;
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
ll n, k, A[100001], neg[100001], pos[100001], nco, pco, ans = LLINF;
int main()
{
	cin >> n >> k;
	for(ll i = 0; i < n; i++)
	{
		cin >> A[i];
	}
	for(ll i = 0; i < n; i++)
	{
		if(A[i] >= 0)
		{
			pos[pco++] = A[i];
		}
		else
		{
			neg[nco++] = A[i];
		}
	}
	sort(pos, pos+pco);
	sort(neg, neg+nco);
	reverse(neg, neg+nco);
	
	if(nco >= k)ans = min(ans, abs(0-neg[k-1]));
	
	for(ll i = 1; i <= k; i++)
	{
		if(pco < i || nco < k-i)continue;
		if(db and ans != 0)cout << i << '\n';
		if(k-i-1 == -1)
		ans = min(ans, pos[i-1]);
		else
		ans = min(ans, min((2*pos[i-1]) + abs(neg[k-i-1]), pos[i-1] + abs((2*neg[k-i-1]))));
	}
	cout << ans << '\n';
}


Measured memory_bytes: 1792
import java.util.Scanner;
import java.util.Vector;

class Main{
  public static class ScoreSet{
    public int a,b;
    ScoreSet( int aa, int bb ){
      a = aa; b = bb;
    }
  }
  public static void main(String[] av){
    Scanner sc = new Scanner(System.in);

    Vector<ScoreSet> ss = new Vector<ScoreSet>();
    while(sc.hasNextInt()){
      int n = sc.nextInt();
      Vector<Integer> vecA = new Vector<Integer>();
      Vector<Integer> vecB = new Vector<Integer>();
      if ( n == 0 ) break;
      for ( int i = 0; i < n; ++i ){
        vecA.add( sc.nextInt() );
        vecB.add( sc.nextInt() );
      }
      int sa = 0;
      int sb = 0;
      for ( int i = 0; i < n; ++i ){
        if ( vecA.get(i) == vecB.get(i) ){
          sa += vecA.get(i);
          sb += vecB.get(i);
        }else if ( vecA.get(i) < vecB.get(i) ){
          sb += vecA.get(i) + vecB.get(i);
        }else{
          sa += vecA.get(i) + vecB.get(i);
        }
      }
      ss.add( new ScoreSet( sa,sb ) );
    }
    for ( ScoreSet s : ss ){
      System.out.println( s.a + " " + s.b );
    }

  }
}

Measured memory_bytes: 52268
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
#define spn setprecision
#define fr(x,a,b,c) for(int x = a; x <= b; x+=c)
using namespace std;
ll multiply(ll num1, ll num2, ll mod) { // with mod > 1e9
	ll ans = 0;
	num1 %= mod;
	num2 %= mod;
	while (num2) {
		if (num2&1) {
			ans += num1;
			ans %= mod;
		}
		num1 *= 2;
		num1 %= mod;
		num2 /= 2;
	}
	return ans;
}
ll powmod2(ll base,ll exponent,ll mod){ // with mod > 1e9
	ll ans = 1;
	while (exponent) {
		if (exponent&1) {
			ans = multiply(ans, base, mod);
		}
		base = multiply(base, base, mod);
		exponent /= 2;
	}
	return ans;
}
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+100;
const int mod = 1e9+7;
int arr[upperlimit];
int occ[upperlimit];
int occ2[upperlimit];
int main() {
	int n;
	sd(n);
	int m=n,m2=n,m3=n,m4=n;
	int ans,x1,x2;
	for(int i = 1; i <= n; i++){
		sd(arr[i]);
		if(i&1) occ[arr[i]]++;
		else occ2[arr[i]]++;
	}
	for(int i = 1; i <= n; i+=2){
		if(n-occ[arr[i]]<m){
			x1=arr[i];
			m2=m;
			m=n-occ[arr[i]];
		}
		else if((n-occ[arr[i]]<m2)&&(arr[i]!=x1)) m2=n-occ[arr[i]];
	}
	for(int i = 2; i <= n; i+=2){
		if(n-occ2[arr[i]]<m3){
			x2=arr[i];
			m4=m3;
			m3=n-occ2[arr[i]];
		}
		else if((n-occ2[arr[i]]<m4)&&(arr[i]!=x2)) m4=n-occ2[arr[i]];
	}
	if(x1==x2){
		ans=min(m+m4,m2+m3);
	}
	else ans=m+m3;
	pd(ans-n);
	return 0;
}

Measured memory_bytes: 8832
s = gets.chomp

a = s.slice(0, 2).to_i
b = s.slice(2, 2).to_i

mmyy = a.between?(1, 12)
yymm = b.between?(1, 12)



if mmyy && yymm
  puts 'AMBIGUOUS'
elsif mmyy
  puts 'MMYY'
elsif yymm
  puts 'YYMM'
else
  puts 'NA'
end


Measured memory_bytes: 1788
#include<stdio.h>
int isprime(int n){
	int i;
	for(i=2;i*i <= n;i++){
		if(n%i==0)return 0;
	}
	return 1;
}
int main(){
	int n, i, k, one=0;
	int sosu[10000];
	for(i=0;i<10000;i++){
		if(isprime(i)==1){
			sosu[i]=i;
		}else{
			sosu[i]=0;
		}
	}
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		for(i=n;i>0 && one==0;i--){
			if(sosu[i]!=0 && sosu[i-2]!= 0){
				printf("%d %d\n",sosu[i-2],sosu[i]);
				one=1;
			}
		}
		one=0;
	}	
	return 0;
}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		Integer[] len = new Integer[n];
		for ( int i = 0; i < n; i++ ) {
			len[i] = in.nextInt();
		}
		Arrays.sort(len);

		int cnt = 0;
		// x, yを比べて等しい時、x > yとみなすコンパレータ
		Comparator<Integer> com = new Comparator<Integer>() {
			@Override
			public int compare(Integer o1, Integer o2) {				
				return o1.compareTo(o2) >= 0 ? 1 : -1;
			}
		};
		
		for ( int e1 = 0; e1 < n - 2; e1++ ) {
			for ( int e2 = e1 + 1; e2 < n - 1; e2++ ) {
				int d = len[e1] + len[e2];
				// LowerBoundを取りたい
				int i = Arrays.binarySearch(len, d, com);
				i = i >= 0 ? i : ~i;
				cnt += Math.max(i - e2 - 1, 0);
			}
		}
		System.out.println(cnt);
		in.close();
	}
}


Measured memory_bytes: 45008
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
g = []
for i in range(n):
    t = na()
    u = t[0] - 1
    k = t[1]
    v = [x-1 for x in t[2:]]
    g.append(v)
d = [0] * n
f = [0] * n
#print(g)
seen = [False] * n
s = 0
t = 0
def dfs(g, v):
    global t
    #print(v+1, t)
    if seen[v]:
        return
    seen[v] = True
    d[v] = t
    t += 1    
    for next_v in g[v]:
        #if seen[next_v]: continue
        dfs(g, next_v)
    f[v] = t
    t += 1
for i in range(n):
    if len(g[i]) != 0:
        dfs(g, i)
for i in range(n):
    print(i+1, d[i]+1, f[i]+1)




Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
const int mod = 1000000007;
long long modpow(long long a, long long n){
  long long r = 1;
  while (n) {
    r = r * ( (n%2)?a:1 ) %mod;
    a = a * a % mod;
    n >>= 1;
  }
  return r;
}

int main(void){
    int n;cin>>n;
    vector<ll> a(n),b(n,1);
    rep(i,n) cin>>a[i];
    vector<int> sieve1,sieve2(10000,0);
    sieve2[0]=sieve2[1]=-1;
    for(int i=2;i*i<=10000;i++){
        for(int j=i*i;j<10000;j+=i){
            sieve2[j]=i;
        }
    }
    rep(i,10000){
        if(sieve2[i]==0) sieve1.push_back(i);
    }
    
    ll sz=sieve1.size();
    vector<ll> lcm(sz,0);
    rep(i,n){
        ll x=a[i];
        for(int j=0;j<sz;j++){
            ll y=sieve1[j];
            ll buf=0;
            while(x%y==0&&x>1){
                x/=y;
                buf++;
            }
            lcm[j]=max(lcm[j],buf);
        }
        if(x>1){
            bool jud=true;
            rep(i,sz){
                if(x==sieve1[i]){
                    lcm[i]++;
                    jud=true;
                    break;
                }
            }
            if(jud){
                sieve1.push_back(x);
                sz++;
                lcm.push_back(1);
            }
        }
    }
    long long LCM=1;
    rep(i,sz) (LCM*=modpow(sieve1[i],lcm[i]))%=mod;
    long long ans=0;
    for(int i=0;i<n;i++){
        (ans+=LCM*modpow(a[i],mod-2)%mod)%=mod;
    }
    cout<<ans<<endl;
    
}

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

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) 0
#endif
//#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
using namespace std;

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

const integer NN = (int) 5e5 + 2;
int ar[NN];
int n, m, k, x;
string s;

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

    int T = 1;
//    cin >> T;
    while (T--) {
        cin >> n;
        cout << n + n * n + n * n * n << endl;
    }
}


Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

vector<int> prime;

void calcPrime(int n){

    bool isPrime[n+1];
    fill(isPrime, isPrime+n+1, true);
    isPrime[0] = false;
    isPrime[1] = false;

    int i1 = 2; 
    while(i1 <= n){
        if(isPrime[i1] == false){
            i1++;
            continue;
        }

        int temp = i1;
        int i2 = i1*2;
        while(i2 <= n){
            isPrime[i2] = false;
            i2 += temp;
        }
        i1++;
    }

    prime.clear();
    for(int i=2; i<=n; i++){
        if(isPrime[i]){
            prime.push_back(i);
        }
    }
}

int main(){

    int q; cin >> q;
    int n = 1e5;

    int l[q], r[q];
    rep(i, q){
        cin >> l[i] >> r[i];
    }

    calcPrime(n+1);

    set<ll> primeset;
    rep(i, prime.size()){
        primeset.insert(prime[i]);
    }

    

    bool is2017like[n+1];
    fill(is2017like, is2017like+n+1, false);

    // is2017like[2] = true;
    for(int i=3; i<n+1; i+=2){
        if(primeset.find(i) != primeset.end()){
            if(primeset.find(i/2 + 1) != primeset.end()){
                is2017like[i] = true;
            }
        }
    }

    // rep(i, 100){
    //     if(is2017like[i] == true){
    //         cout << i << endl;
    //     }
    // }

    ll cntsum[n+1] = {};

    reps(i, 1, n+1){
        if(is2017like[i] == true){
            cntsum[i] = cntsum[i-1]+1;
        }
        else{
            cntsum[i] = cntsum[i-1];
        }
    }

    // rep(i, 100){
    //     cout << cntsum[i] << endl;
    // }

    rep(i, q){
        cout << cntsum[r[i]] - cntsum[l[i]-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 2816
n, W = map(int, input().split())
w, v = [], []

for i in range(n):
    temp1, temp2 = map(int, input().split())
    w.append(temp1)
    v.append(temp2)

#dp = [[None for i in range(W+1)] for j in range(n+1)]
dp = [[0 for i in range(W+1)] for j in range(n+1)]

for i in reversed(range(n)):
    for j in reversed(range(W)):
        weight, val = w[i], v[i]

        if j + weight <= W:
            chose = dp[i+1][j + weight] + val
            unchose = dp[i+1][j]
            dp[i][j] = max(chose, unchose)
        else:
            dp[i][j] = dp[i+1][j]

#print(dp)
#print(dp[n][W])
print(dp[0][0])

Measured memory_bytes: 173704
#include <stdio.h>

int main()
{
  int i, j;
  unsigned long n, a, b;
  scanf("%lu%lu%lu", &n, &a, &b);
  unsigned long d = n / (a + b);
  unsigned long e = n % (a + b);
  if(e >= a){
    printf("%lu\n", (d + 1) * a);
  }else{
    printf("%lu\n", d * a + e);
  }
  
  return 0;
}

Measured memory_bytes: 128