akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n;
	cin>>n;
	vector<queue<int>>A(n+1);
	rep(i,1,n+1)
	{
		rep(j,0,n-1)
		{
			int a;
			cin>>a;
			A[i].push(a);
		}
	}
	int counter=0, ans=0;
	queue<int>Q;
	rep(i,1,n+1)
	{
		Q.push(i);
	}
	while(true)
	{
		ans++;
		bool d=0;
		set<int>B;
		int q=Q.size();
		//cout<<ans<<endl;
		rep(h,0,q)	
		{
			int i=Q.front(), x=A[i].front();
			//cout<<counter<<" "<<i<<" "<<x<<endl;
			Q.pop();
			if(B.count(i)||B.count(x))continue;
			if(A[i].empty())continue;
			if(A[x].front()==i)
			{
				//cout<<i<<" "<<x<<endl;
				counter++;
				B.insert(i);
				B.insert(x);
				A[x].pop();
				A[i].pop();
				Q.push(i);
				Q.push(x);
				d=1;
			}
		}
		if(counter==(n*(n-1))/2){break;}
		//cout<<Q.size()<<endl;
		if(!d)
		{
			//cout<<counter<<endl;
			cout<<-1<<endl;
			return 0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define forloop(n) for(int i = 0; i < n; i++)
#define ll long long
 
#define mod 1000000007


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	string s; cin>>s;
	int count = 0;
	for(int i = 0; i < n-2; i++){
		if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')count++;
	}
	cout<<count;
	return 0;
}


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

typedef long long ll;

ll cou;

void merge(vector<ll> &v,ll l,ll r){
    ll mid = (r+l)/2;
    ll n1 = mid-l;
    ll n2 = r-mid;
    vector<ll> a,b;
    for(ll i=0;i<n1;i++)a.push_back(v[l+i]);
    for(ll i=0;i<n2;i++)b.push_back(v[mid+i]);
    a.push_back(1e9);
    b.push_back(1e9);
    ll aa=0,bb=0;
    for(ll i=l;i<r;i++){
        if(a[aa]<b[bb]){
            v[i]=a[aa++];
        }else{
            v[i]=b[bb++];
            cou+=n1-aa;
        }
    }
}
void merge_sort(vector<ll> &v,ll l,ll r){
    if(r-l>1){
        ll mid = (r+l)/2;
        merge_sort(v,l,mid);
        merge_sort(v,mid,r);
        merge(v,l,r);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)cin >> a[i];
    merge_sort(a,0,n);
    cout << cou << endl;
}



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

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

  int r = 0;
  int b = 0;
  for (int i=0; i<n; i++) {
    if (s[i] == 'R') r++;
    else b++;
  }

  if (r > b) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

ll Pow(ll x,ll p){
  if(!p) return 1;
  if(p%2){
    return (x*Pow(x,p-1))%mod;
  }
  ll t = Pow(x,p>>1);
  return (t*t)%mod;
}

struct combination{
  vector<ll> fact,ifact;
  combination(int n) : fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(ll i=1; i<=n; i++) fact[i] = (fact[i-1]*i)%mod;
    ifact[n] = Pow(fact[n],mod-2);
    for(ll i=n; i>=1; i--) ifact[i-1] = (ifact[i]*i)%mod;
  }
  ll operator()(ll n,ll k){
    return (((fact[n]*ifact[k])%mod)*ifact[n-k])%mod;
  }
};

int main(){
  ll X,Y;
  cin >> X >> Y;
  if((X+Y)%3 != 0){
    cout << 0 << endl;
    return 0;
  }
  ll temp = X+Y;
  X -= temp/3;
  Y -= temp/3;
  if(X<0 || Y<0){
    cout << 0 << endl;
    return 0;
  }
  combination c(X+Y);
  cout << c(X+Y,Y) << endl;
  return 0;
}


Measured memory_bytes: 10624
#[allow(unused_macros)]
macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut iter = $s.split_whitespace();
            let mut next = || { iter.next().unwrap() };
            input_inner!{next, $($r)*}
        };
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }

#[allow(unused_macros)]
macro_rules! input_inner {
        ($next:expr) => {};
        ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };

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

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

        ($next:expr, bytes) => {
            read_value!($next, String).into_bytes()
        };

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

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

fn main() {
    input! {
            n: usize,
            nums: [i32; n],
        }

    let unordered_nums: i32 = nums.iter().enumerate().map(|(i, &x)| if x == i as i32+1 { 0 } else { 1 }).sum();

    println!("{}", if unordered_nums == 0 || unordered_nums == 2 { "YES" } else { "NO" });
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

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

	    int N = Integer.parseInt(scanner.next());
	    long[] H  = new long[N];

	    String r="Yes";
	    boolean flg=false;
	    H[0]=Long.parseLong(scanner.next());
	    for (int i=1; i<N; i++) {
	    	H[i]=Long.parseLong(scanner.next());
	    	if (H[i] - H[i-1] == -1) {
	    		if(flg) {
	    			r="No";
	    			break;
	    		} else {
	    			flg=true;
	    		}
	    	} else if (H[i] - H[i-1] <-1) {
	    		r="No";
    			break;
	    	} else if (H[i] - H[i-1] > 0) {
	    		flg=false;
	    	}
	    }
	    
        System.out.print(r);
	}

}

Measured memory_bytes: 59784
#include<stdio.h>
#include <stdlib.h>
int main(void){
	int a,b,k,j=0;
	int q[200];
	scanf("%d %d %d",&a,&b,&k);
	for(int i=k;i>0;i--,a++){
	if(a<=b){
	q[j]=a;
	j++;
	}else{
		break;
	}
	}
	for(int i=k;i>0;i--){
	if(q[j-1]<b-i+1){
		q[j]=b-i+1;
		j++;
		}
	}
	for(int i=0;i<j;i++){
		printf("%d\n",q[i]);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
int main(int argc, char const *argv[]) {
    int x_1, y_1, x_2, y_2;
    std::cin >> x_1 >> y_1 >> x_2 >> y_2;
    std::cout << x_2 + y_1 - y_2 << " ";
    std::cout << y_2 + x_2 - x_1 << " ";
    std::cout << x_1 + y_1 - y_2 << " ";
    std::cout << y_1 + x_2 - x_1 << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
int main() {
	int n, a[100],c[50],co=0;
	for (int i = 0; i < 50; ++i) {
		c[i] = 0;
	}
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		std::cin >> a[i];
		if (a[i] == 1) {
			c[co] += 1;
		}
		else {
			co += 1;
		}
	}
	std::cout << *std::max_element(c, c + 50)+1 << std::endl;
}


Measured memory_bytes: 3108
# Binary search 二分検索
def binarySearch(A, n, k):
    left = 0
    right = n
    while left < right:
        mid = int((left + right) / 2)
        if A[mid] == k:
            return mid
        elif A[mid] > k:
            right = mid
        elif A[mid] < k:
            left = mid + 1
    return -1


n = int(input())
S = [int(i) for i in input().split()]
q = int(input())
T = [int(i) for i in input().split()]
C = 0
for t in T:
    if binarySearch(S, n, t) != -1:
        C += 1
print(C)



Measured memory_bytes: 16900
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, e) for (int i = (s); i < (int)(e); ++i)
using namespace std;
using ll = long long;
using ld = long double;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep (i, N) {
    cin >> A[i];
  }

  map<ll, ll> counts;
  for (const auto &a : A) {
    counts[a] += 1;
  }

  ll ans = 0;
  for (const auto &count : counts) {
    if (count.first <= count.second) {
      ans += count.second - count.first;
    } else {
      ans += count.second;
    }
  }
  cout << ans << endl;
}


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
    int N;
    cin >> N;
    string s;
    cin >> s;
    rep(i,s.size())
    {
        if(s[i]+N > 90) cout << char(65 + (s[i]+N-91));
        else cout << char(s[i]+N);
        //cout << char((s[i]+2)%90 + 65) << endl; 
    }
    cout << endl;
    //rep(i,s.size()) cout << s[i]+2 << endl; 
}


Measured memory_bytes: 256
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, -1, -2, 0, -1, -2, 0, -1, -2};
int dy[] = {0, 0, 0, -1, -1, -1, -2, -2, -2};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

map<pii, int> m;
signed main() {
    int H, W, N; cin >> H >> W >> N;
    rep(i,0,N) {
        int a, b; cin >> a >> b;
        rep(k,0,9) {
            int nx = a + dx[k], ny = b + dy[k];
            if(nx <= 0 || nx > H-2 || ny <= 0 || ny > W-2) continue;
            m[ make_pair(nx, ny) ]++;
        }
    }
    int cnt = 0, ans[10] = {};
    ans[0] = (H-2) * (W-2);
    for(auto e : m) {
        // printf("(%lld, %lld) -> %lld\n", e.first.first, e.first.second, e.second);
        ans[ e.second ]++;
        ans[0]--;
    }

    rep(i,0,10) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 56448
#include "bits/stdc++.h"
using namespace std;

int main(){
  long long int n,k;
  cin>>n>>k;

  if(k%2==1){
    cout<<(n/k)*(n/k)*(n/k)<<endl;
  }else{
    long long int x=(n+(k/2))/k;
    cout<<(n/k)*(n/k)*(n/k)+x*x*x<<endl;
  }
}


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

using namespace std;

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

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m;
  cin >> n >> m;

  vll h(n + 1);
  REP(i, n + 1) {
    cin >> h[i];
  }

  vvll e(n + 1);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    e[a].push_back(b);
    e[b].push_back(a);
  }

  vll hiest(n + 1);

  REP(i, n + 1) {
    if (hiest[i] == 0) {
      FORm(it, e[i]) {
        if (h[i] > h[*it]) {
          hiest[*it] = -1;
        } else {
          hiest[i] = -1;
        }
      }
      if (hiest[i] == 0) {
        hiest[i] = 1;
      }
    }
  }

  ll ans = 0;
  REP(i, n + 1) {
    if (hiest[i] == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10588
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

main(){
  int n;
  cin>>n;
  while(n--){
    long double hh,mm;
    scanf("%Lf:%Lf",&hh,&mm);
    hh=30*hh+mm*0.5;
    
    mm*=6;
    //cout<<hh<<":"<<mm<<endl;
    long double diff=abs(hh-mm);
    if(mm>hh)diff=abs(mm-hh);
    if(diff>180)diff=360-diff;

    if(diff<30)puts("alert");
    else if(diff>=90)puts("safe");
    else puts("warning");
  }
}

Measured memory_bytes: 0
#include <iostream>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


string X;
int cnt;
int s;

int main(void) {
  cin >> X;

  cnt = 0;
  s = 0;
  REP(i, 0, X.length()) {
    if(X.at(i) == 'S') {
      s++;
    }
    if(X.at(i) == 'T' && s > 0) {
      s--;
      cnt += 2;
    }
  }

  cout << X.length() - cnt << endl;

  return 0;
}


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

int main()
{
	char x,y;
	scanf(" %c %c",&x,&y);
	if(x<y) printf("<\n");
	if(x>y) printf(">\n");
	if(x==y) printf("=\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int K;
    string S;
    cin >> K;
    cin >> S;
    for(int i=0; i<S.size(); ++i){
        if(i==K){
            cout << "...";
            break;
        }
        cout << S.at(i);
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = 100005;
char str[MAXN];
int main()
{
    int flag=0;
    scanf("%s", str);
    int len = strlen(str);
    for(int i=0,j=len-1;i<j;--j,++i)
    {
        while(str[i]=='x')
            i++;
        if(i>=len)
            break;
        while(str[j]=='x')
            j--;
        if(j<0)
            break;
        if(str[i]!=str[j])
            flag=1;
    }
    if(!flag)
    {
        int ans=0;
        int i=0, j=len-1;
        while(i<=j)
        {
            if(str[i]!=str[j])
            {
                while(str[i]=='x')
                {
                    i++,ans++;
                }
                while(str[j]=='x')
                {
                    j--,ans++;
                }
                    
            }
            else
            {
                i++,j--;
            }
        }
        printf("%d\n",ans);
    }
    else
        printf("-1\n");
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
  int next_combination(int sub) {
      int x=sub & -sub, y=sub+x;
      return (((sub & ~y)/x)>>1)|y;
  }
  int main() {
      int n,k;
      cin >> n >> k;
      int bit=(1<<k)-1;
      for(;bit<(1<<n); bit=next_combination(bit)) {
          vector<int> v;
          for(int i=0; i<n; i++) {
              if(bit&(1<<i)) {
                  v.push_back(i);
              }
          }
          cout << bit << ":";
          for(int i=0; i<v.size(); i++) {
              cout << " " << v[i];
          }
          cout << endl;
      }
  }


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s;
    int a = 0,z = 0;
    bool ab = false;
    cin >> s;
    rep(i, s.size()){
        if (s[i] == 'A' && !ab) {
            a = i;
            ab = true;
        }else if(s[i] == 'Z' && ab){
            z = i;
        }
    }
    cout << z - a + 1 << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long n=sc.nextInt(),count=0;
    long[] l=new long[(int)n];
    for(int i=0;i<n;i++)l[i]=sc.nextInt();
    Arrays.sort(l);
    for(int i=0;i<n-2;i++) {
    	for(int j=i+1;j<n-1;j++) {
    		long buff=B_search(l,l[i]+l[j]);
			count+=Math.max(buff-j-1,0);
    	}
    }
    System.out.println(count);
  }
  //okはv以上の最小index、ngはv未満の最大index。aに検索対象の配列、vに検索値を入れる。
	public static long B_search(long[] a,long v) {
		int ng=-1,ok=a.length;

		while(Math.abs(ok-ng)>1) {
			int mid=(ok+ng)/2;

			if(a[mid]>=v) ok=mid;
			else ng=mid;
		}
		return ok;
	}
}


Measured memory_bytes: 26756
#include<bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define S set<int>
#define pb(v) push_back(v)
int main(){
    string A,B;cin>>A>>B;
    if(A.size()>B.size()){
        COUT("GREATER");
        return 0;
    }
    if(A.size()<B.size()){
        COUT("LESS");
        return 0;
    }
    if(A.size()==B.size()){
        REP(a,A.size()){
            if(A.at(a)>B.at(a)){
                COUT("GREATER");
                return 0;
            }
            if(A.at(a)<B.at(a)){
                COUT("LESS");
                return 0;
            }
        }
    }
    COUT("EQUAL");
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on 2019/2/
Solved on 2019/2/
@author: shinjisu
"""


# ARC 062 C AtCoDeer and Rock-Paper
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def zeros(n): return [0]*n


def getIntLines(n): return [int(input()) for i in range(n)]


def getIntMat(n):
    mat = []
    for i in range(n):
        mat.append(getIntList())
    return mat


def zeros2(n, m): return [zeros(m)]*n


ALPHABET = [chr(i+ord('a')) for i in range(26)]
DIGIT = [chr(i+ord('0')) for i in range(10)]


def dmp(x, cmt=''):
    global debug
    if debug:
        if cmt != '':
            print(cmt, ':  ', end='')
        print(x)
    return x


def probC():
    S = input()
    dmp(S)
    GU = 'g'
    PA = 'p'
    guCount = 0
    paCount = 0
    point = 0
    allTe = ''
    for i in range(len(S)):
        if paCount < guCount:
            te = PA
            paCount += 1
        else:
            te = GU
            guCount += 1

        if te == GU and S[i] == PA:
            point -= 1
        elif te == PA and S[i] == GU:
            point += 1
        allTe += te
    dmp(allTe,'allTe')
    dmp(point)
    return point


debug = False  # True False
ans = probC()
print(ans)
#for row in ans:
#    print(row)

"""
        if S[i] == GU:
            if paCount < guCount:
                te = PA
                paCount += 1
            else:
                te = GU
                guCount += 1
        else:
            if paCount < guCount:
                te = PA
                paCount += 1
            else:
                te = GU
                guCount += 1
"""


Measured memory_bytes: 3316
#include <stdio.h>
#include <string.h>
int main(){
  char s[100001];
  int c=0;
  scanf("%s",s);
  for(int i=0;i<26;i++){
    for(int j=0;j<strlen(s);j++){
      if(s[j]=='a'+i){
        c++;
        break;
      }
    }
    if(c!=i+1){
      printf("%c",'a'+c);
      return 0;
    }
  }
  puts("None");
  return 0;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
/*---------------------DEBUGGING------------------------------------*/
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
/*-------------------------------------------------------------------------------------*/
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define pcc pair<char,char>
#define F first
#define S second
#define int long long
#define pi 3.141592653589793238462643383279502
#define M   998244353    //1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define N 100005
#define vi vector<int>

signed main()
{
   ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int h,n;
   cin>>h>>n;
   int a[n];
   int s=0;
   for(int i=0;i<n;i++)
   {
       cin>>a[i];s+=a[i];
   }
   if(s<h)
    cout<<"No"<<endl;
   else
    cout<<"Yes"<<endl;

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int A,B,M;
    cin >> A >> B >> M;
    vector<int> a(A),b(B);
    for(int i = 0;i < A;i++){
        cin >> a[i];
    }
    for(int i = 0;i < B;i++){
        cin >> b[i];
    }
    int minA = *min_element(a.begin(),a.end());
    int minB = *min_element(b.begin(),b.end());
    int ans = minA + minB;
    for(int i = 0;i < M;i++){
        int x,y,c;
        cin >> x >> y >> c;
        x--;y--;
        
        ans = min(ans,a[x] + b[y] - c);
        
    }
    cout << ans << endl;
    
}

  

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int weight;
	int price_table[] = {
		0, 0, 380, 550, 760, 850, 1100, 1230, 1400, 1610, 1520, 1950,
		1870, 2070, 2250, 2244, 2620, 2624, 2794, 3004, 3040, 3344,
		3390, 3590, 3740, 3764, 4120, 4114, 4314, 4494, 4488, 4864,
		4868, 5038, 5248, 5284, 5588, 5634, 5834, 5984, 6008, 6364,
		6358, 6558, 6738, 6732, 7108, 7112, 7282, 7492, 7528
	};

	while (1) {
		scanf("%d", &weight);
		if (!weight)
			break;
		printf("%d\n", price_table[weight/100]);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
long long n, m, k;
long long ans;
long long x, y;
long long p = 1000 * 1000 * 1000 + 7;
long long rui(long long a, long long b) {
	a %= p;
	if (b == 0) return 1;
	if (b == 1)return a % p;
	if (b == 2)return a * a % p;
	if (b % 2) {
		return rui(rui(a, b / 2), 2) * a % p;
	}
	return rui(rui(a, b / 2), 2);
}
long long inv(long long a) {
	a %= p;
	return rui(a, p - 2);
}
int main() {
	scanf("%lld%lld%lld", &n, &m, &k);
	ans = 1;
	for (int i = 0; i < n; i++) {
		x += i * (n - i); x %= p;
	}
	for (int i = 0; i < m; i++) {
		y += i * (m - i); y %= p;
	}
	ans *= (x * m % p * m % p + y * n % p * n % p); ans %= p;
	ans *= 2; ans %= p;
	ans *= inv(n * m - 1); ans %= p;
	ans *= inv(n * m); ans %= p;
	ans *= k; ans %= p;
	ans *= (k - 1); ans %= p;
	ans *= inv(2); ans %= p;
	for (long long i = 0; i < k; i++) {
		ans *= (n * m - i); ans %= p;
		ans *= inv(i + 1); ans %= p;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y;
  cin>>x>>y;
  if(x==y) cout<<"Draw"<<'\n';
  else if(x==1) cout<<"Alice"<<'\n';
  else if(y==1) cout<<"Bob"<<'\n';
  else if(x>y) cout<<"Alice"<<'\n';
    else if(x<y) cout<<"Bob"<<'\n';
  return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	a := make([]int, n)
	max1, max2 := 0, 0
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
		if a[i] > max1 {
			max1, max2 = a[i], max1
			continue
		}
		if a[i] > max2 {
			max2 = a[i]
		}
	}

	wr := bufio.NewWriter(os.Stdout)
	for _, v := range a {
		if v == max1 {
			wr.WriteString(strconv.Itoa(max2) + "\n")
		} else {
			wr.WriteString(strconv.Itoa(max1) + "\n")
		}
	}
	wr.Flush()
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x1, y1, x2, y2, x3, y3, x4, y4;
  cin>>x1>>y1>>x2>>y2;
  int dx = (x2-x1), dy=(y2-y1);
  y3 = y2+dx;
  x3 = x2-dy;
  x4 = x3-dx;
  y4 = y3-dy;
  cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    while(true){
        int n,m; cin >> n >> m;
        if(n==0 && m==0) break;
        int A[n],B[m];
        int sumA=0,sumB=0;
        int ex=INF;
        pi ans;
        rep(i,n){
            cin >> A[i];
            sumA+=A[i];
        }
        rep(i,m){
            cin >> B[i];
            sumB+=B[i];
        }
        rep(i,n){
            rep(j,m){
                if(sumB-sumA==(B[j]-A[i])*2){
                    if(chmin(ex,A[i]+B[j])){
                        ans=(make_pair(A[i],B[j]));
                    }
                }
            }
        }
        if(ex==INF) cout << -1 << endl;
        else cout << ans.fi << " " << ans.se << endl;
    }
}


Measured memory_bytes: 3040
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let a = get!([usize]);
    let mut set = BTreeSet::new();
    for e in a {
        if set.contains(&e) {
            println!("NO");
            return;
        }
        set.insert(e);
    }
    println!("YES");
}


Measured memory_bytes: 14588
n = gets.chomp.to_i
xs = gets.chomp.split(' ').map(&:to_i)

xs = xs.sort

if n == 1
  puts 0
  exit
end

results = []

((xs.first)..(xs.last)).each do |x1|
  results << xs.map { |x2| (x2 - x1) * (x2 - x1) }.reduce(:+)
end

puts results.min


Measured memory_bytes: 1916
#include <iostream>

using namespace std;

struct card
{
	char suit;
	int value;
}a[100], a1[100];

int main()
{
	void bubble_sort(struct card a[],int n);
	void seletion_sort(struct card a1[],int n);
	void print(struct card b[],int n);
	bool is_stable(struct card a[],struct card a1[],int n);
	int n, i;
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> a[i].suit >> a[i].value;
	}
	for(i = 0; i < n; i++)
	{
		a1[i] = a[i];
	}
	bubble_sort(a,n);
	seletion_sort(a1,n);
	print(a,n);
	cout << "Stable" << endl;
	print(a1,n);
	if(is_stable(a,a1,n))
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
	
	return 0;
}

void bubble_sort(struct card a[],int n)
{
	int i, j;
	for(i = 0; i < n - 1; i++)
	{
		for(j = 0; j < n - 1 - i; j++)
		{
			if(a[j].value > a[j + 1].value)
			{
				card d = a[j];
				a[j] = a[j + 1];
				a[j + 1] = d;
			}
		}
	}
}

void seletion_sort(struct card a1[],int n)
{
	int i, j;
	for(i = 0; i < n; i++)
	{
		int minj = i;
		for(j = i; j < n; j++)
		{
			if(a1[j].value < a1[minj].value)
			{
				minj = j;
			}
		}
		card d = a1[i];
		a1[i] = a1[minj];
		a1[minj] = d;
	}
}

void print(struct card b[],int n)
{
	int i;
	for(i = 0; i < n; i++)
	{
		if(i > 0)
		{
			cout << " ";
		}
		cout << b[i].suit << b[i].value;
	}
	cout << endl;
}

bool is_stable(struct card a[],struct card a1[],int n)
{
	int i;
	for(i = 0; i < n; i++)
	{
		if(a[i].suit != a1[i].suit)
		{
			return false;
		}
	}
	return true;
}


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

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

    // dp
    vector<ll> dp(n); // the cost of to get to scafolld of index_n
    rep(j,n+1) dp[j] = 100100100100100100; // sup
    dp[0] = 0; // The cost is 0 to get to scafolld of index_0.

    rep(j,n){
        dp[j+1] = min(dp[j+1], dp[j] + abs(h[j+1] - h[j])); 
        if(j == n - 2) break; 
        dp[j+2] = min(dp[j+2], dp[j] + abs(h[j+2] - h[j]));
    }

    // output
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
const log = console.log;

const createScanFunctions = (input: string) => {
  const str = input.trim();
  const len = str.length;
  let index = 0;

  const scan = () => {
    const startIndex = index;

    while (index < len) {
      const char = str[index];

      if (char === " " || char === "\n")
        return str.substring(startIndex, index++);

      index++;
    }

    return str.substr(startIndex);
  };

  const scanInt = () => parseInt(scan());

  return { scan, scanInt };
};

const scanArray = <T>(scanFunction: () => T, length: number) => {
  const array = new Array<T>(length);
  for (let i = 0; i < length; i++) array[i] = scanFunction();

  return array;
};

// ----

const countSetBits = (bits: number, length = 32): number => {
  let count = 0;

  for (let i = 0; i < length; i += 1) {
    if ((bits & 1) === 1) count += 1;
    bits >>>= 1;
  }

  return count;
};

// ----

function Main(input: string): void {
  const { scanInt } = createScanFunctions(input);

  const n = scanInt();
  const m = scanInt();

  /**
   * Bits to be checked for each light.
   */
  const kBits = new Array<number>(m);

  /**
   * Should be referred by a switch index.
   */
  const kBitArray = [
    0b0000000001,
    0b0000000010,
    0b0000000100,
    0b0000001000,
    0b0000010000,
    0b0000100000,
    0b0001000000,
    0b0010000000,
    0b0100000000,
    0b1000000000
  ];

  for (let lightIndex = 0; lightIndex < m; lightIndex++) {
    kBits[lightIndex] = 0;
    const k = scanInt();

    for (let i = 0; i < k; i++) {
      const s = scanInt(); // switch number
      kBits[lightIndex] += kBitArray[s - 1];
    }
  }

  const p = scanArray(scanInt, m);

  const allLightsOn = (switchBits: number) => {
    for (let lightIndex = 0; lightIndex < m; lightIndex++) {
      const onSwitchCount = countSetBits(switchBits & kBits[lightIndex]);
      if (onSwitchCount % 2 === p[lightIndex]) continue;

      return false;
    }

    return true;
  };

  // validate each switch pattern
  let validPatternCount = 0;
  const len = Math.pow(2, n);

  for (let switchBits = 0; switchBits < len; switchBits++) {
    if (allLightsOn(switchBits)) validPatternCount++;
  }

  log(validPatternCount);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <cstdio>
#include <utility>
#include <bitset>

using namespace std;
typedef long long ll;

int main(){
	int h,w;
	cin >> h >> w;
	vector<string> s(h*w);
	for(int i=0;i<h*w;i++)
		cin >> s[i];
	for(int i=0;i<h*w;i++)
		if(s[i]=="snuke"){
			cout << (char)('A'+i%w) << i/w+1 << endl;
		}
	return 0;
}

Measured memory_bytes: 764
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for _ in range(N)]
ans = 0 
for i in range(N):
    res = C
    for j in range(M):
        res += A[i][j]*B[j]
    if res > 0:
        ans += 1
print(ans)

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

bool a[500][500];
int b[500][500];

int main() {
  int h, w, t, x;
  char c, buf[502];
  while (1) {
    scanf("%d %d\n", &h, &w);
    if (!h && !w) break;
    for (int i=0; i<h; i++) {
      fgets(buf, sizeof(buf), stdin);
      for (int j=0; j<w; j++) {
        a[i][j] = (buf[j]=='*');
      }
    }

    x = 0;
    for (int i=0; i<h; i++) {
      b[i][w-1] = (a[i][w-1] ? 0 : 1);
      if (b[i][w-1] > x) x = b[i][w-1];
      for (int j=w-2; j>=0; j--) {
        b[i][j] = (a[i][j] ? 0 : (b[i][j+1]+1));
        if (b[i][j] > x) x = b[i][j];
      }
    }

    for (int i=1; i<h; i++) {
      for (int j=0; j<h-i; j++) {
        for (int k=0; k<w; k++) {
          b[j][k] = ((b[j][k]<b[j+1][k]) ? b[j][k] : b[j+1][k]);
          t = b[j][k] * (i+1);
          if (t > x) x = t;
        }
      }
    }
    printf("%d\n", x);
  }

  return 0;
}

Measured memory_bytes: 2260
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  if (a.at(0)=='S') {
    cout << "Cloudy" << endl;
  }
  else if (a.at(0)=='C') {
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int main(){
  vector<int> A(3);
  rep(i,3) cin >> A[i];
  sort(all(A));
  if(A[0]==A[1] && A[1]!=A[2]){
    cout << "Yes" << endl;
  }
  else if(A[2]==A[1] && A[0]!=A[1]){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
public class
Main
{
  public void
  run (
    final java.util.Scanner sc,
    final java.io.PrintStream out
    )
  {
    int[ ][ ] d;
    int[ ] a, b;
    int n;
    int i, j, k;

    n = sc.nextInt ( );
    a = new int[ n ];
    b = new int[ n ];
    for ( i = 0; i < n; ++i )
    {
      a[ i ] = sc.nextInt ( );
      b[ i ] = sc.nextInt ( );
    }

    d = new int[ n ][ n ];
    for ( j = 0; j < n; ++j )
      d[ 0 ][ j ] = 0;
    for ( i = 1; i < n; ++i )
    for ( j = 0; j + i < n; ++j )
    {
      d[ i ][ j ] = d[ 0 ][ j ] + d[ i - 1 ][ j + 1 ] + a[ j ] * b[ j ] * a[ j + 1 ] * b[ j + i ];
      for ( k = 1; k < i; ++k )
        d[ i ][ j ] = Math.min ( d[ i ][ j ], d[ k ][ j ] + d[ i - k - 1 ][ j + k + 1 ] + a[ j ] * b[ j + k ] * a[ j + k + 1 ] * b[ j + i ] );
    }
    out.println ( d[ n - 1 ][ 0 ] );
  }

  public static void
  main (
    final String[ ] args
    )
  {
    ( new Main ( ) ).run ( new java.util.Scanner ( System.in ), System.out );
  }
}

Measured memory_bytes: 21448
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

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

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


int main()
{
	int x, n;
	cin >> x >> n;
	Vi p(n);
	rep(i, n)  cin >> p[i];

	int ans1;
	for (int i = x; i < 1000; i++) {
		bool f = true;
		for (int u : p) {
			if (i == u) f = false;
		}
		if (f) {
			ans1 = i;
			break;
		}
	}
	int ans2;
	for (int i = x; i > -1000; i--) {
		bool f = true;
		for (int u : p) {
			if (i == u) f = false;
		}
		if (f) {
			ans2 = i;
			break;
		}
	}

	//cout << ans1 << ans2 << endl;
	if (ans1 - x < x - ans2) cout << ans1 << endl;
	else  cout << ans2 << endl;
}


Measured memory_bytes: 3632
import java.util.*;

class Main {
  public static final long MOD = 1000000007;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int S = sc.nextInt();
    boolean first = false;
    boolean end = false;
    int a = S / 100;
    if(a >= 1 && a <= 12) first = true;
    int b = S % 100;
    if(b >= 1 && b <= 12) end = true;
    String ans;
    if(first == true && end == true) ans = "AMBIGUOUS";
    else if(first == false && end == true) ans = "YYMM";
    else if(first == true && end == false) ans = "MMYY";
    else ans = "NA";
    System.out.println(ans);
    
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

Measured memory_bytes: 21716
from functools import reduce
n = int(input())
a = [int(m) for m in input().split()]
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)
def gcd_list(numbers):
    return reduce(gcd, numbers)
a.sort()
new = [a[0]]
for i in range(1, n):
    new.append(a[i] % a[0])

new.sort()

k = gcd_list(new)
for i in range(n):
    if new[i] % k != 0:
        print(1)
        exit()
print(gcd_list(new))

Measured memory_bytes: 14596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int j=0,c=0;
  if(vec.at(j)==2){
    c++;
    cout<<c<<endl;
  }
  else{
    while(j!=1){
      int k=vec.at(j)-1;
      j=k;
      if(c>=N){
        break;
      }
      c++;
    }
    if(c>=N){
      c=-1;
    }
    cout<<c<<endl;
  }
}
      
    

Measured memory_bytes: 640
from itertools import accumulate

def resolve():
    n,k = map(int, input().split())
    ans = 0
    mod = 10**9+7
    dp = [i for i in range(n+1)]
    acc = [0] + list(accumulate(dp))
    for i in range(k-1, n+1):
        r = acc[-1] - acc[n-i]
        l = acc[i+1]
        ans = (ans + r - l + 1) % mod
    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 28764
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
    int n,m,a,b,ans,temp;
    string s;
    cin>>n;
    while(n>0)
    {
        temp=n%10;
        if(temp==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        n/=10;
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
  setprecision(9);
  int n,i,j;
    double k,t;
  cin>>n;
    double a[n+1],d[n+1][n+1];
  for(i=1;i<=n;i++)
    cin>>a[i];
  d[0][0]=1;
  for(i=1;i<=n;i++)
  {
    for(j=0;j<=i;j++)
    {
      d[i][j]=0;
      if(j-1>=0)
      {
        d[i][j]=d[i-1][j-1]*a[i];
      }
      if(j<i)
      {
        d[i][j]+=d[i-1][j]*(1-a[i]);
      }
    }
  }
    double ans=0;
  for(i=(n/2)+1;i<=n;i++)
  ans+=d[n][i];
   printf("%.10lf\n",ans);
  //cout<<ans;
}

Measured memory_bytes: 69760
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;


int solve(int n, int sum, int amax) {
	if (n == 0) {
		if (sum == 0) {
			return 1;
		}
		else {
			return 0;
		}
	}
	else if (amax*n < sum ||0 * n>sum)return 0;
	else {
		int nans=0;
		for (int x =0; x <= amax; ++x) {
			nans+=solve(n-1,sum-x,x-1);
		}
		return nans;
	}
}


int main() {
	while (true) {
		int N,S;cin>>N>>S;
		if(!N)break;
		int ans=solve(N,S,9);
		cout<<ans<<endl;

	}
	return 0;
}


Measured memory_bytes: 3044
from collections import defaultdict
N,X,M = map(int,input().split())
ans = 0
d = defaultdict(lambda:-1)
x = X%M
for n in range(M+100):
    if x in d:
        T = n-d[x]
        break
    else:
        d[x] = n
    x *= x
    x %= M
p = 0
y = x
for m in range(d[x],n):
    p += y
    y *= y
    y %= M

ans = 0
n = N
z = X%M
while n:
    ans += z
    n -= 1
    z *= z
    z %= M
    if z==x:
        ans += n//T*p
        n %= T
print(ans)

Measured memory_bytes: 75244
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>

int main() {
  int X;
  scanf("%d", &X);

  int A = X / 100;
  int B = X % 100;

  std::vector<std::string> res;
  if (0 < A && A <= 12)
    res.push_back("MMYY");
  if (0 < B && B <= 12)
    res.push_back("YYMM");

  if (res.size() > 1)
    return puts("AMBIGUOUS"), 0;
  if (res.empty())
    return puts("NA"), 0;

  printf("%s\n", res[0].c_str());
}


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

typedef long long ll;
typedef pair <int, int> ii;

const int Maxn = 100005;

int n, m;
int a[Maxn];
ii bc[Maxn];

bool Less(const ii &a, const ii &b)
{
    return a.second > b.second;
}

int main()
{
    scanf("%d %d", &n, &m);
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    sort(a, a + n);
    for (int i = 0; i < m; i++)
        scanf("%d %d", &bc[i].first, &bc[i].second);
    sort(bc, bc + m, Less);
    int pnt = 0;
    for (int i = 0; i < m; i++)
        for (int j = 0; j < bc[i].first && pnt < n && a[pnt] <= bc[i].second; j++)
            a[pnt++] = bc[i].second;
    ll res = 0;
    for (int i = 0; i < n; i++)
        res += a[i];
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1408