akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = "";
			while((s=Console.ReadLine())!=null)
			{
				var n = double.Parse(s);
				Console.WriteLine((int)Math.Ceiling((n * n / (9.8 * 2) + 5) / 5));
			}
		}
	}
}

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

int n;
vector<int> arr(100004, 0);
vector<int> dp(100004, -1);

int main() {

	cin >> n;
	for(int i=0; i<n; ++i) cin >> arr[i];

	dp[n-1] = 0;
	dp[n-2] = abs(arr[n-1] - arr[n-2]);

	for(int i=n-3; i>=0; --i) dp[i] = min(abs(arr[i]-arr[i+1])+dp[i+1], abs(arr[i]-arr[i+2])+dp[i+2]);

	cout << dp[0] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long N,A,B,a,ans;
int main(){
    cin>>N;
    cin>>A;
    while(--N){
        cin>>B;
        if(A!=B){
            if(!a)a=B>A?1:-1;
            else if(a>0&&A>B)++ans,a=0;
            else if(a<0&&A<B)++ans,a=0;
        }
        A=B;
    }
    cout<<ans+1<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int a,b,ab,x,y;
    cin>>a>>b>>ab>>x>>y;
    int apb = a+b;
    if(ab*2>apb){
        int sum = x*a+y*b;
        cout<<sum<<endl;
    }
    else{
        int ans = inf;
        int min1 = min(x,y);
        int sum = ab*min1*2;
        //cout<<sum<<endl;
        //最低min1分はabで買う
        x -= min1;
        y -= min1;
        //cout<<x<<" "<<y<<endl;
        for(int i = 0;i <=x;i++){
            for(int j = 0;j<=y;j++){
                //aをi枚,jをb枚個別で買う
                //cout<<"check"<<i<<" "<<j<<endl;
                int copy = sum;
                copy+=a*i+b*j;
                copy+=ab*2*max(x-i,y-j);
                ans = min(ans,copy);
                //cout<<copy<<" "<<ans<<endl;
                //cout<<endl;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値

// nCk を取得
void f(int res , string s){
     if(res==0){
       cout << s << endl;}
   else{
     for(char c='a'; c<='c'; c++){
        f(res -1, s + c);}
   }
}
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}

int main() {
cout << fixed << setprecision(8);
long double a,b,c;
cin>>a>>b>>c;
long double d = a*b;
if(c-a-b<=0){
cout<<"No"<<endl;}
else{
long double e = (c-a-b)*(c-a-b)/4;
if(d<e){
cout<<"Yes"<<endl;}
else
cout<< "No" <<endl;}}


Measured memory_bytes: 3764
#include <cstdio>
 
int main()
{
    int matrix[4][4];
 
    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= 3; j++)
            scanf("%d", &matrix[i][j]);
 
    int A[4];
    int B[4];
 
    A[1] = 51;
    B[1] = matrix[1][1] - A[1];
    B[2] = matrix[1][2] - A[1];
    B[3] = matrix[1][3] - A[1];
    A[2] = matrix[2][1] - B[1];
    A[3] = matrix[3][1] - B[1];
 
    int is_possible = true;
    for(int i = 1; i <= 3; i++)
        for(int j = 1; j <= 3; j++)
            if(A[i] + B[j] != matrix[i][j])
                is_possible = false;
 
    printf(is_possible ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 128
/*------------------------------------------------,
|  __                                       __    |
| |  |--.-----.---.-.----.----.-----.-----.|  |_  |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _| |
| |_____|_____|___._|____|____|_____|   __||____| |
|                                   |__|          |
`------------------------------------------------*/
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define MOD 10000007
#define REP(i, lower, upper) for (long long i = lower; i < upper; i++)
#define ALL(ls) ls.begin(), ls.end()
typedef long long ll;
using namespace std;

int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
vector<long long> divisor(long long n) {// if 2,it's prime
  vector<long long> ret;
  for(long long i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  return (ret);
}

void execute(){

  int h;
  int w;
  int k;
  cin >> h >> w >> k;
  char mark[h][w];
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      cin >> mark[i][j];
    }
  }
  int ans = 0;
  for (int bith = 0; bith < (1 << h); bith++)
  {
    for (int bitw = 0; bitw < (1 << w); bitw++)
    {
      int black = 0;
      for (int i = 0; i < h; i++)
      {
        for (int j = 0; j < w; j++)
        {
          if (!(bith & (1 << i)) && !(bitw & (1 << j)))
          {
            if (mark[i][j] == '#')
              black++;
          }
        }
      }
      if (black == k)
        ans++;
    }
  }
  cout << ans << endl;
}
int main() {

  cin.tie(0);
  ios::sync_with_stdio(0);
  //cout<<fixed<<setprecision(20);

  execute();

  return 0;
}


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

int main() {
  map<string,int> mon;
  queue<string> str;
  int N,M;
  cin >> N;
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    str.push(s);
    mon[s]++;
  }

  int ans = 0;
  
  cin >> M;
  for (int i = 0; i < M; i++) {
    string s;
    cin >> s;
    mon[s]--;
  }
  
  for (pair<string,int> p :mon) {
    ans = max(ans,p.second);
  }

  
  cout << ans << endl; 
  
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace _0611
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] road = new int[x[0]];
            for (int i = 0; i < x[0]; i++)
            {
                road[i] = int.Parse(Console.ReadLine());
            }
            int[] weather = new int[x[1]];
            for (int i = 0; i < x[1]; i++)
            {
                weather[i] = int.Parse(Console.ReadLine());
            }
            int[,] dp = new int[x[1] + 1,x[0] + 1];
            for (int i = 1; i <= x[0]; i++)
            {
                dp[0,i] = 1000000000;
            }
            for (int i = 1; i <= x[1]; i++)
            {
                for (int j = 1; j <= x[0]; j++)
                {
                    dp[i,j] = Math.Min(dp[i - 1,j - 1] + road[j - 1] * weather[i - 1],dp[i - 1,j]);
                }
            }
            Console.WriteLine(dp[x[1],x[0]]);
        }
    }
}


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

int count_round_mine(vector<vector<char>> S, int H, int W)
{
  int result = 0;
  for (int i = H - 1; i < H + 2; i++)
  {
    if (i < 0 || i + 1 > S.size())
      ;
    else
    {
      for (int j = W - 1; j < W + 2; j++)
      {
        if (j < 0 || j + 1 > S[i].size())
          ;
        else
        {
          if (S[i][j] == '#')
            result++;
        }
      }
    }
  }

  return result;
}

int main()
{
  int H, W;
  cin >> H >> W;

  vector<vector<char>> S(H, vector<char>(W));

  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      cin >> S[i][j];
    }
  }

  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (S[i][j] == '#')
        cout << '#';
      else
        cout << count_round_mine(S, i, j);
    }
    cout << endl;
  }
}


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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);


int main(){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) {
        int a;
        cin >> a;
        A[i] = a;
    }

    vector<int> B;
    ll sum = 0;
    ll ans = 0;
    int right = 0;
    for (int left=0; left<N; left++) {
        while((sum+A[right])==(sum^A[right]) && right<N) {
            sum += A[right];
            right++;
        }
        ans += right-left;
        if (left==right) right++;
        else {
            sum -= A[left];
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 4372
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <stack>
#include <queue>
#include <set>

#define mod 1000000007
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll count(ll n){
    if(n == 1) return 1;
    return 2*count(n/2)+1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k, n;
    ll ans = 0;
    cin >> n >> k;
    if(n <= k){
        cout << 0;
        return 0;
    }
    vector<ll> h(n);
    rep(i,n){
        cin >> h[i];
        ans+=h[i];
    }
    sort(h.begin(), h.end(),greater<int>());
    rep(j,k){
        ans-=h[j];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){
  int N, X;
  int x[100000];
  int ans = 1e9;
  
  cin >> N >> X;
  for(int i = 0;i < N;i++){
    cin >> x[i];
    x[i] = abs(x[i] - X);
    ans = min(ans, x[i]);
  }
  
  for(int i = 0;i < N;i++) ans = __gcd(ans, x[i]);
  
  cout << ans << endl;
  
  return 0;
}

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

int n;
int a[100];
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      sum += a[i] * a[j];
    }
  }
  cout << sum << endl;
}

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

#include <vector>

int main() {
    int r, c;
    cin >> r >> c;
    vector<vector<int> > v(r+1, vector<int>(c+1, 0));
    for(int i=0; i<r; i++) {
	for(int j=0; j<c; j++) {
	    int n;
	    cin >> n;
	    v[i][j] = n;
	    v[i][c] += n;
	    v[r][j] += n;
	    v[r][c] += n;
	}
    }

    for(int i=0; i<=r; i++) {
	for(int j=0; j<=c; j++) {
	    if(j != 0)
		cout << " ";
	    cout << v[i][j];
	}
	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1256
import java.util.Scanner;

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

        int n = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= n; i++ ) {
            if (String.valueOf(i).length() % 2 == 1) {
                ans++;
            }
        }
        System.out.println(ans);
        sc.close();
    }
}

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

void trace(int a[], int n){
    for(int i = 0; i < n; i++){
        cout << a[i];
        if (i != n - 1) cout << " ";
        else cout << endl;
    }
}

int bubbleSort(int a[], int n){
    int flag = 1, count = 0;
    while(flag){
        flag = 0;
        for(int j = n - 1; j > 0; j--){
            if(a[j - 1] > a[j]){
                int temp = a[j - 1];
                a[j - 1] = a[j];
                a[j] = temp;
                flag = 1;
                count++;
            }
        }
    }

    return count;
}

int main(void){
    int n, a[100], c;

    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];

    c = bubbleSort(a, n);
    trace(a, n);
    cout << c << endl;

    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int c,n,m,s,p;
  cin>>c>>n>>m;
  int dp[c+1]={};
  for(int i=0;i<n;i++){
    cin>>s>>p;
    for(int j=c;j>=0;j--) if(j-s>=0) dp[j]=max(dp[j],dp[j-s]+p);
  }
  for(int i=1;i<=m;i++) cout<<dp[c/i]*i<<endl;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  int pr, ps, pp;
  cin >> pr >> ps >> pp;
  string t;
  cin >> t;

  i64 score = 0;
  REP(i, n) {
    int pt = 0;
    if (t[i] == 'r') {
      pt += pp;
    } else if (t[i] == 's') {
      pt += pr;
    } else {
      pt += ps;
    }
    if (i >= k && t[i - k] == t[i]) {
      pt = 0;
    }
    if (pt == 0) {
      t[i] = '_';
    }
    score += pt;
  }
  cout << score << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int M = 0;
    for ( int i = 0; i < N; ++i){
        cin >> A.at(i);
        M = max(A.at(i),M);
    }
    vector<int> idx;
    int M2 = 0;
    for ( int i = 0; i < N; ++i){
        if ( A.at(i) == M ){
            idx.push_back(i);
        } else {
            M2 = max(M2,A.at(i));
        }
    }
    
    if ( idx.size() != 1 ){
        for ( int i = 0; i < N; ++i){
            cout << M << endl;
        }
    } else {
        for ( int i = 0; i < N; ++i){
            if ( i != idx.at(0) ){
                cout << M << endl;
            } else {
                cout << M2 << endl;
            }
        }
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 3316
#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 spn setprecision
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 = 2e5;
const int mod = 1e9+7;
ll sum[upperlimit+1];
ll nc2(int n){
	ll r=n;
	r*=n-1;
	r/=2;
	return r;
}
map<ll, int> M;
int main() {
	M[0]=1;
	int n,inp;
	ll temp,ans=0;
	sd(n);
	for(int i = 1; i <= n; i++){
		sd(inp);
		sum[i]=sum[i-1]+inp;
		M[sum[i]]++;
	}
	for(auto it:M){
		ans+=nc2(it.S);
	}
	plld(ans);
	return 0;
}

Measured memory_bytes: 14336
//#define _GLAIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <cassert>
using namespace std;
const long long mod = (1e9) + 7;

long long mod_inv(long long x){
  long long k = mod - 2, ret = 1;
  while(k){
    if(k&1) ret *= x, ret %= mod;
    x *= x, x %= mod;
    k >>= 1;
  }
  return ret;
}

int main(){
  int N;
  cin >> N;
  vector<long long> A(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  long long f = 1;
  for(int i = 1; i <= N; ++i) f *= i, f %= mod;
  vector<long long> F(N+1,0);
  for(int i = 1; i <= N; ++i) F[i] = mod_inv(i);
  for(int i = 0; i < N; ++i) F[i+1] += F[i], F[i+1] %= mod;
  long long ans = 0;
  for(int i = 1; i <= N; ++i){
    long long t = 0;
    t += (F[i]+F[N-i+1])%mod;
    t += mod - 1, t %= mod;
    t *= f, t %= mod;
    ans += (t*A[i-1])%mod;
    ans %= mod;
    //cerr << i << " " << t << endl;
  }
  cout << ans << endl;
  return 0;
}


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

string s[10] = {
	"0111111",
	"0000110",
	"1011011",
	"1001111",
	"1100110",
	"1101101",
	"1111101",
	"0100111",
	"1111111",
	"1101111",
};


int main(void){
	int n;
	while(cin>>n, (n!=-1)){
		string now = "0000000";
		for(int i=0;i<n;i++){
			int x;
			cin>>x;
			string change = "0000000";
			for(int i=0;i<7;i++){
				if(s[x][i] != now[i]){
					change[i] = '1';
				}
			}
			cout<<change<<endl;
			now = s[x];
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int count(int n)
{
    string s = to_string(n);
    int sum = 0;
    for (int i=0; i<s.size(); i++)
        sum += s[i] - '0';
    return sum;
}

int main() 
{
    int n, a, b;
    cin >> n >> a >> b;
    int sum = 0;
    for (int i=0; i<=n; i++)
    {
        int x = count(i);
        // cout << x << endl;
        if (x>=a && x<=b)
            sum+=i;
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int Q = sc.nextInt();
        sc.nextLine();
        int[] ans = new int[N];
        int[] ten = new int[N];

        for (int i = 0; i < Q; i++) {
            int a = sc.nextInt();
            ten[a-1] += 1; 
        }
        
        for (int i = 0; i < N; i++) {
            ans[i] = K - Q;
            if(ans[i]+ten[i]>0) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
        sc.close();
    }
}

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

void fail(){
    cout << "No" << endl;
    exit(0);
}

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    if(A*2 > W) fail();
    if(B*2 > H) fail();
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            int v = (i<B) == (j<A);
            cout << v;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
int main(){
    int N; cin >> N;
    vector<vector<pair<int, int>>> a(N);
    for (int i = 0; i < N; i++)
    {
        int A; cin >> A;
        for (int j = 0; j < A; j++)
        {
            int x, y; cin >> x >> y;
            x--;
            a[i].push_back(make_pair(x, y));
        }
    }

    int ans = 0;
    for (ll i = 0; i < (1<<N); i++)
    {
        bool flag = true;
        for (int j = 0; j < N; j++)
        {
            if(!flag) break;
            if(!((i>>j) & 1)) continue;
            for (int k = 0; k < a[j].size(); k++)
            {
                if((a[j][k].second==1 && !((i>>a[j][k].first)&1)) || (a[j][k].second==0 && ((i>>a[j][k].first)&1))){
                    flag = false;
                    break;
                }
            }
        }
        if(flag) ans = max(ans, __builtin_popcount(i)); 
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    double A = nextDouble();
    double B = nextDouble();
    double N = nextDouble();

    long[] kou = new long[3];



    double ans = 0;

    int cnt = 0;

    double x = B-1.0;

    if(x>N){
      x = N;
    }

    ans = (x/B) - (long)(x/B);

    //System.out.println("小数点:"+ans);

    ans *= A;

    System.out.println((long)ans);

  }

  static int lcm(int a,int b){
    return a*b*gcd(a,b);
  }

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

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


Measured memory_bytes: 35724
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int s(int n) {
  int r = 0;
  while(n) {
    r += n%10;
    n /= 10;
  }
  return r;
}

int main() {
  int n, a, b;
  scanf("%d%d%d", &n, &a, &b);
  int r = 0;
  for(int i = 1; i <= n; i++) {
    int ss = s(i);
    if(a <= ss && ss <= b) r += i;
  }
  printf("%d\n", r);
}


Measured memory_bytes: 256
#include <stdio.h>

void line(int w, char a, char b) {
	int i;
	for (i = 0; i < w; i++) {
		if (i % 2 == 0) printf("%c", a);
		else printf("%c", b);
	}
	printf("\n");
	return;
}

int main(void) {
	int h, w, i;
	while (1) {
		scanf("%d%d", &h, &w);
		if (h == 0 && w == 0) break;
		for (i = 0; i < h; i++)
		{
			if (i % 2 == 0) line(w, '#', '.');
			else line(w, '.', '#');
		}
		printf("\n");
	}
	return 0;
}



Measured memory_bytes: 2096
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(string, S);
    IN(string, T);
    ll ans = 0;
    REP(i, S.size())
    {
        ans += S[i] != T[i];
    }
    OUT(ans);
}

Measured memory_bytes: 3920
def print_result(arr, n):
    for i in range(n):
        if i > 0:
            print(' ', end='')
        print(arr[i], end='')
    print('\n', end='')


def bubble_sort(arr, n):
    flag = True
    i = 0
    sw_count = 0
    while flag:
        flag = False
        for j in range(n-1, i, -1):
            if arr[j] < arr[j-1]:
                arr[j], arr[j-1] = arr[j-1], arr[j]
                flag = True
                sw_count += 1
        i += 1
    return sw_count


n = eval(input())
arr = [eval(x) for x in input().split()]
sw = bubble_sort(arr, n)
print_result(arr, n)
print(sw)




Measured memory_bytes: 5596
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
 
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
 
T lread(T = long)()
{
    return readln.chomp.to!T();
}
 
T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}
 
void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long n = lread();
    string s = sread();
    long k = lread();

    char c = s[k - 1];
    foreach(i;s)
    {
        if(i == c)
        {
            write(i);
        }
        else
        {
            write("*");
        }
    }
    writeln();
}

Measured memory_bytes: 256
from math import fsum
s = [0] * 1001
for i in range(1, len(s)):
    s[i] = s[i - 1] + i
N, K = map(int, input().split())
exps = [s[p] / p for p in map(int, input().split())]
exp = fsum(exps[:K])
ans = exp
for i in range(K, N):
    exp = fsum((exp, -exps[i - K], exps[i]))
    if ans < exp:
        ans = exp
print(ans)

Measured memory_bytes: 23588
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;




int main(){FIN
    
    REP(i,5){
        ll a;cin>>a;
        if(a==0) {
            cout<<i+1<<endl;
            return 0;
        }
    }
    
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  if ( (N - N/1000*1000)%111 == 0 || N/10%111 == 0){
	cout << "Yes" << endl;
  }
  else {
    cout <<"No" <<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,m,q;
    cin>>n>>m>>q;
    int a[n+1][n+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++)
        a[i][j]=0;
    }
    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;
        a[l][r]++;
    }
    int b[n+1][n+1];
     for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++)
        b[i][j]=0;
    }
    for(int j=1;j<=n;j++){
        b[j][j]=a[j][j];
        for(int i=j-1;i>=1;i--){
          b[i][j]=b[i+1][j]+a[i][j];  
        }
    }
    int ans[n+1][n+1];
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++)
        ans[i][j]=0;
    }
    for(int i=1;i<=n;i++){
        ans[i][i]=a[i][i];
        for(int j=i+1;j<=n;j++){
            ans[i][j]=ans[i][j-1]+b[i][j];
        }
    }
   /* for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++)
        cout<<b[i][j]<<" ";
        cout<<endl;
    }*/
    while(q--){
        int p,q;
        cin>>p>>q;
        cout<<ans[p][q]<<"\n";
    }
}


Measured memory_bytes: 3840
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
        string a = Console.ReadLine();
        int[] ret = new int[26];
        for (int j = 0; j <= 'z' - 'a'; j++)
        {
            int i = j + 'a';
            int maxvalue = 0, KOushin = 0;
            for (int k = 0; k < a.Length; k++)
            {
                if (a[k] == (char)i) { maxvalue = Math.Max(maxvalue, KOushin);/*maxvalue < KOushin ? KOushin : maxvalue;*/ KOushin = 0; }
                else { KOushin++; }
            }maxvalue = Math.Max(maxvalue, KOushin);
            ret[j] = maxvalue;
        }
        Array.Sort(ret);
        Console.WriteLine(ret[0]);
    }
    public static Boolean uso() { return false; }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b)
    {
        return a * b / gcd(a, b);
    }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;

        for (long i = 2; i < n; i++)
        {
            if (n % i == 0) return false;
        }
        return true;
    }

}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] longs()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }
    public static int Int()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] ints()
    {
        return Console.ReadLine().Split().Select(int.Parse).ToArray();
    }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 11092
Alice, Bob = map(int, input().split())
if Alice == 1 and Bob == 1:
  print("Draw")
elif Alice == 1 and Bob != 1:
  print("Alice")
elif Alice != 1 and Bob == 1:
  print("Bob")
elif Alice > Bob:
  print("Alice")
elif Alice == Bob:
  print("Draw")
else:
  print("Bob")

Measured memory_bytes: 9004
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#define int long long
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define FOR(i,a,b)  for(int i = (a); i <= (b); ++i)

using namespace std;
constexpr int MOD = 10e9+7;
constexpr int INF = 1LL << 60;
template <class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}  
template <class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}  

class Solve {
public:
    int N;
    vector<int> primeNum;
    int pNum (const int & i){
        return  count_if(primeNum.begin(),primeNum.end(),[&i](const auto& x){return x >= i ;});
    }
    Solve(int _N);
    void exe();
}; 

Solve::Solve(int _N) :
    N(_N),primeNum(_N+1,0)
{
}

void Solve::exe(){
    FOR(i,2,N){
        int isPrime = 1;
        FOR(j,2,i-1){
            if(i % j == 0) isPrime = 0;
        }

        if(isPrime) {
            int p = i;
            int tmp = N/p;
            while(tmp > 0){
                
                tmp = N/p;
                primeNum[i] += tmp;
                p *= i;
            }
        } else {
            primeNum[i] = -1; //素数でない
        }
    }
    int ans = pNum(74) + pNum(24)*(pNum(2)-1/*同じものは使えない*/) + (pNum(4)-1) * pNum(14) + (pNum(2)-2)*pNum(4) * (pNum(4)-1)/2;//4,4の時、二つ選ぶ、つまりnC2をしなくちゃいけない
    cout << ans << endl;
 
}


signed main (){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int N;
    cin >> N;
    Solve solve(N);
    solve.exe();
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <memory.h>
#include <vector>
#include <queue>
#include <map>

using namespace std;
typedef long long LL;
const int maxn = 100005;
#define fi first
#define se second
#define pb push_back

typedef pair<int,int> mp;
vector<int> a[maxn],b[maxn];
int p[maxn],sa[maxn],sb[maxn],n,que[maxn],tail;
int findp(int u) {return p[u]?p[u]=findp(p[u]):u;}
mp mkpr(int u,int v) {u=findp(u);v=findp(v);return u<v?mp(u,v):mp(v,u);}
map<mp,int> H;
queue<mp> Q;
void insert(mp w,int o) {if (H[w]!=3) {H[w]|=o;if (H[w]==3) Q.push(w);}}

int merge(int u,int v)
{
	u=findp(u);v=findp(v);
	if (u==v) return 0;
	if (sa[u]+sb[u]<sa[v]+sb[v]) swap(u,v);
	p[v]=u;sa[u]+=sa[v];sb[u]+=sb[v];
	for (int j=0;j<sa[v];j++) {
		int x=findp(a[v][j]);a[u].pb(x);
		if (x!=u) insert(mkpr(u,x),1);
	}
	for (int j=0;j<sb[v];j++) {
		int x=findp(b[v][j]);b[u].pb(x);
		if (x!=u) insert(mkpr(u,x),2);
	}
	return 1;
}
int main()
{
	#ifdef Amberframe
		freopen("agc014e.in","r",stdin);
		freopen("agc014e.out","w",stdout);
	#endif
	scanf("%d",&n);
	for (int u,v,i=1;i<n;i++)
		scanf("%d %d",&u,&v),a[u].pb(v),a[v].pb(u),insert(mkpr(u,v),1),sa[u]++,sa[v]++;
	for (int u,v,i=1;i<n;i++)
		scanf("%d %d",&u,&v),b[u].pb(v),b[v].pb(u),insert(mkpr(u,v),2),sb[u]++,sb[v]++;
	int cnt=0;
	while (!Q.empty()) {
		mp cur=Q.front();Q.pop();
		cnt+=merge(cur.fi,cur.se);
	}
	printf("%s",cnt==n-1?"YES":"NO");
	return 0;
}

Measured memory_bytes: 38104
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <iomanip>
#include <sstream>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

template <typename T>
T gcd(T a, T b) {
	while (b != 0) {
		T temp = a;
		a = b;
		b = temp % b;
	}

	return a;
}

// cout << setfill('0') << setw(5) << number < endl;
// while(getline(cin, s)) { .. } | `s` is a string

void solve() {
	int n;
	cin >> n;
	vector<int> h(n);
	vector<ll> dp(n);
	for (auto &it : h)
		cin >> it;

	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (int i = 2; i < n; ++i) {
		dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
	}

	cout << dp[n-1] << endl;
}


int main(){
	IOS;
	
	
	int t = 1;
	// cin >> t;
	while(t--)
		solve();

	return 0;
}



























 

Measured memory_bytes: 1408
#include <cstdio>           // printf(), scanf()
#include <vector>
#include <queue>
#include <algorithm>        // max()

using namespace std;

static const int MAX_N = 100000;
static const int INFTY = -1;

class edge
{
public:
	int t, w;
	edge() {}
	edge(int t, int w): t(t), w(w) {}
};

vector<edge> G[MAX_N];
int n;
int d[MAX_N];

bool vis[MAX_N];
int count;

void
bfs(int s)
{
	for (int i = 0; i < n; ++i)
		d[i] = INFTY;

	queue<int> Q;
	Q.push(s);
	d[s] = 0;
	while(!Q.empty())
	{
		int u = Q.front(); Q.pop();
		for (unsigned int i = 0; i < G[u].size(); ++i)
		{
			edge e = G[u][i];
			if (d[e.t] == INFTY)
			{
				d[e.t] = d[u] + e.w;
				Q.push(e.t);
			}
		}
	}
}

int
solve()
{
	// ??????????????? s ???????????????????????? tgt ????±???????
	bfs(0);
	int maxv = 0;
	int tgt = 0;
	for (int i = 0; i < n; ++i)
	{
		if (d[i] > maxv)
		{
			maxv = d[i];
			tgt = i;
		}
	}

	// tgt ????????????????????????????????¢ maxv ????±???????
	bfs(tgt);
	maxv = 0;
	for (int i = 0; i < n; ++i)
		maxv = max(maxv, d[i]);

	return maxv;
}

int
main(int argc, char** argv)
{
	int s, t, w;

	scanf("%d", &n);
	for (int i = 0; i < n - 1; ++i)
	{
		scanf("%d %d %d", &s, &t, &w);
		G[s].push_back(edge(t, w));
		G[t].push_back(edge(s, w));
	}

	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 9444
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;

int a[MAXN], b[MAXN], c[MAXN];
long long tot[MAXN];

int main ()
{
    int n;
    scanf ("%d", &n);
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%d", &a[i]);
    }
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%d", &b[i]);
    }
    for (int i = 1; i <= n; i ++)
    {
        scanf ("%d", &c[i]);
    }
    sort (a + 1, a + n + 1);
    sort (b + 1, b + n + 1);
    sort (c + 1, c + n + 1);
    memset (tot, 0, sizeof (tot));
    int now = 1;
    for (int i = 1; i <= n; i ++)
    {
        while ((now <= n) && (a[now] < b[i]))
        {
            now ++;
        }
        tot[i] = (long long) now - 1 + tot[i - 1];
    }
    now = 1;
    long long ans = 0;
    for (int i = 1; i <= n; i ++)
    {
        while ((now <= n) && (b[now] < c[i]))
        {
            now ++;
        }
        ans += tot[now - 1];
    }
    printf ("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define rb(a) scanf("%lf", &a)
#define rf(a) scanf("%f", &a)
#define pd(a) printf("%d\n", a)
#define plld(a) printf("%lld\n", a)
#define pc(a) printf("%c\n", a)
#define ps(a) printf("%s\n", a)
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _  ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1100000, INF = 0x7fffffff, MOD = 1e9 + 7;

LL D[maxn], U[maxn];
LL q_pow(LL a, LL b)
{
    LL ret = 1;
    while(b)
    {
        if(b & 1) ret = ret * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ret;
}

void init()
{
    U[0] = D[0] = 1;
    for(int i = 1; i < maxn; i++)
    {
        U[i] = U[i - 1] * i % MOD;
        D[i] = q_pow(U[i], MOD - 2);
    }
}

LL C(LL n, LL m)
{
    return U[n] * D[m] % MOD * D[n - m] % MOD;
}

int main()
{
    init();

    LL h, w, a, b, ret = 0;
    cin >> h >> w >> a >> b;
    for(int i = b + 1; i <= w; i++)
    {
        ret = (ret + C(h - a + i - 2, i - 1) * C(a - 1 + w - i, a - 1)) % MOD;
     //   cout << C(h - a + i - 2, i - 1) << "    " << C(a - 1 + w - i, a - 1) << endl;
    }
   ret = (ret % MOD + MOD) % MOD;
   cout << ret << endl;




    return 0;
}

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

using namespace std;

typedef long long ll;

ll solve(int n) {
    vector<ll> step(n);
    step[0] = 1;
    if( n > 1 ) step[1] = 2;
    if( n > 2 )  step[2] = 4;
    for(int i=3; i < n; ++i){
        step[i] = step[i-3] + step[i-2] + step[i-1];
    }
    return step[n-1];
}

ll getdays(ll ptns){
    if(ptns % 10 == 0) return ptns / 10;
    else return ptns / 10 + 1;
}

ll getyears(ll days){
    if(days % 365 == 0) return days / 365;
    else return days / 365 + 1;
}

int main(){
    int n;
    while(true) {
        cin >> n;
        if(n == 0) break;
        cout << getyears(getdays(solve(n))) << endl;
    }
}

Measured memory_bytes: 1192
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
typedef long long int Int;
const int N = 3;

Int gcd(Int a, Int b){
  if(b == 0) return a;
  else return gcd(b, a%b);
}

Int lcm(Int a, Int b){
  return a / gcd(a, b) * b;
}

int main() {
  Int A[N], M[N];
  while(true){
    REP(i, N) cin >>A[i] >>M[i];
    if(A[0] == 0) break;
    Int v[N], num[N];
    REP(i, N){
      Int cnt = 1;
      v[i] = A[i] % M[i];
      while(v[i] != 1){
        v[i] = A[i] * v[i] % M[i];
        ++cnt;
      }
      num[i] = cnt;
    }
    cout <<lcm(num[0], lcm(num[1], num[2])) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int cnt = 0;
  for(int i=0; i<N; i++)
    if((i % 2 == 0 && S[i] == '0') ||
       (i % 2 == 1 && S[i] == '1'))
      cnt++;
  cout << min(N-cnt, cnt) << endl;
  return 0;
}

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

using namespace std;
#define int long long
signed main() {
    int h, w, k;
    cin >> h >> w >> k;
    string str[h];
    int i, j;
    for(i=0;i<h;i++)
        cin >> str[i];
    int ans = 0;
    for(i=0;i<(1 << h);i++)
    {
        for(j=0;j<(1 << w);j++)
        {
            char arr[h][w];
            int n, m;
            for(n=0;n<h;n++)
                for(m=0;m<w;m++)
                    arr[n][m] = str[n][m];
            for(n=0;n<h;n++)
                if((i >> n)&1)
                {
                    for(m=0;m<w;m++)
                        arr[n][m] = 'R';
                }
            for(n=0;n<w;n++)
                if((j >> n)&1)
                {
                    for(m=0;m<h;m++)
                        arr[m][n] = 'R';
                }
            int val = 0;
            for(n=0;n<h;n++)
                for(m=0;m<w;m++)
                    if(arr[n][m] == '#')
                        val++;
            if(val == k)
            {
                ans++;
                // cout << i << " " << j << '\n';
                // for(n=0;n<h;n++)
                // {
                //     for(m=0;m<w;m++)
                //         cout << arr[n][m];
                //     cout << '\n';
                // }
                // cout << '\n';
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3628
f=0
while 1:
  n=input()
  if n==0: break
  if f>0: print
  N=[""]*n
  C=[0]*n
  for i in range(n):
    s=raw_input()
    p=s.index(" ")
    N[i]=s[:p]
    a,b,c=map(int,s[p+1:].split(" "))
    C[i]=(i,a*3+c)
  C=sorted(C,key=lambda x:(-x[1],x[0]))
  for e in C: print "".join([N[e[0]],",",str(e[1])])
  f=1

Measured memory_bytes: 4240
from math import gcd
from functools import reduce


def pairwise_coprime(a):
    check = [set() for _ in range(10 ** 6 + 10)]
    for i, aa in enumerate(a):
        now = aa
        while now % 2 == 0:
            if len(check[2]) > 0 and i not in check[2]:
                return False
            now //= 2
            check[2].add(i)
        f = 3
        while f * f <= now:
            if now % f == 0:
                if len(check[f]) > 0 and i not in check[f]:
                    return False
                now //= f
                check[f].add(i)
            else:
                f += 2
        if now != 1:
            if len(check[now]) > 0 and i not in check[now]:
                return False
            check[now].add(i)
    return True


def main():
    n = int(input())
    a = list(map(int, input().split()))
    if pairwise_coprime(a):
        print("pairwise coprime")
    elif reduce(gcd, a) == 1:
        print("setwise coprime")
    else:
        print("not coprime")


if __name__ == '__main__':
    main()


Measured memory_bytes: 214780
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
int main() {
  ios::sync_with_stdio(0); 
  cin.tie(0); 
  
  int n, m;
  cin >> n >> m;

  unordered_map<int, int> mp;

  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    mp[u]++, mp[v]++;
  }

  for (int i = 1; i <= n; ++i) {
    cout << mp[i] << "\n";
  }
}


Measured memory_bytes: 3656
#include <stdio.h>

int main(void)
{
  unsigned X, ureshisa = 0;
  scanf("%u", &X);
  ureshisa += (X / 500) * 1000;
  ureshisa += ((X % 500) / 5) * 5;
  printf("%u\n", ureshisa);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
typedef long long ll;
int main() {
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	q *= 4;
	h *= 2;
	s = min(s, min(q, h));
	cout << min(s*n, d*(n / 2) + s*(n % 2)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

int n;
pair<ll, ll> p[200005];
ll INF = 1000000000000000000;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	ll mama = -1, mimi = INF, mami = INF, mima = -1, mai, mii;
	FOR(i, n) {
		ll x, y;
		cin >> x >> y;
		if (x > y) swap(x, y);
		mimi = min(mimi, x);
		mima = max(mima, x);
		mami = min(mami, y);
		mama = max(mama, y);
		p[i] = make_pair(x, y);
	}
	ll res = (mama-mami) * (mima-mimi);

	sort(p, p+n);

	ll ma = p[n-1].first;
	ll mi = INF, mmi = INF;
	FOR(i, n-1) {
		mi = min(mi, p[i].second);
		mmi = min(mi, p[i+1].first);
		ma = max(ma, p[i].second);
		res = min(res, (mama-mimi)*(ma-min(mi,mmi)));
	}

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>

using namespace std;

int main()
{
  string S;
  cin>>S;
  if(S.length()==4){
      if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3]){
          cout<<"Bad";
      }
      else{
          cout<<"Good";
      }
  }
    
    return 0;
}

Measured memory_bytes: 3636