akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            final int times = Integer.parseInt(br.readLine());
            if (times == 0) { break; }
            
            Map<String, Long> data = new LinkedHashMap<>();
            for (int i=1; i <= times; i++) {
                String[] col = br.readLine().split(" ");
                data.merge(col[0], Long.parseLong(col[1]) * Long.parseLong(col[2]), Long::sum);
            }
            
            long count = data.entrySet().stream()
                .filter(e -> e.getValue() >= 1_000_000)
                .peek(e -> System.out.println(e.getKey()))
                .count();
            if (count == 0) { System.out.println("NA"); }
        }

   }
}

Measured memory_bytes: 31476
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

int main() {
    auto t = string();
    cin >> t;

    replace(t.begin(), t.end(), '?', 'D');
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
int main(void) {
    int r, d, x; cin >> r >> d >> x;
    rep(i, 10) {
        x = r*x -d;
        cout << x << endl;
    }
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
int main() {
	string a;
	string b = "yuiophjklnm";
	while (cin >> a&&a != "#") {
		int c,sum=0;
		bool l = false;
		for (int i = 0; i < a.length(); i++) {
			l = false;
			for (int j = 0; j < b.length(); j++) {
				if (a[i] == b[j]) {
					l = true;
					break;
				}
			}
			if (l) {
				if(i!=0&&c!=2){
					sum++;
				}
				c = 2;
			}
			else {
				if (i != 0 && c != 1)
					sum++;
				c = 1;
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3212
eval"_,*A="+gets.split*?,
s=*$<
q=[]
f=->i{s[i]&.chop&.bytes{|x|A[y=s[i].sum-x-75]+=1;q<<(y+65).chr;f[i+1]if~0<A[x-=65]-=1;A[x]+=1;A[y]-=1;q.pop}||puts(:Yes,q)+exit}
f[0]
puts:No

Measured memory_bytes: 157324
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int a[1000005],b[1000005];
int main()
{
    int n;
    cin >> n;
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        b[a[i]]++;
    }

    for(int i=1;i<=n;i++)
    {
        int x= a[i];
        int f=0;
        for(int j=1;j*j<=x;j++)
        {
            if(x%j==0)
            {
                if(j==a[i])
                {
                    if(b[j]>1)
                    {
                        f=1;
                        break;
                    }
                }
                else
                {
                    if(b[j]>0)
                    {
                        f=1;
                        break;
                    }
                }

                int tmp = a[i]/j;

                if(tmp==a[i])
                {
                    if(b[tmp]>1)
                    {
                        f=1;
                        break;
                    }
                }
                else
                {
                    if(b[tmp]>0)
                    {
                        f=1;
                        break;
                    }
                }

            }
        }

        if(f==0)
            ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 8272
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){
    int i, s, x[26]={};
    char ch;
    while(cin >> ch){
        if ('a' <= ch && ch <= 'z'){
           x[ch - 'a']++;
        } else if ('A' <= ch && ch <= 'Z'){
           x[ch - 'A']++;
        }
    }
    for (i = 0; i < 26;i++){
        printf("%c : %d\n", 'a' + i, x[i]);
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a); i<(b); ++i)
inline ll in() { ll x; cin >> x; return x; }

#define int ll
bool is_prime(int x){
  for (int i=2; i*i<=x; i++)
    if (x%i == 0)
      return false;
  return true;
}
void solve() {
  int x = in();
  while (!is_prime(x)) x++;
  cout << x << endl;
}

#undef int
int main() {
  solve();
}

Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		long n = long.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
		long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] numsSub = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
    long[] numMemos = new long[n];
    long[] numFixes = new long[n];//固定値なら1
    long maxMemo = 0;
    long answer = 1;
    long mod = 1000000007;

    for(long i = 0; i < n; i++)
    {
      if(nums[i] > maxMemo)
      {
        maxMemo = nums[i];
        numFixes[i] = 1;
      }
      numMemos[i] = nums[i];
    }

    maxMemo = 0;

    for(long i = 0; i < n; i++)
    {
    long memo = n-1-i;
      if(numsSub[memo] > maxMemo)
      {
        maxMemo = numsSub[memo];
        if(numFixes[memo] == 1 && numMemos[memo] != maxMemo ||
          numMemos[memo] < maxMemo) answer = 0;//不正なデータがある
      }else
      {
        if(numFixes[memo] == 1 && numMemos[memo] > maxMemo) answer = 0;//不正なデータがある
        if(numFixes[memo] != 1)
        {
          answer *= Math.Min(maxMemo, numMemos[memo]);
          //Console.WriteLine(maxMemo+" "+ numMemos[memo]);
          answer %= mod;
        }
      }
      //Console.WriteLine(answer);
    }
    
		Console.WriteLine(answer);//WriteLineをWriteとすると、改行なしで出力。
	}
}

Measured memory_bytes: 38620
def resolve():
    N = int(input())
    A_list = list(map(int, input().split()))   

    for A in A_list:
        if(A % 2 == 0):
            if (A % 3 != 0) and (A % 5 != 0):
                print("DENIED")
                return

    print("APPROVED")
 
if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3060
n, p = map(int, input().split())
s = input()

ans = 0
mod = [-1 for i in range(p)]
mod[0] = 0

if p == 2 or p == 5:
    for i in range(n):
        if int(s[i]) % p == 0:
            ans += i+1
else:
    mp = 0
    m10 = 1
    for i in range(n-1, -1, -1):
        mp = (mp + int(s[i]) * m10) % p
        m10 = (10 * m10) % p
        mod[mp] += 1

    for m in mod:
        ans += m*(m+1)//2

print(ans)

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int MAX_N = 30, NIL = -1;
// parent親、left左の子、 right右の子
struct Node { int parent, left, right; };
Node T[MAX_N];
int H[MAX_N];


int getSibling(int u){
    if(T[u].parent == NIL) return -1;
    if(T[T[u].parent].left == NIL || T[T[u].parent].right == NIL) return -1;
    else if(T[T[u].parent].left == u) return T[T[u].parent].right;
    else return T[T[u].parent].left;
}

int getDeg(int u){
    if(T[u].left == NIL && T[u].right == NIL) return 0;
    else if(T[u].left == NIL || T[u].right == NIL) return 1;
    else return 2;
}

int getDepth(int u){
    int d = 0;
    while(T[u].parent != -1){
        u = T[u].parent;
        d++;
    }
    return d;
}

int getParent(){
    int p = 0;
    while(T[p].parent != NIL){
        p = T[p].parent;
    }
    return p;
}

// uの初期値は必ず親の節点番号にする
int setHeight(int u){
    int h1, h2; h1 = h2 = 0;
    if(T[u].left != NIL){
        h1 = setHeight(T[u].left) + 1;
    }
    if(T[u].right != NIL){
        h2 = setHeight(T[u].right) + 1;
    }
    return H[u] = max(h1, h2);
}


int main()
{
    int n; cin >> n;
    // 初期化
    rep(i,n) T[i].parent = T[i].left = T[i].right = NIL;
    // 情報入力
    rep(i,n){
        int p; cin >> p;
        int l, r; cin >> l >> r;
        T[p].left = l; T[p].right = r;
        T[l].parent = T[r].parent = p;
    }
    // 各木の高さをセット
    setHeight(getParent());
    rep(i,n){
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, T[i].parent, getSibling(i), getDeg(i), getDepth(i), H[i]);
        if(T[i].parent == NIL) printf("root\n");
        else{
            if(T[i].left == NIL && T[i].right == NIL) printf("leaf\n");
            else printf("internal node\n");
        }
    }
}


Measured memory_bytes: 3204
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<map>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<stack>
#include<string>
#include<complex>
#define pb push_back
#define clr clear()
#define sz size()
#define EPS (1e-8)
#define INF 500000000
#define For(i,a) for(int i=0;i<(int)a;i++)
#define all (a) (a).begin(),(a).end()
#define RES(i) memset(i,0,sizeof(i))
#define EQ(a,b) (abs((a)-(b))<EPS)
#define let(i,a) __typeof(a)i=(a)
#define each(i,a) for(let(i,(a).begin());i!=(a).end();i++)

using namespace std;

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

int main(){
  int t,n,m;

  cin >> t;
  double ma = 0.0;
  int v[110];
  double r[110],p;

  For(i,t){
    cin >> n >> m;
    p = 0.0;
    For(j,m){
      cin >> v[j] >> r[j];
      p += r[j];
    }

    For(j,m){
      r[j] /= p;
    }

    double tmp = 0.0;
    For(j,m){
      tmp += v[j] * r[j];
    }
    ma = max(ma,tmp);
  }
 

  double op = 0.0;
  cin >> n >> m;
  p = 0.0;
  For(j,m){
      cin >> v[j] >> r[j];
      p += r[j];
  }

  For(j,m){
    r[j] /= p;
  }
  
  For(j,m){
    op += v[j] * r[j];
  }

  if(ma-op-(1e-7)+EPS>0)cout << "YES\n";
  else cout << "NO\n";
}

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

int main(){
    int t;
    cin >> t;
    int arr1[t], arr2[t];
    for(int i=0; i<t; i++){
        cin >> arr1[i] >> arr2[i];
    }
    int flag=0;
    for(int i=0; i<=t-3; i++){
        if(arr1[i]==arr2[i] && arr1[i+1]==arr2[i+1] && arr1[i+2]==arr2[i+2]){
            cout << "Yes";
            flag++;
            break;
        }
    }
    if(flag<=0)
        cout << "No";
    return 0;
}


Measured memory_bytes: 3604
def resolve():
    n = int(input())
    lr_list = list()
    for i in range(n):
        a = list(map(int, input().split()))
        lr_list.append(a)

    ans = 0
    for i in range(n):
        groupe = lr_list[i][1] - lr_list[i][0] + 1
        ans += groupe
    print(ans)
resolve()

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
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 /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}



  


int main() {
 int n;
 cin >> n;
 int a[n+1];
 rep (i,n){
   cin >> a[i];
 }
 int cnt = 0;
 rep (i,n){
   if (a[i]%2!=0&&i%2==0) cnt++;
 }
 cout << cnt << endl;
}




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



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

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

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


ll func(ll a,ll b,ll x){
    return floor(a*x/b)-a*floor(x/b);
}

ll a,b,n;

int main()
{
    cin>>a>>b>>n;
    ll ans=0;
    // ll tmp;
    // loop(i,0,a){
    //     tmp=func(a,b,i);
    //     ans=max(ans,tmp);
    // }
    if(n>=b-1){
        ans=func(a,b,b-1);
    }else{
        ans=func(a,b,n);
    }
    
    cout<<ans<<endl;
    return 0;

}




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


class Main{
	
	public static void main(String[] args) throws NumberFormatException, IOException {
	
		int a, b, c, d, e, f;
		String input;
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		
		while ((input = bf.readLine()) != null) {
			String[] dataset = input.split(" ");
			int i = 0;
			a = Integer.parseInt(dataset[i++]);
			b = Integer.parseInt(dataset[i++]);
			c = Integer.parseInt(dataset[i++]);
			d = Integer.parseInt(dataset[i++]);
			e = Integer.parseInt(dataset[i++]);
			f = Integer.parseInt(dataset[i++]);
			
			float y = ((float)(d * c - a * f)) / ((float)(d * b - a * e));
			float x = (c - b * y) / a;
			
			System.out.printf("%.3f ", x);
			System.out.printf(String.format("%.3f\n", y));
		}
	}
}

Measured memory_bytes: 24472
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N,L;cin>>N>>L;
    int all=0; int t=0;
    int d; int ans=10000000; int res;
    for(int i=1; i<=N;i++){
      all = all + L + i -1;
    }

    for(int i=1; i<=N;i++){
      for(int j=1; j<=N; j++){
        if(j!=i) t = t+L+j-1;
      }
      d = abs(all - t);
      if(d<ans){
        ans = d; res = t;
      }

      t=0;

    }

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


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    S = sum(A)
    if N >= S:
        print(N - S)
    else:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 10056
S=list(input())
N=len(S)
answers=[0 for _ in range(N)]
numbers_R=[0 for _ in range(N)]
number=0
for n in range(N-1):
    if S[n]=='R':
        number+=1
        if S[n+1]=='L':
            answers[n+1]+=number//2
            answers[n]+=number-number//2
    else:
        number=0
reverse_S=list(reversed(S))
number=0
reverse_answers=list(reversed(answers))
for n in range(N-1):
    if reverse_S[n]=='L':
        number+=1
        if reverse_S[n+1]=='R':
            reverse_answers[n+1]+=number//2
            reverse_answers[n]+=number-number//2
    else:
        number=0
kotae=list(reversed(reverse_answers))
print(*kotae)


Measured memory_bytes: 92012
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
using namespace std;

int INF = 1e9 + 7;

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

int main() {
	int n, a;
	cin >> n;
	vector<int> cnt(100010, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a;
		if (a == 0) cnt[0]++, cnt[1]++;
		else cnt[a - 1]++, cnt[a]++, cnt[a + 1]++;
	}
	int ans = 0;
	for (int i = 0; i <= 100000; i++) {
		ans = max(ans, cnt[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll powmod(ll a, ll b){
	if(b == 0) return 1;
	if(b & 1) {
		return a * powmod(a, b - 1) % MOD;
	} else {
		ll d = powmod(a, b / 2) % MOD;
		return d * d % MOD;
	}
}

ll sub(ll a, ll b){
	return a + MOD - b;
}

ll inv(ll a){
	return powmod(a, MOD - 2);
}

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

	ll n, k;
	cin >> n >> k;

	ll ans = 0;
	vector<ll> dp(k + 1, 0);
	for(ll i = k; i >= 1; i--){
		ll t = powmod(k / i, n);
		for(ll j = 2 * i; j <= k; j += i){
			t += MOD - dp[j];
			t %= MOD;
		}
		ans += i * t % MOD;
		ans %= MOD;

		dp[i] = t;
	}

	cout << ans << endl;
}


Measured memory_bytes: 3984
leap=[]
while true
	a,b=gets.split().map{|x| x.to_i}
	break if a==0 && b==0
	puts  if leap.size!=0
	leap=[]
	a.upto(b){|n|
		leap<<n if n%400==0 || (n%4==0 && n%100!=0)
	}
	if leap.size==0
		puts "NA"
		leap<<0
	else
		leap.each{|y| puts y}
	end
end

		

Measured memory_bytes: 6112
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        CP sc = new CP();
        int n = sc.nextInt();
        BigInteger[] A = new BigInteger[n];
        BigInteger[] B = new BigInteger[n];
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            B[i] = BigInteger.valueOf(x);
            if (i == 0)
                A[i] = BigInteger.valueOf(x);
            else
                A[i] = BigInteger.valueOf(x).add(A[i - 1]);
        }
        BigInteger res = new BigInteger("0");
        for (int i = 0; i < n; i++) {
            res = res.add(B[i].multiply(A[n - 1].subtract(A[i])));
        }
        System.out.println(res.mod(new BigInteger("1000000007")));
    }

    /*****************************************************************************/
    static class CP {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        public CP() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        int nextInt() {
            return Integer.parseInt(NNNN());
        }

        long nextLong() {
            return Long.parseLong(NNNN());
        }

        double nextDouble() {
            return Double.parseDouble(NNNN());
        }

        String NNNN() {
            while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

        String nextLine() {
            String spl = "";
            try {
                spl = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return spl;
        }
    }
    /*****************************************************************************/
}

Measured memory_bytes: 85704
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
#include <iomanip>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  int A,B,C;
  cin>>A>>B>>C;
  if((C-A)*(C-B)>0) cout<<"No";
  else cout<<"Yes";
return 0;}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N=1e5+5;

int n, ans=1e9;
int len[N];
int a, b, c;

int rec(int idx, int i, int j, int k)
{
	if(idx==n+1)
	{
		if(i==0 || j==0 || k==0)
			return 1e9;
		return abs(i-a) + abs(j-b) + abs(k-c);
	}
	int ans=1e9;
	ans=min(ans, rec(idx+1, i, j, k));
	if(i==0)
		ans=min(ans, rec(idx+1, i+len[idx], j, k));
	if(j==0)
		ans=min(ans, rec(idx+1, i, j+len[idx], k));
	if(k==0)
		ans=min(ans, rec(idx+1, i, j, k+len[idx]));
	if(i>0)
		ans=min(ans, 10 + rec(idx+1, i+len[idx], j, k));
	if(j>0)
		ans=min(ans, 10 + rec(idx+1, i, j+len[idx], k));
	if(k>0)
		ans=min(ans, 10 + rec(idx+1, i, j, k+len[idx]));
	return ans;
}

int32_t main()
{
	IOS;
	cin>>n>>a>>b>>c;
	for(int i=1;i<=n;i++)
		cin>>len[i];
	int ans=rec(1, 0, 0, 0);
	cout<<ans;
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  int D[N];
  rep(i,N) cin>>D[i];
  int M;
  cin >> M;
  int T[M];
  rep(i,M) cin>>T[i];
  sort(D,D+N);
  sort(T,T+M);
  int i=0,j=0;
  while(i<N and j<M){
    if(D[i]==T[j]){
      i++;
      j++;
    }
    else{
      i++;
    }
  }
  if(j==M) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string S; cin >> S;
  int N = S.size();

  ll ans = 0;
  rep(bit, 1 << (N-1)) {
    ll term = S[0] - '0';
    ll sum = 0;
    rep(i, N-1) {
      if (bit & (1 << i)) {
        sum += term;
        term = S[i+1] - '0';
      } else
        term = term * 10 + (S[i+1] - '0');
    }
    sum += term;
    ans += sum;
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 256
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;


int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    vector<int>b(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) cin>>b[i];
    int max=0;
    for(int i=0;i<n;i++){
        int count=0;
        for(int j=0;j<n;j++){
            if(j<i) count+=a[j];
            else if(j==i) count+=a[j]+b[j];
            else count+=b[j];
        }
        if(max<count) max=count;
    }
    cout<<max<<endl;
   
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if ((a + b) == (c + d)) {
  	cout << "Balanced" << endl;
  }
  else if ((a + b) > (c + d)) {
  	cout << "Left" << endl;
  }
  else {
  	cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(std::string s){
    int n = s.size();
    int ans = 0;
    for(int i = 0; i < n / 2; ++i){
        ans += (s[i] != s[n - i - 1]);
    }
    cout << ans << endl;
}


signed main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
using namespace std;
int n,k;struct P
{
	int a[N+5];I P(CI x=0) {for(RI i=1;i<=x;++i) a[i]=i;}
	I int& operator [] (CI x) {return a[x];}I int operator [] (CI x) Con {return a[x];}
 	I friend P operator ~ (Con P& A) {P B;for(RI i=1;i<=n;++i) B[A[i]]=i;return B;}
	I friend P operator * (Con P& A,Con P& B) {P C;for(RI i=1;i<=n;++i) C[i]=A[B[i]];return C;}
}p,q,s,a[10],ans;
I P QP(P x,RI y) {P t=P(n);W(y) y&1&&(t=t*x,0),x=x*x,y>>=1;return t;}
int main()
{
	RI i;for(scanf("%d%d",&n,&k),i=1;i<=n;++i) scanf("%d",&p[i]);for(i=1;i<=n;++i) scanf("%d",&q[i]);
	a[1]=p,a[2]=q,a[3]=a[2]*(~a[1]),a[4]=a[3]*(~a[2]),a[5]=a[4]*(~a[3]),a[6]=a[5]*(~a[4]);
	s=q*(~p)*(~q)*p,ans=QP(s,(k-1)/6)*a[(k-1)%6+1]*QP(~s,(k-1)/6);
	for(i=1;i<=n;++i) printf("%d%c",ans[i]," \n"[i==n]);return 0;
}

Measured memory_bytes: 11972
S = input()

if len(S) % 2 == 1:
    print("No")
    exit()
    
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] != "h":
            print("No")
            exit()
    else:
        if S[i] != "i":
            print("No")
            exit()

print("Yes")

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

// [l, r), l and r is 0-indexed.
template<typename T>
using Interval = tuple<int, int, T>;
template<typename T>
struct Imos {
    int n;
    vector<T> s;
    Imos(const int n, const vector<Interval<T>> &intervals) : n(n) {
        s.resize(n + 1, 0);
        for (auto interval : intervals) {
            T v = std::get<2>(interval);
            s[std::get<0>(interval)] += v;
            s[std::get<1>(interval)] -= v;
        }
        for (int i = 0; i < n; ++i) s[i + 1] += s[i];
    }
    int size() {
        return n;
    }
    T get(int i) {
        return s[i];
    }
};

/*
    verified https://onlinejudge.u-aizu.ac.jp/problems/DSL_5_A
*/
int main() {
    int n, t; cin >> n >> t;
    vector<Interval<long long>> intervals(n);
    for (int i = 0; i < n; ++i) {
        int l, r; cin >> l >> r;
        intervals[i] = make_tuple(l, r, 1);
    }
    Imos<long long> imos(t, intervals);
    long long res = numeric_limits<long long>::min();
    for (int i = 0; i < imos.size(); ++i) {
        res = max(res, imos.get(i));
    }
    cout << res << endl;
}



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

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

  bool flag = true;
  for (int i = 0; i < s.size();i++) {
    if (i%2==1&& s[i]=='R')  flag = false;
    if (i%2==0&& s[i]=='L')  flag = false;
  }

  if (flag) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  // int val = 0;
  // cout<<val<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10000)

def solve(i,wa,use):
    global ct,s,n
    if wa==s and use==n:
        ct+=1
        return
    if use>n or i==10 or wa>s:
        return
    solve(i+1,wa,use)
    solve(i+1,wa+i,use+1)

while 1:
    n,s=map(int,raw_input().split())
    if n==0 and s==0:
        break
    ct=0
    wa=0
    solve(0,0,0)
    print ct

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

#define INF 1<<29

template <typename T>
struct MaxFlow {
  struct Edge {
    int to, rev; T cap;
    Edge(int to, int rev, T cap) : to(to), rev(rev), cap(cap) { }
  };

  typedef vector<Edge> Edges;
  vector<Edges> G;
  int V;
  vector<int> level, iter;
  
  MaxFlow(int V) : V(V) { G.resize(V); }

  void add_edge(int from, int to, T cap) {
    G[from].push_back(Edge(to, (int)G[to].size(), cap));
    G[to].push_back(Edge(from, (int)G[from].size()-1, 0));
  }

  void bfs(int source) {
    level.assign(V, -1);
    queue<int> que;
    que.push(source);
    level[source] = 0;
    while (!que.empty()) {
      int v = que.front(); que.pop();
      for (int i = 0; i < (int)G[v].size(); i++) {
	Edge &e = G[v][i];
	if (e.cap > 0 && level[e.to] < 0) {
	  level[e.to] = level[v] + 1;
	  que.push(e.to);
	}
      }
    }
  }

  T dfs(int v, int sink, T flow) {
    if (v == sink) return flow;
    for (int &i = iter[v]; i < (int)G[v].size(); i++) {
      Edge &e = G[v][i];
      if (e.cap > 0 && level[v] < level[e.to]) {
	T d = dfs(e.to, sink, min(e.cap, flow));
	if (d > 0) {
	  e.cap -= d;
	  G[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }

  T dinic(int source, int sink) {
    T flow = 0;
    while (true) {
      bfs(source);
      if (level[sink] < 0) return flow;
      iter.assign(V, 0);
      T f;
      while ((f = dfs(source, sink, INF)) > 0) {
	flow += f;
      }
    }
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int V, E;
  cin >> V >> E;
  MaxFlow<int> mf(V);
  REP(i, E) {
    int u, v, c;
    cin >> u >> v >> c;
    mf.add_edge(u, v, c);
  }
  cout << mf.dinic(0, V-1) << endl;  
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef ll _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

ll h,w;
int main() {
    cin>>h>>w;

    if(h%3==0 || w%3==0){
        cout << "0" << endl;
        return 0;
    }

    ll ans = LONG_MAX;

    //≡
    ans = w*((h/3)+1)-w*(h/3);

    //|||
    ans = min(ans, h*((w/3)+1)-h*(w/3));

    // T
    FOR(i,1,h){
        ll a,b,c;
        ll imax = -1;
        ll imin = LONG_MAX;
        a = i*w;
        b = (h-i)*(w/2);
        if(w%2==1)
            c = (h-i)*((w/2)+1);
        else
            c = (h-i)*(w/2);

        imax = max(a,b);
        imax = max(imax,c);

        imin = min(a,b);
        imin = min(imin,c);

        if(ans > imax-imin)
            ans = imax-imin;
    }

    //|-
    FOR(i,1,w){
        ll a,b,c;
        ll imax = -1;
        ll imin = LONG_MAX;
        a = i*h;
        b = (w-i)*(h/2);
        if(h%2==1)
            c = (w-i)*((h/2)+1);
        else
            c = (w-i)*(h/2);

        imax = max(a,b);
        imax = max(imax,c);

        imin = min(a,b);
        imin = min(imin,c);

        if(ans > imax-imin)
            ans = imax-imin;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    bool one = false, two = false;
    while (t--)
    {
        int a, b;
        cin >> a >> b;
        if (a == b)
        {
            if(two){
                cout << "Yes\n";
                return 0;
            }
            if(one){
                two = 1;
                continue;
            }
            one = 1;
        }
        else{
            one = two = false;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3580
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0


a,b=LI()
if a+b==15:
    ans='+'
elif a*b==15:
    ans='*'
else:
    ans='x'

print(ans)


Measured memory_bytes: 41964
n, m, x = map(int, input().split())

A = []
for i in range(n):
    A.append(list(map(int, input().split())))

# print(A)

ans = float("inf")
for i in range(2 ** n):
    skill = [0] * (m+1)
    for j in range(n):
        if ((i >> j) & 1):
            for k in range(m+1):
                skill[k] += A[j][k]


    # print(ans, skill)

    if skill:
        for i in range(1, m+1):
            if x > skill[i]:
                break
        else:
            ans = min(ans, skill[0])

if ans == float("inf"):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9208
X, K, D = map(int, input().split())

X = abs(X)

candidate1 = abs(X - K*D)
candidate2 = abs(X % D)
candidate3 = candidate2 - D

count2 = (X - candidate2)//D
if (K - count2) % 2==0:
    count2ok = True
else:
    count2ok = False


count3 = (X - candidate3)//D
if (K - count3) % 2==0:
    count3ok = True
else:
    count3ok = False

candidate3 = abs(candidate3)

if abs(X) - K*D > 0:
    print(candidate1)
elif count2ok == True and count3ok == True:
    print(min([candidate1, candidate2, candidate3]))
elif count2ok == True:
    print(min([candidate1, candidate2]))
elif count3ok == True:
    print(min([candidate1, candidate3]))
else:
    print(candidate1)

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

int main(){
  int h, n;
  int *a;
  int i;
  
  scanf("%d %d", &h, &n);
  if((a = (int*)malloc(sizeof(int)*n)) == NULL){
    printf("malloc");
    return 0;
  }
  
  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
  }
  
  for(i=0; i<n; i++){
    h -= a[i];
    if(h <= 0){
      break;
    }
  }
  
  if(h > 0){
    printf("No");
  }else{
    printf("Yes");
  }
  return 0;
}

Measured memory_bytes: 512
n = gets.to_i

if n < 4
    puts 'No'
elsif n%4 == 0 || n%7 == 0
    puts 'Yes'
else
    flag = false
    while n >= 7
        n -= 7
        if n%4 == 0
            flag = true
            break
        end
    end
    
    if flag
        puts 'Yes'
    else
        puts 'No'
    end
end


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
    long long N;
    int min=99;
    cin>>N;
    long long RN=sqrt(N);
    for(long long i=1;i<=RN;i++){
            if(N%i==0){
            int j=N/i;
            string C1=to_string(i);
            int digit1=C1.length();
            string C2=to_string(j);
            int digit2=C2.length();
            if(digit1<digit2) digit1=digit2;
            if(min>digit1) min=digit1;
            }
            if(i*i==N) break;
    }
    cout<<min;
    return 0;
}

Measured memory_bytes: 256
import itertools
[N,M,X] = list(map(int,input().split()))

C = []
A = []
for i in range(N):
    tmp = list(map(int,input().split()))
    C.append(tmp[0])
    A.append(tmp[1:])

TF = [0,1]
L = list(itertools.product(TF, repeat=N))

out = float('inf')
for K in L:
    Cost = 0
    ML = [0]*M
    for i in range(N):
        if K[i]==1:
            for j in range(M):
                ML[j]+=A[i][j]
            Cost+=C[i]
    flag = 1
    for j in range(M):
        if ML[j]<X:
            flag = 0
    if flag==1:
        if Cost < out:
            out = Cost

if out!=float('inf'):
    print(out)
else:
    print(-1)

Measured memory_bytes: 9672
d1 = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
d2 = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
d3 = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]
n = int(input())
m = "MARCH"
s = [input() for i in range(n)]
d = {"M":0, "A":0, "R":0, "C":0, "H":0}
for i in range(n):
    if s[i][0] in d:
        d[s[i][0]] += 1
tot = 0
for j in range(10):
    tot += d[m[d1[j]]]*d[m[d2[j]]]*d[m[d3[j]]]
print(tot)

Measured memory_bytes: 9776
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
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 x;

int main() {
    cin >> x;
    int ll = LCM(x, 360);
    cout << ll/x << endl;
}

Measured memory_bytes: 3636
n = int(input())
multiple_3_num = n // 3
multiple_5_num = n // 5
multiple_3_and_5_num = n // (3*5)
sum = 0
for i in range(1,n+1):
    sum += i
minus_num = 0
for i in range(1,multiple_3_num+1):
    minus_num += 3*i
for i in range(1,multiple_5_num+1):
    minus_num += 5*i
for i in range(1,multiple_3_and_5_num+1):
    minus_num -= 3*5*i
print(sum - minus_num)

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

int main(){
    int n; cin >> n;
    priority_queue<double,vector<double>,greater<double> > v;
    rep(i,n){
        double a; cin >> a;
        v.push(a);
    };
    double ans = 0;
    rep(i,n-1){
        double x,y,z;
        x = v.top(); v.pop();
        y = v.top(); v.pop();
        z = (x+y)/2;
        v.push(z);
    }
    ans = v.top();
    cout << fixed << setprecision(12) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void printArray(int num, int[] array) {
		for(int i = 0; i < num; i++) {
			if(i != 0) {
				System.out.print(" ");
			}
			System.out.print(array[i]);
		}
		System.out.println("");
	}

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] array = new int[100];
		int num;
		int j;
		int v;

		// 入力
		num = scan.nextInt();
		for(int i = 0; i < num; i++) {
			array[i] = scan.nextInt();
		}

		// ソート＆出力
		printArray(num, array);
		for(int i = 1; i < num; i++) {
			v = array[i];
			j = i - 1;
			while(j >= 0 && array[j] > v) {
				array[j + 1] = array[j];
				j--;
			}
			array[j+1] = v;
			printArray(num, array);
		}


	}
}


Measured memory_bytes: 32132
h,w,k = map(int,input().split())
s = [list(input()) for i in range(h)]
a = [[0]*w for i in range(h)]
num = 1
for i in range(h):
  b = s[i]
  if "#" in b:
    t = b.count("#")
    for j in range(w):
      c = b[j]
    #  print(c)
      if c=="#" and t!=1:
        a[i][j] = num
        num += 1
        t -= 1
      elif c=="#" and t==1:
        a[i][j] = num
        t = -1
      else:
        a[i][j] = num
    if t==-1:
      num += 1
  else:
    if i==0:
      continue
    else:
      for j in range(w):
        a[i][j] = a[i-1][j]
index = 0

for i in range(h):
  if "#" not in s[i]:
    index += 1
  else:
    break
for j in range(index):
  for k in range(w):
    a[j][k] = a[index][k]
for j in a:
  print(*j)

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

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

const int MX = 1e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define ps(x) cout << x << "\n";
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define rall(x) (x).rbegin(), (x).rend() 
#define rsz resize
#define ins insert 

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
		ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
		// cin.exceptions(cin.failbit); 
		// throws exception when do smth illegal
		// ex. try to read letter into int
		if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int N;

int main() {
	cin >> N;

	int a = 0, b = 0;
	F0R(i, N) {
		int x; cin >> x;
		if (x & 1) b++;
		else a++;
	}

	a += b / 2;
	b = b % 2;

	if (!a && !b) {
		ps("NO");
	}
	else if (b && a) {
		ps("NO");
	}
	else if (a == 1 && !b) {
		ps("YES");
	}
	else if (b == 1 && !a) {
		ps("YES");
	}
	else if (b % 2 == 0 || a % 2 == 0) {
		ps("YES");
	}
	else {
		ps("NO");
	}
}







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

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

    if (H % h == 0 && W % w == 0)
    {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    const int x = int(1e9);
    if (W % w != 0)
    {
        for (int r = 0; r < H; r++)
        {
            for (int c = 0; c < W; c++)
            {
                if (c % w == 0)
                    cout << x-1 << " ";
                else if (c % w == w-1)
                    cout << -x << " ";
                else
                    cout << 0 << " ";
            }
            cout << "\n";
        }
    }
    else
    {
        for (int r = 0; r < H; r++)
        {
            for (int c = 0; c < W; c++)
            {
                if (r % h == 0)
                    cout << x-1 << " ";
                else if (r % h == h-1)
                    cout << -x << " ";
                else
                    cout << 0 << " " ;
            }
            cout << "\n";
        }
    }
}


Measured memory_bytes: 2944
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')

# input macro
def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())
def join(s):
    return ''.join(s)

#memoize macro
def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

nh=zip([1,0,-1,0],[0,1,0,-1])
mod=1000000007

###########
n=i()
t=ii()
a=ii()
just=[0]*n
ub=[INF]*n
lb=[0]*n

def justa(x,y):
    if just[x] in [0,y]:
        just[x]=y
    else:
        print '0'
        sys.exit()

justa(0,t[0])
justa(n-1,a[n-1])

for j in range(1,n):
    if t[j]!=t[j-1]:
        justa(j,t[j])
    else:
        ub[j]=t[j]
for j in reversed(range(0,n-1)):
    if a[j]!=a[j+1]:
        justa(j,a[j])
    else:
        ub[j]=min(ub[j],a[j])

ans=1
for j in range(1,n):
    if just[j]==0:
        ans=ans*ub[j]%mod
    elif just[j]<=ub[j]:
        ans=ans
    else:
        print '0'
        sys.exit()

print ans
    


Measured memory_bytes: 14864
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
typedef pair<ll,ll> P;
int dfs(int n){
  if(n==0){
    return 0;
  }
  int now=n;
  int co=0;
  while(now>0){
    if(now%2==1){
      co++;
    }
    now/=2;
  }
  return dfs(n%co)+1;
}
int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;
  int tot=0;
  rep(i,n){
    if(s[i]=='1'){
      tot++;
    }
  }
  
  vector<int>com(n),cop(n);
  int p=1;
  rep(i,n){
    if(tot>1){
    com[i]=p%(tot-1);
    p=p*2%(tot-1);
    }
  }
  p=1;
  rep(i,n){
    
    cop[i]=p%(tot+1);
    p=p*2%(tot+1);
    
  }
  int tm=0;
  int tp=0;
  rep(i,n){
    if(s[n-1-i]=='1'){
      if(tot>1){
    tm=(tm+com[i])%(tot-1);
      }
    tp=(tp+cop[i])%(tot+1);
    }
  }
  rep(i,n){
    int nowm=tm;
    int nowp=tp;
    if(s[i]=='1'){
      if(tot<=1){
        cout<<0<<endl;
      }
      else{
      nowm=(nowm+tot-1-com[n-1-i])%(tot-1);
      cout<<dfs(nowm)+1<<endl;
      }
    }
    else{
      nowp=(nowp+cop[n-1-i])%(tot+1);
      cout<<dfs(nowp)+1<<endl;
    }
  }
  
}




Measured memory_bytes: 5220
#include <bits/stdc++.h>
 
#define ll long long
#define loop(a) loopi(i,a)
#define loopi(i,a) for(int i=0; i<a; i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
 
using namespace std;
 
const int mod=1e9+7;
 
int main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	int a,b,c;
	cin >> a >> b >> c;
	if(a+b+c>21) cout << "bust\n";
	else cout << "win\n";
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef unsigned long long ll;
#define MAX_N 101
#define MAX_W 10001

int dp[MAX_N][MAX_W];
void init(){
	rep(i,MAX_N){
		rep(j,MAX_W) dp[i][j] = 0;
	}
}


int main()
{
	init();
	int N,W;
	cin>>N>>W;
	int *v = new int[N];
	int *w = new int[N];
	rep(i,N){
		cin>>v[i]>>w[i];
	}

	rep(i,N){
		rep(j,W+1){
			if( j >= w[i]){
				dp[i+1][j] = max(dp[i][j],dp[i+1][j-w[i]] + v[i]);
			}else{
				dp[i+1][j] = dp[i][j];
			}
		}
	}
	cout<<dp[N][W]<<endl;

	return 0;
}




Measured memory_bytes: 7044