akhauriyash/Code-Regression huggingface dataset:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
num = [0 for _ in range(5)]
arr = ['M', 'A', 'R', 'C', 'H']
for _ in range(n):
    s = STR()
    if s[0] in arr:
        num[arr.index(s[0])] += 1
ans = 0
arr2 = list(combinations(range(5), 3))
for i in range(len(arr2)):
    tmp = 1
    for j in arr2[i]:
        tmp *= num[j]
    ans += tmp
print(ans)


Measured memory_bytes: 5332
#include<stdio.h>
#include<string.h>
int main(){
  int i;
  char weather[10];
  char wt_list[3][10] = {"Sunny","Cloudy","Rainy"};
  scanf("%s",weather);
  for(i=0;i<3;i++){
  	if(strcmp(weather,wt_list[i]) == 0){
  	  printf("%s",wt_list[(i+1)%3]);
  	}
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x,i,ans=1;
  cin>>n>>x;
  int l[n+1];
  l[0]=0;
  for(i=1;i<=n;i++)
  {
    cin>>l[i];
    l[i]+=l[i-1];
    if(l[i]<=x) ans++;
    else break;
  }
  cout<<ans;
  
  return 0;
}

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

using namespace std;

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

int main() {
  int N;
  cin >> N;
  vi a(N + 1);
  for (int i = 0; i < N; i++) cin >> a[i + 1];

  vi ans(N + 1);
  for (int i = N; i >= 1; i--) {
    ans[i] = a[i];
    if (ans[i]) {
      for (int j = 1; j * j <= i; j++) {
        if (i % j == 0) {
          a[j] = 1 - a[j];
          if (j * j != i) a[i / j] = 1 - a[i / j];
        }
      }
    }
  }

  vi v;
  for (int i = 1; i <= N; i++) {
    if (ans[i]) v.push_back(i);
  }

  cout << v.size() << endl;
  int n = v.size();
  for (int i = 0; i < n; i++) {
    cout << v[i];
    if (i != n - 1) cout << ' ';
    else cout << endl;
  }
}


Measured memory_bytes: 4980
//url:
//problem name:

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N;
    cin >> N;
    int K;
    cin >> K;
    set<int> res;
    REP(i,K) {
        int d; cin >> d;
        REP(j,d) {
            int a; cin >> a;
            res.insert(a);
        }
    }
    cout << N - res.size() << endl;
}


Measured memory_bytes: 3632
# 複数の値をキーにするソートを行うため、クラスを作成した。

# レストランを紹介する本のクラス。
class Book:
  	# インスタンス
    def __init__(self, no, name, value):
      	# レストラン番号(0から開始する)
        self.no = no
        # レストラン名
        self.name = name
        # レストラン評価
        self.value = value
# 本のクラスの配列。
book = []
n = int(input())
for i in range(n):
  	# レストラン名、レストラン評価
    s, p = input().split()
    book.append(Book(i, s, int(p)))

# レストラン評価の降順で整列する。
book = sorted(book, key=lambda b: b.value, reverse=True)
# レストラン名で整列する。
book = sorted(book, key=lambda b: b.name)
for b in book:
  	# 本に紹介されるレストラン順で表示する。
    print(b.no+1)


Measured memory_bytes: 9200
S=input()

if 1<=int(S[:2])<=12:
  if 1<=int(S[2:])<=12:
    print("AMBIGUOUS")
  elif 0<=int(S[2:])<=99:
    print("MMYY")
elif 0<=int(S[:2])<=99:
  if 1<=int(S[2:])<=12:
    print("YYMM")
  elif 0<=int(S[2:])<=99:
    print("NA")



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int x; cin>>x;
	int ans1 = 0, ans2 = 0;
	ans1 += x/500; x -= ans1*500;
	ans2 += x/5;
	cout << ans1*1000+ans2*5 << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**9
eps = 10**-7

N,M = map(int,input().split())
# 1-indexed union-find
# parent(親)
par = [i for i in range(N+1)]
# rank(深さ)
rank = [0]*(N+1)
# 同グループの頂点数
# size = [1]*(N+1)

# 木の根を求める
def root(x):
    if par[x] == x:             # 根の時
        return x
    else:
        par[x] = root(par[x])   # 経路圧縮
        return par[x]

# xとyの属する集合を併合(ランク有)
def unite(x,y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    if rank[x] < rank[y]:
        par[x] = y              # xの親をyに
        #size[y] += size[x]      # yの頂点数+=xの頂点数
    else:
        par[y] = x              # yの親をxに
        #size[x] += size[y]      # xの頂点数+=yの頂点数
        if rank[x] == rank[y]:
            rank[x] += 1

LRD = [tuple(map(int,readline().split())) for i in range(M)]

for (L,R,D) in LRD:
    unite(L,R)

from collections import defaultdict,deque
rel = defaultdict(lambda: [])

for (L,R,D) in LRD:
    rel[root(L)].append((L,R,D))

for k,v in rel.items():
    dist = defaultdict(lambda: [])
    for (L,R,D) in v:
        dist[L].append((R,D))
        dist[R].append((L,-D))
    que = deque([])
    x = {}
    for k1,v1 in dist.items():
        x[k1] = 0
        for (to,dis) in v1:
            x[to] = dis
            que.append(to)
        break
    while que:
        fro = que.popleft()
        for (to,dis) in dist[fro]:
            if to not in x.keys():
                x[to] = x[fro] + dis
                que.append(to)
    for (L,R,D) in v:
        if x[R] - x[L] != D:
            print('No')
            exit()
print('Yes')


    



Measured memory_bytes: 191664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include<queue>
#include<math.h>
#include <iomanip>
#define rep(i,n) for (int i=0; i<(n);++i)
using namespace std;
using ll=long long;
const ll INF = 1LL << 60;
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; }
const double PI = 3.14159265358979323846;
const ll d =1000000007;
ll A[200000], B[200000];
pair<ll, string> p;
using Graph=vector<vector<int>>;



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

	rep(i, T.size()) {
		if (T[i] == '?') T[i] = 'D';
	}
	
	cout << T << endl;

	return 0;
}

Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int a,b,c;
		a = sc.nextInt();
		b = sc.nextInt();
		c = sc.nextInt();
		
		String ret;
		if ((a+b == c) || (a+c == b) || (b+c == a)){
			System.out.println("Yes");
			return;
		}
		System.out.println("No");
		
		
		
		
	}
}


Measured memory_bytes: 10324
use std::collections::HashMap;

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

fn main() {
    let (n, k) = get!(usize, usize);
    let v = get!([usize]);
    let mut map = HashMap::new();
    for i in 0..n {
        let counter = map.entry(v[i]).or_insert(0);
        *counter += 1;
    }
    let mut p = Vec::new();
    for (_key, val) in map.iter() {
        p.push(*val);
    }
    if p.len() <= k {
        println!("0");
        return;
    }
    p.sort_by(|a, b| b.cmp(&a));
    let mut t = 0;
    for i in 0..k {
        t += p[i];
    }
    println!("{}", n - t);
}


Measured memory_bytes: 17872
#include <iostream>
using namespace std;
int main(void){
    string s;
    std::cin >> s;
    string k="2019/04/30";
    if(s<=k){
        std::cout << "Heisei" << std::endl;
    }else{
        std::cout << "TBD" << std::endl;
    }
    
}


Measured memory_bytes: 256
#n=int(input())
x,n=map(int,input().split())
pl=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]
ans=x
if not x in pl:
    ans=x
else:
    for i in range(1,1000):
        x1=x+i
        x2=x-i
        if not x2 in pl:
            ans=x2
            break
        elif not x1 in pl:
            ans=x1
            break
print(ans)


Measured memory_bytes: 9140
A, B, C = map(int, input().split())

if A == B == C and A%2 == 1:
    print('0')
elif A == B == C:
    print('-1')
else:
    ans = 0
    while A%2 == B%2 == C%2 == 0:
        A, B, C = B//2+C//2, A//2+C//2, A//2+B//2
        ans += 1
    print(ans)


Measured memory_bytes: 9124
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = (ll)a;i < (ll)b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = (ll)b-1LL;i >= (ll)a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N, long long M){
  cout<<(N*(N-1)/2)+(M*(M-1)/2)<<endl;
}

int main(){
  cout<<setprecision(1000);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    solve(N, M);
    return 0;
}


Measured memory_bytes: 256
import math

N, D = map(int, input().split())

l = []
cnt = 0
for _ in range(N):
    if len(l) == 0:
        l.append([int(x) for x in input().split()])
    else:
        new_point = [int(x) for x in input().split()]
        for known_point in l:
            sum_val = 0
            for i in range(D):
                sum_val += (new_point[i] - known_point[i]) ** 2

            root = math.sqrt(sum_val)
            if root == int(root):
                cnt += 1

        l.append(new_point)

print(cnt)


Measured memory_bytes: 3064
N = int(input())
l = list(map(int,input().split()))
def GCD(a,b): #Greatest Common Diverser
	x = max(a,b)
	y = min(a,b)
	if x % y == 0:
		return y
	else:
		while x % y != 0:
			z = x % y
			x = y
			y = z
		else:
			return y


ans = l[0]
for i in range(N):
	ans=GCD(ans,l[i])
print(ans)

Measured memory_bytes: 14252
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0

for coin500 in range(a+1):
    for coin100 in range(b+1):
        for coin50 in range(c+1):
            if coin500 * 500 + coin100 * 100 + coin50 * 50 == x:
                ans += 1
print(ans)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
    int a, b, c, x, ans = 0;
    cin >> a >> b >> c >> x;
    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= b; j++){
            for(int k = 0; k <= c; k++){
                if(500 * i + 100 * j + 50 * k == x)
                    ans += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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


using namespace std;

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

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

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

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

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

LL gcd(LL a, LL b) {
	if (b == 0) return a;

	return gcd(b, a%b);
}

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

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

	vector<LL> t(n);

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

	LL ans = t[0];

	for (int i = 1; i < n; i++) {
		ans = lcm(ans, t[i]);
	}

	cout << ans << endl;

	return 0;
}

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

int main(void) {
    int N, M;
    cin >> N >> M;
    const int NMMAX = 50;
    int A[NMMAX], B[NMMAX];
    for (int i=0;i<M;++i){ 
        cin >> A[i] >> B[i];
    }
    int road[NMMAX];
    for (int i=0;i<N;++i){
        road[i] = 0; }
        for (int i=0;i<M;++i){ road[A[i] - 1] += 1; road[B[i] - 1] += 1;
        }
        for (int i=0;i<N;++i){ cout << road[i] << endl;
        }
        return 0;
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<numeric>
#include<sstream>
#include<cmath>
using namespace std;
int main(){

  int n, m; cin >> n >> m;
  vector< pair<long long int, long long int> > p(n);
  for(int i=0; i<n; i++) cin >> p[i].first >> p[i].second;
  sort(p.begin(), p.end());
  long long int ans = 0;
  for(int i=0; i<n; i++){
    ans += p[i].first * p[i].second;
    m -= p[i].second;
    if(m < 0) {
      ans -= p[i].first * (-m);
      break;
    }
  }
  cout << ans << endl;


  return 0;
}


//


Measured memory_bytes: 1792
import java.util.Scanner;

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

        String a = sc.next();
        String b = sc.next();
        if (a.equals(b))
            System.out.println("H");
        else
            System.out.println("D");
    }
}

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

long long N, Q, A[1 << 17], X[1 << 17], V[1 << 17], B[1 << 17];

long long ranged(long long L1, long long R1) {
	return B[R1 + 1] - B[L1];
}

long long query(long long Z) {
	long long L = 0, R = N + 1, M, minx = N + 1;
	for (int i = 0; i < 30; i++) {
		M = (L + R) / 2;

		pair<long long, long long> V = make_pair(N - M, N - (M + 1LL) / 2LL - 1LL); // 順当に行った場合の区間
		bool ok = false; // 違反しているか
		if (V.first <= V.second) {
			long long SUB = max(abs(Z - A[V.first]), abs(Z - A[V.second]));
			if (0LL <= V.second + 1 && V.second - 1 < N && abs(Z - A[V.second + 1]) < SUB) ok = true; // 左すぎ！
		}

		if (ok == true) { minx = min(minx, M); R = M; }
		else { L = M; }
	}

	// minx が確定した
	long long K = minx - 1;
	long long T1 = ranged(N - (K + 1LL) / 2LL, N - 1LL);
	long long T2 = V[N - K];
	return T1 + T2;
}

int main() {
	cin >> N >> Q;
	for (int i = 0; i < N; i++) { cin >> A[i]; B[i + 1] = A[i]; V[i + 1] = V[i]; if (((N - 1) - i) % 2 == 0) V[i + 1] += A[i]; }
	for (int i = 1; i <= N; i++) B[i] += B[i - 1];
	for (int i = 0; i < Q; i++) cin >> X[i];
	for (int i = 0; i < Q; i++) {
		cout << query(X[i]) << endl;
	}
	return 0;
}

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

int xl,xr;
int h,w;
vector<string> map,use;
int l,r;
int col[10];
int c;

void piece(int a, int b){
  if(b<w-1 && map[a][b] == map[a][b+1] && use[a][b+1]=='0'){
    use[a][b+1] = '1';
    if(a==h-1 || (map[a+1][b+1] != map[a][b+1] && map[a+1][b+1] != '.') ){
      if(xl<0 || xl > b+1)xl = b+1;
      if(xr<0 || xr < b+2)xr = b+2;
    }
    piece(a,b+1);
  }
  if(b && map[a][b] == map[a][b-1] && use[a][b-1]=='0'){
    use[a][b-1] = '1';
    if(a==h-1 || (map[a+1][b-1] != map[a][b-1] && map[a+1][b-1] != '.') ){
      if(xl<0 || xl > b-1)xl = b-1;
      if(xr<0 || xr < b)xr = b;
    }
    piece(a,b-1);
  }
  if(a<h-1 && map[a][b] == map[a+1][b] && use[a+1][b]=='0'){
    use[a+1][b] = '1';
    if(a+1==h-1 || (map[a+2][b] != map[a+1][b] && map[a+2][b] != '.') ){
      if(xl<0 || xl > b)xl = b;
      if(xr<0 || xr < b+1)xr = b+1;
    }
    piece(a+1,b);
  }
  if(a && map[a][b] == map[a-1][b] && use[a-1][b]=='0'){
    use[a-1][b] = '1';
    piece(a-1,b);
  }
}

void tree(int a,int b){
  if(b<w-1 && map[a][b+1]==map[a][b] && (use[a][b+1]=='0' || use[a][b+1] == '1')){
    if(use[a][b+1] != '1')use[a][b+1] = 'a';
    else use[a][b+1] = 'b';
    if(r<b+1)r=b+1;
    col[b+1]++;
    tree(a,b+1);
  }
  if(b && map[a][b-1]==map[a][b] && (use[a][b-1]=='0' || use[a][b-1] == '1')){
    if(use[a][b-1] != '1')use[a][b-1] = 'a';
    else use[a][b-1] = 'b';
    if(l>b-1)l=b-1;
    col[b-1]++;
    tree(a,b-1);
  }
  if(a<h-1 && map[a+1][b]==map[a][b] && (use[a+1][b]=='0' || use[a+1][b] == '1')){
    if(use[a+1][b] != '1')use[a+1][b] = 'a';
    else use[a+1][b] = 'b';
    col[b]++;
    tree(a+1,b);
  }
  if(a && map[a-1][b]!='.' && (use[a-1][b]=='0' || use[a-1][b] == '1')){
    if(use[a-1][b] != '1')use[a-1][b] = 'a';
    else use[a-1][b] = 'b';
    col[b]++;
    tree(a-1,b);
  }
}

double balance(void){
  double sum,total;
  sum = 0;
  total = 0;
  for(int i=l;i<=r;i++){
    sum += col[i] * (i+1);
    total += col[i];
  }
  sum /= total;
  return sum - 0.5;
}

int main(){
  string tmp;
  double m;
  bool f;

  c = 0;
  while(1){
    c++;
    cin >> w >> h;
    if(!w && !h)break;

    map.clear();
    use.clear();
    tmp.clear();
    for(int i=0;i<w;i++)tmp.push_back('0');
    for(int i=0;i<h;i++)use.push_back(tmp);

    for(int i=0;i<h;i++){
      cin >> tmp;
      map.push_back(tmp);
    }

    f = true;
    for(int i=h-1;i>=0;i--){
      for(int j=0;j<w;j++){
	if(map[i][j] != '.' && use[i][j] != '2'){
	  if(i==h-1 || (map[i+1][j] != map[i][j] && map[i+1][j] != '.') ){
	    xl = j;
	    xr = j+1;
	  }else{
	    xl = xr = -1;
	  }
	  use[i][j] = '1';
	  piece(i,j);
	  l = r = j;
	  for(int k=0;k<w;k++)col[k]=0;
	  tree(i,j);
	  m = balance();
	  for(int k=0;k<h;k++){
	    for(int l=0;l<w;l++){
	      if(use[k][l] == 'b')use[k][l] = '2';
	      if(use[k][l] == 'a')use[k][l] = '0';
	    }
	  }
	  if( !(xl < m && xr > m) ){
	    f = false;
	    break;
	  }
	}
      }
      if(!f)break;
    }
    if(f)cout << "STABLE" << endl;
    else cout << "UNSTABLE" << endl;
  }
}

Measured memory_bytes: 0
function main(input) {
    var line = input.split(/\r?\n/g);
    const A = line[1].split(" ").map(Number);
    var flg = true;
    for (var i in A) {
        if (!(A[i] % 2)) {
            if ((A[i] % 3) && (A[i] % 5)) {
                flg = false;
                break;
            }
        }
    }
    console.log(flg ? "APPROVED" : "DENIED");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(void) {
  int x, y;
  cin >> x >> y;

  // B 0or1 -> A 0~ -> B 0or1
  int answer = INT_MAX;
  // B 0 -> A 0~ -> B 0
  if(x <= y) answer = min(answer, y - x);
  // B 1 -> A 0~ -> B 0
  if(-x <= y) answer = min(answer, 1 + y + x);
  // B 0 -> A 0~ -> B 1
  if(x <= -y) answer = min(answer, -y - x + 1);
  // B 1 -> A 0~ -> B1
  if(-x <= -y) answer = min(answer, -y + x + 2);

  cout << answer << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
enum{Nor,Eas,Sou,Wes};
#define MAX_MASU 21

using namespace std;

set<int> gemplace;
bool isgem(int p[2]);
void removegem(int p[2]);

int main(){
    while(1){
        gemplace.clear();
        int n;
        cin>>n;
        if(n==0)break;
        int gemcount=n;
        
        for(int i=0;i<n;i++){
            int p[2];
            cin>>p[0]>>p[1];
            gemplace.insert(p[0]+p[1]*MAX_MASU);
        }
        
        int M;
        cin>>M;
        int orderlist[M][2];//{N,12},{S,3},{///
        int nowplace[2];
        nowplace[0]=10;nowplace[1]=10;
        for(int i=0;i<M;i++){
            char dir;
            int temp;
            cin>>dir>>temp;
            orderlist[i][1]=temp;
            switch(dir){
            case 'N':
                orderlist[i][0]=Nor;
                break;
            case 'E':
                orderlist[i][0]=Eas;
                break;
            case 'S':
                orderlist[i][0]=Sou;
                break;
            case 'W':
                orderlist[i][0]=Wes;
                break;
            }
        }
        for(int i=0;i<M;i++){
            while(orderlist[i][1]){
                switch(orderlist[i][0]){
                case Nor:
                    nowplace[1]++;
                    break;
                case Eas:
                    nowplace[0]++;
                    break;
                case Sou:
                    nowplace[1]--;
                    break;
                case Wes:
                    nowplace[0]--;
                    break;
                }
                //cout<<"P:"<<nowplace[0]<<","<<nowplace[1]<<"\n";
                if(isgem(nowplace)){
                    removegem(nowplace);
                    gemcount--;
                }
                orderlist[i][1]--;
            }
        }
        if(gemcount==0)cout<<"Yes\n";
        else cout<<"No\n";
    }
}
bool isgem(int p[2]){
    if(gemplace.find(p[0]+p[1]*MAX_MASU)!=gemplace.end())return true;
    return false;
}
void removegem(int p[2]){
    gemplace.erase(p[0]+p[1]*MAX_MASU);
    return;
}

Measured memory_bytes: 0
while nums = gets
  nums.chomp!
  data = nums.split(//).map{|e|e.to_i}
  break if data.size == 1 && data[0] == 0
  puts data.inject(0){|memo,elem|memo += elem}
end

# inject(init){|memo,arrayElement|}
# inject's return value is last memo values

Measured memory_bytes: 6108
N = int(input())
s = []
syuugou = set()
for _ in range(N):
    i = input()
    s.append(i)
    syuugou.add(i)
M = int(input())
t = []
for _ in range(M):
    i = input()
    t.append(i)
    syuugou.add(i)
    
def counter(array):
    from collections import Counter
    return Counter(array)
t = counter(t)
s = counter(s)
ans = [0]
for x in syuugou:
    ans.append(s[x] - t[x])
print(max(ans))
    


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

int T,maxl,L,l=1,r,tmp;

struct node{
	double t;
	int v;
}s[500010];

signed main(){
	scanf("%lld%lld",&T,&maxl);
	while(T--){
		int t,v;
		scanf("%lld%lld",&t,&v);
		while(L+v>maxl){
			int out=min(s[l].v,L+v-maxl);
			s[l].v-=out;L-=out;
			tmp-=out*s[l].t;
			if(!s[l].v) ++l;
		}
		s[++r]=(node){t,v};
		tmp+=t*v;L+=v;
		while(l<r&&s[r-1].t>s[r].t){
			s[r-1].t=(double)(s[r-1].t*s[r-1].v+s[r].t*s[r].v)/(s[r-1].v+s[r].v);
			s[r-1].v+=s[r].v;--r;
		}
		printf("%.7lf\n",(double)tmp/maxl);
	}
}

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

long long dp[2][100005];

long long solution(int n , int* weight , int* values , int w){

    bool flag = 1;

    for(int i=1 ; i<=n ; i++){
        for(int j=1 ; j<=w ; j++){
            dp[flag][j] = 0;
            dp[flag][j] = dp[(flag^1)][j];
            if((j-weight[i-1]) >= 0){
                dp[flag][j] = max(dp[flag][j] , dp[(flag^1)][j-weight[i-1]] + values[i-1]);
           }
        //    cout<<dp[flag][j]<<" ";
        }
        // cout<<endl;
        flag = flag^1;
    }


    // for(int i=0 ; i<2 ; i++){
    //     for(int j=0 ; j<=w ; j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }

    return dp[(flag^1)][w];

}



int main(){
    int n , w;
    cin>>n>>w;
    int* weight = new int[n];
    int* values = new int[n];
    
    for(int i=0 ; i<n ; i++){
        cin>>weight[i];
        cin>>values[i];
    }

    cout<<solution(n , weight , values , w)<<endl;


}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
int main(void)
{
  int N,i,j,min,tmp,count=0,flag;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  for(i=0;i<N;i++)
  {
    min=i;
    flag=0;
    for(j=i;j<N;j++)
    {
      if(A[j]<A[min]) {min=j; flag=1;}
    }
    if(flag==1) count++;
    tmp=A[i];
    A[i]=A[min];
    A[min]=tmp;
  }
  for(i=0;i<N-1;i++) printf("%d ",A[i]);
  printf("%d",A[N-1]);
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;

typedef vector<double> vec;
typedef vector<vec> mat;
const double EPS=1E-8;

vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j]; //n*(n+1)の配列にする。

  for(int i=0;i<n;i++)B[i][n]=b[i]; //n番目に代入

  for(int i=0;i<n;i++){
    int pivot=i;//次の基準となる添え字。
    for(int j=i;j<n;j++)if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;//0以外の1つを探す
    swap(B[i],B[pivot]);//i行目に持ってくる。

    if(abs(B[i][i])<EPS)return vec();//もしも０だったら解なしまたは複数存在。
    
    for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i]; //左辺をB[i][i]で両辺を割る。
    
    for(int j=0;j<n;j++){ //
      if(i!=j)//i行目-i行目はスキップ
        for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];//i列の値をi列目以外を0にする。
    }
  }
  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}

typedef pair<int,int> P;

const int INF = 1e9;

int n, s, t, q[105], C[105][105];
int d[105];

void dijkstra(){
  
  for(int i=0;i<n;i++) d[i] = INF;
  
  priority_queue<P,vector<P>,greater<P> > Q;
  
  d[t] = 0;
  Q.push(P( 0, t ));
  
  while( !Q.empty() ){
    
    P tmp = Q.top(); Q.pop();
    
    int cost = tmp.first;
    int node = tmp.second;
    
    if( d[node] < cost ) continue;
    
    for(int i=0;i<n;i++){
      
      if( C[node][i] == 0 ) continue;
      
      int nnode = i;
      int ncost = cost + C[node][i];
      
      if( d[nnode] > ncost ){
	d[nnode] = ncost;
	Q.push(P( ncost, nnode ));
      }
      
    }
    
  }
  
}

int used[105];
set<P> memo;

void dfs(int x){
  
  if( used[x] ) return;
  used[x] = 1;
  
  for(int nx=0;nx<n;nx++){
    
    if( C[x][nx] == 0 ) continue;
    
    if( d[x] - C[x][nx] == d[nx] ){
      memo.insert( P( x, nx ) );
      dfs( nx );
    }
    
  }
  
}

signed main(){

  while(1){
    
    memset(used,0,sizeof(used));
    memo.clear();
    
    cin>>n>>s>>t;
    if( !n && !s && !t ) break;
    
    s--, t--;
    
    int flag = 0;
    
    for(int i=0;i<n;i++){
      cin>>q[i];
      flag |= q[i];
    }
    
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++) cin>>C[i][j];
    
    dijkstra();
    
    if( d[s] == INF ){
      cout<<"impossible"<<endl;
      return 0;
    }
    
    for(int i=0;i<n;i++){
      
      if( used[i] == 0 ){
	
	dfs( i );

      }
      
    }
        
    mat A(n,vec(n,0));
    vec B(n,0);
    
    for(int i=0;i<n;i++){
      
      if( i == t ) continue;
      
      double cnt = 0;
      
      for(int j=0;j<n;j++){
	
	if( C[i][j] == 0 ) continue;
	
	if( q[i] == 0 ) cnt++;
	
	if( q[i] == 1 && memo.count(P( i, j )) ) cnt++;
	
      }
      
      double p = 1.0 / cnt;
      
      for(int j=0;j<n;j++){
	
	if( C[i][j] == 0 ) continue;

	if( q[i] == 0 ){
	  
	  A[i][j] = -p;
	  
	  B[i] += p * C[i][j];
	  
	}
	
	if( q[i] == 1 && memo.count(P( i, j )) ){
	  
	  A[i][j] = -p;
	  
	  B[i] += p * C[i][j];
	  
	}
	
      }
      
    }

    for(int i=0;i<n;i++) A[i][i] = 1;
    
    vec ans = gauss_jordan( A, B );
    
    printf("%.8Lf\n", ans[s] );
    
  }
  
  return 0;
}



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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        sum += a & 1;
    }
    if (sum & 1) cout << "NO\n";
    else cout << "YES\n";
    return 0;
}

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

int main(){
    int D;
    cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(j,D) rep(i,26) cin >> s[j][i];

    vector<int> t(D);
    vector<vector<int>> last(26, vector<int>(1,-1));
    Int manzoku = 0;

    rep(j,1) {
        int maxs = 0;
        rep(i,26) maxs = max(maxs, s[j][i]);
        vector<int> v(0); //s[j][i]が最も大きくなるようなiを入れる
        rep(i,26) {
            if (s[j][i] == maxs) {
                v.push_back(i+1);
            }
        }
        if (v.size() == 1) {
            t[j] = v[0];
            last[t[j]-1].push_back(j);
        }
        else { //仮
            t[j] = v[0];
            last[t[j]-1].push_back(j);
        }
    }
    int i = t[0]-1;
    rep1(j,D-1) {
        i = (i + 1) % 26;
        t[j] = i+1;
        last[t[j]-1].push_back(j);
    }


    rep(i,26) last[i].push_back(D);

    vector<int> nums(26,0);
    rep(i,26) nums[i] = last[i].size();

    int M = 400000;
    int cnt = 0;
    rep(k,M) {
        int d, q;
        vector<pair<int,int>> vp(26);
        rep(i,26) vp[i] = make_pair(c[i] - 4 * nums[i],i);
        sort(vp.begin(),vp.end());
        reverse(vp.begin(),vp.end());
        q = vp[0].second + 1;
        int p;
        for (int j = 25; j>=0; j--) {
            p = vp[j].second;
            if (last[p].size() == 2) continue;
            else {
                break;
            }
        }
        if (last[p].size() <= 2) continue;
        int lpsz = last[p].size() - 2;
        d = last[p][1 + (cnt % lpsz)] + 1;
        manzoku = 0;

        manzoku -= s[d-1][t[d-1]-1];
        manzoku += s[d-1][q-1];

        auto iteold = find(last[t[d-1]-1].begin(), last[t[d-1]-1].end(), d-1);
        int old_last = *(iteold-1);
        manzoku -= c[t[d-1]-1] * (d-1 - old_last) * (*(iteold+1) - (d-1));

        auto itenew = upper_bound(last[q-1].begin(), last[q-1].end(), d-1);
        int new_last = *(itenew-1);
        manzoku += c[q-1] * (d-1 - new_last) * (*itenew - (d-1));

        if (manzoku > 0) {
            //更新したほうがよいならこれをやる
            last[t[d-1]-1].erase(iteold);
            last[q-1].insert(itenew,d-1);
            t[d-1] = q;
            nums[t[d-1]-1]--;
            nums[q-1]++;
        
        }
        cnt++;
        //cout << manzoku << endl;
    }

    rep(j,D) cout << t[j] << endl;
}

Measured memory_bytes: 3692
n,k = list(map(int, input().split()))
p = list(map(int, input().split()))

max_num = []
tmp = 0
current_sum = sum(p[:k-1])
for i in range(n-k+1):
    current_sum += p[k+i-1]
    if tmp < current_sum:
        max_num = p[i:k+i]
        tmp = current_sum
    current_sum -= p[i]

print(sum([(1+n)/2 for n in max_num]))

Measured memory_bytes: 25060
#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;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	int n,x,y;
	cin >> n >> x >> y;
	x--; y--;
	vector<int> ans(n+10,0);
	rep(i,n){
		int now;
		for(int j= i+1 ; j<n ; j++){
			now = min({abs(j-i), abs(j-x)+abs(i-y)+1,  abs(j-y)+abs(i-x)+1});
			ans[now] ++;
		}
	}
	for(int i = 1;i < n; i++){
			cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//Moh_K_Imar .......
//22/08/2020  ... 12,00 .
//Ya Rab....
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
int main(){
    string a;
    cin>>a;
    ll counter=0;
    for(int i=0;i<a.size();i++){
        if(a[i]=='A'){
            counter++;
        }
    }
    if(counter==0||counter==3)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

    return 0;
}



Measured memory_bytes: 3632
h, w = map(int,input().split())

if (h == 1) or (w == 1):
  print(1)
  
#共に偶数or偶奇
elif (h % 2 == 0) or (w % 2 == 0):
  print(int((h*w)/2))
#共に奇数
else:
  print(int(h*w/2 + 1))

Measured memory_bytes: 3060
n,m=map(int,input().split())
x = [ 0 for i in range(n) ]
y = [ 0 for i in range(n) ]
z = [ 0 for i in range(n) ]
op=['+', '-']
vals = {}
for i in range(n):
    x[i], y[i], z[i] = map(int, input().split())
    for o1 in op:
        term1 = o1 + str(x[i])
        for o2 in op:
            term2 = o2 + str(y[i])
            for o3 in op:
                term3 = o3 + str(z[i])
                eq = term1 + term2 + term3
                key = o1+o2+o3
                if key not in vals:
                    vals[key] = []
                vals[key].append(eval(eq))
vl = []
for key in vals.keys():
    vals[key].sort(reverse=True)
    vl.append(abs(sum(vals[key][:m])))
print(max(vl))


Measured memory_bytes: 3572
A, B, K = map(int,input().split())

for k in range(K):
    if k%2 == 0:
        if A%2 == 1:
            A -= 1
        A //= 2
        B += A
    else:
        if B%2 == 1:
            B -= 1
        B //= 2
        A += B
print(A,B)


Measured memory_bytes: 9176
H, W = gets.split.map(&:to_i)
c = 10.times.map { gets.split.map(&:to_i) }
A = H.times.map { gets.split.map(&:to_i) }
10.times{|k| 10.times{|a| 10.times{|b|
    c[a][b] = [c[a][b], c[a][k] + c[k][b]].min
    }}}
puts A.flatten.select{|v|v!=-1}.map{|v|c[v][1]}.inject(&:+)


Measured memory_bytes: 3580
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
int n;
vvi v;
vi visited;
int dfs(int u)
{
    int res = 0;
    visited[u] = 1;
    bool flag = true;
    rep(i, n)
    {
        if (visited[i] == 0)
        {
            flag = false;
        }
    }
    if (flag)
    {
        res++;
    }
    rep(i, v[u].size())
    {
        if (!visited[v[u][i]])
        {
            visited[v[u][i]] = 1;
            res += dfs(v[u][i]);
            visited[v[u][i]] = 0;
        }
    }
    return res;
}
int main()
{
    int m;
    cin >> n >> m;
    v.resize(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    visited.resize(n);
    cout << dfs(0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int A, B;
    int a, b;

    cin >> A >> B;

    for (int i = 0; i <= 1000000000; i++)
    {
        if (A - i < 0)
        {
            a = (A - i) * -1;
        }
        else
        {
            a = A - i;
        }

        if (B - i < 0)
        {
            b = (B - i) * -1;
        }
        else
        {
            b = B - i;
        }

        if (a == b)
        {
            cout << i << endl;
            return 0;
        }
    }

    cout << "IMPOSSIBLE" << endl;
}


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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.length();
    vll L, R;
    for(int i = 0; i < N; i++) {
        if(S[i] == 'L') {
            L.push_back(i);
        } else {
            R.push_back(i);
        }
    }
    ll ans[N] = {};
    for(int i = 0; i < N; i++) {
        if(S[i] == 'L') {
            int j = lower_bound(R.begin(), R.end(), i) - R.begin() - 1;
            if((i - R[j]) & 1)
                ans[R[j] + 1]++;
            else
                ans[R[j]]++;
        } else {
            int j = lower_bound(L.begin(), L.end(), i) - L.begin();
            if((L[j] - i) & 1)
                ans[L[j] - 1]++;
            else
                ans[L[j]]++;
        }
    }
    for(int i = 0; i < N; i++) {
        cout << ans[i] << (i == N - 1 ? "\n" : " ");
    }
    return 0;
}


Measured memory_bytes: 2372
/*input
2 3 4
..#
###
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
// #define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m;
int r[4]={0,0,1,-1};
int c[4]={1,-1,0,0};

int dp[7][7]={0};

void solve()
{

    cin>>n>>m;
    cin>>k;

    int a[n][m];
char ac;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            cin>>ac;

            if(ac=='.')
                a[i][j]=0;
            else 
                a[i][j]=1;
        }
    }

    int row=(1<<n)-1;
    int col=(1<<m)-1;
    
    int count=0;

    for(i=0;i<=row;i++)
    {
        for(j=0;j<=col;j++)
        {int temp=0;
            for(auto i1=0;i1<n;i1++)
            {
                for(auto i2=0;i2<m;i2++)
                {
                    if(((i>>i1)&1)&&((j>>i2)&1))
                        temp+=a[i1][i2];
                }
            }
            if(temp==k)
                count++;

        }
    }

    cout<<count;
}
 
 
 
 
 
 
signed main()
{

    // inputFile;
    // outputFile;
    fast;
    int T = 1;
 // cin >> T;
ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 3640
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    var count = 0
    for (index in n downTo 1) {
        var tmpIndex = index.toString()
        if (tmpIndex.length % 2 != 0) {
            count++
        }
    }
    println(count)
}

Measured memory_bytes: 33952
S=input()
for i in range(0,3):
    if S[0]=="R" and S[1]=="R" and S[2]=="R":
        x=3
    elif S[0]=="R" and S[1]=="R":
        x=2
    elif S[1]=="R" and S[2]=="R":
        x=2
    elif S[0]=="R" or S[1]=="R" or S[2]=="R":
        x=1
    else:
        x=0
print(x)

Measured memory_bytes: 9120
from operator import itemgetter
n = int(input())
dic = {}
for i in range(1, n + 1):
  s, p = input().split()
  p = int(p)
  dic.setdefault(s, [])
  dic[s].append((i, p))
cities = sorted(list(dic.keys()))
for c in cities:
  dic[c].sort(key=itemgetter(1), reverse=True)
  for i in dic[c]:
    print(i[0])

Measured memory_bytes: 9124
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

ll dp[3100][3100];
int n;
vi a;

ll dfs(int l,int r) {
    if(dp[l][r] != -linf) return dp[l][r];
    if(l+r == n) return 0;
    if((l+r)%2 == 0) {
        // Taro's turn
        return dp[l][r] = max(a[l]+dfs(l+1,r),a[n-1-r]+dfs(l,r+1));
    } else {
        // Jiro's turn
        return dp[l][r] = min(dfs(l+1,r)-a[l],dfs(l,r+1)-a[n-1-r]);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> n;
    a.resize(n);
    cin >> a;
    rep(i,3100) rep(j,3100) dp[i][j] = -linf;
    cout << dfs(0,0) << endl;
}


Measured memory_bytes: 75648
#入力
K=int(input())
A,B=map(lambda x:int(x),input().split())

flag=False
i=0
num=0
while num<=B:
	num=K*i
	if num>=A and num<=B:
		flag=True
		break
	else:
		i=i+1
      
if flag:
	print("OK")
else:
	print("NG")


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int n,k;cin>>n>>k;
  ll ans=1;
  rep(i,0,n){
    ans=min((ans*2),(ans+k));
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[] num = new int[n + 1];
			for (int i = 1; i <= n; i++)
				num[i] = scanner.nextInt();
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i <= n; i++)
				for (int j = i; j <= n; j++)
					if (num[i] + num[j] <= m)
						list.add(num[i] + num[j]);
			int ans = 0;
			int i = 0;
			int l = 0;
			int r = list.size() - 1;
			Collections.sort(list);
			while (i < r) {
				l = i;
				while (l <= r) {
					int mid = (l + r) / 2;
					int ret = list.get(i) + list.get(mid);
					if (ret <= m) {
						ans = Math.max(ans, ret);
						l = mid + 1;
					} else {
						r = mid - 1;
					}
				}

				i++;
			}
			System.out.println(ans);

		}
	}
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;
const ll inf = 1e6+5;
typedef pair<int, bool> pib;

int main() {
    int a; cin >> a;
    vector<int> v (a);
    for (int i = 0; i < a; i++){
        cin >> v[i];
    }
    cout << *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end());
}



Measured memory_bytes: 256
#include <cstdio>

int main(){
  int N, M, K; scanf("%d%d%d", &N, &M, &K);

  bool ans = false;

  for(int n = 0; n <= N; n++){
    for(int m = 0; m <= M; m++){
      int k = n * M + m * N - 2 * n * m;
      if(k == K) ans = true;
    }
  }

  puts(ans ? "Yes" : "No");
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		while(sc.hasNextInt()){
			int i,a;long b=0;
			a=sc.nextInt();
			for(i=a;i<600;i=i+a){
				b+=a*Math.pow(i,2);
			}
			System.out.println(b);
		}
		
	}
}

Measured memory_bytes: 17368
#include <algorithm>
#include <queue>
#include <cstdio>
typedef long long LL ;
using namespace std ;
int main()
{
    char X[10];
    char Y[10];
    while(scanf("%s %s",X,Y)!=EOF)
    {
        int x,y;
        x=X[0]-'A';
        y=Y[0]-'A';
        if(x>y)
            printf(">\n");
        else if(x<y)
            printf("<\n");
        else
            printf("=\n");
    }
    return 0;
}

Measured memory_bytes: 128