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

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long W = scan.nextLong();
        long[] w = new long[N];
        long[] v = new long[N];
        List<Long>[] list = new List[4];
        for (int i = 0; i < 4; i++) {
            list[i] = new ArrayList<>();
        }
        for (int i = 0; i < N; i++) {
            w[i] = scan.nextInt();
            v[i] = scan.nextLong();
            list[(int)(w[i]-w[0])].add(v[i]);
        }
        for (int i = 0; i < 4; i++) {
            Collections.sort(list[i], Comparator.reverseOrder());
        }
        List<Long>[] sum = new List[4];
        for (int i = 0; i < 4; i++) {
            sum[i] = new ArrayList<>();
            sum[i].add(0L);
            for (int j = 1; j <= list[i].size(); j++) {
                sum[i].add(sum[i].get(j - 1) + list[i].get(j-1));
            }
        }
        long ans = 0;
        for (int i = 0; i <= list[0].size(); i++) {
            for (int j = 0; j <= list[1].size(); j++) {
                for (int k = 0; k <= list[2].size(); k++) {
                    for (int l = 0; l <= list[3].size(); l++) {
                        long sumW = (long) (i + j + k + l) * w[0];
                        sumW += j;
                        sumW += k * 2;
                        sumW += l * 3;
                        if (W < sumW) {
                            continue;
                        }
                        long sumV = sum[0].get(i)+sum[1].get(j)+sum[2].get(k)+sum[3].get(l);
                        ans = Math.max(ans, sumV);
                    }
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 24768
#include<stdio.h>
int main (void)
{
  int i,n=0,a,min=0,max=0;
  long long sum=0;
  scanf("%d",&n);
    a=0;    
    scanf("%d",&a);
    min=a;
    max=a;
    sum+=a;
  for(i=0;i<(n-1);i++){
    a=0;    
    scanf("%d",&a);
    if(a<min)min=a;
    if(a>max)max=a;
    sum+=a;
  }
  printf("%d %d %lld\n",min,max,sum);
  return 0;
}

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

bool dp[200010];
int main() {
	int N, K, a[105]; cin >> N >> K;
	for(int i=0; i<N; ++i) cin >> a[i];
	for(int i=0; i<=K; ++i){
	    if(!dp[i]){
	        for(int j=0; j<N; ++j) dp[i+a[j]]=true;
	    }
	}
	cout << (dp[K] ? "First" : "Second") << endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			long n=sc.nextLong(),m=sc.nextLong();
			System.out.println(Math.min(m/2, (m+2*n)/4));
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD=1e9+7;

int main() {
  int a,b,x;
  cin>>a>>b>>x;
  if(a<=x && x<=a+b) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
  
using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int ans = -1;
    for(int t = 0; t < 1000; t++){
        if((60 * t + c) % (a + b) <= a){
            ans = 60 * t + c;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    public static int solve(int N, int M, int[] x, int[] y) {
        List<Integer>[] adj = new List[N];
        for (int i = 0; i < M; i++) {
              if (adj[x[i]-1] == null) adj[x[i]-1] = new ArrayList<>();
              adj[x[i]-1].add(y[i]-1);
        }

        int[] longest = new int[N];
        Arrays.fill(longest, -1);

        int  maxLength = -1;
        for (int from = 0; from < N; from++)
            if (longest[from] == -1)
                maxLength = Math.max(maxLength, dfs(from, adj, longest));

        return maxLength;
    }

    private static int dfs(int from, List<Integer>[] adj, int[] longest) {
        if (longest[from] != -1) return longest[from];

        int currentLongest = 0;
        if (adj[from] != null)
          for (int to: adj[from])
            currentLongest = Math.max(currentLongest, 1 + dfs(to, adj, longest));

        longest[from] = currentLongest;
        return currentLongest;
      }

    public static void main(String[] args) {
        int N, M;
        int[] x, y;

        try (Scanner scanner = new Scanner(System.in)) {
            N = scanner.nextInt();
            M = scanner.nextInt();
            x = new int[M];
            y = new int[M];
            for (int i=0; i < M; i++) {
                x[i] = scanner.nextInt();
                y[i] = scanner.nextInt();
            }
        }

        int result = solve(N, M, x, y);
        System.out.println(result);

        //Tests.run();
    }
}

class Tests {
    public static void run() {
        testCase(4, 5, new int[] {1,1,3,2,3}, new int[] {2,3,2,4,4}, 3);
        testCase(6, 3, new int[] {2,4,5}, new int[] {3,5,6}, 2);
        testCase(5, 8, new int[] {5,2,2,5,5,1,4,1}, new int[] {3,3,4,2,1,4,3,3}, 3);
        System.out.println("DONE");
    }

    private static void testCase(int N, int M, int[] x, int[] y, int expected) {
        int result = Main.solve(N, M, x, y);
        if (result != expected) System.out.println("N=" + N + " M=" + M + " x=" + Arrays.toString(x) + " y=" + Arrays.toString(y) + " was " + result + " expected " + expected);
    }
}


Measured memory_bytes: 80592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define inf 1e18
#define mod pow(10,9)+7
#define mii map<int,int>
#define pii pair<int,int>
#define setbits(x) __builtin_popcountll(x)
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int32_t main()
{
	int n;
	cin >> n;
	set<string>s;
	while (n--)
	{
		string se;
		cin >> se;
		s.insert(se);


	}
	cout << s.size();

	return 0;
}

Measured memory_bytes: 19260
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	long long int sum =0;
	for(int i=1;i<=n;i++){
		if(i%3!=0 && i%5!=0){	
			sum = sum + i;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3596
<?php
// D
fscanf(STDIN, '%d %d', $n, $m);
for ($i  = 0; $i < $m; $i++) {
    fscanf(STDIN, '%d %d', $a, $b);
    $a--;
    $b--;
    $g[$a][] = $b;
    $g[$b][] = $a; // 無向グラフの場合
}

// BFS（幅優先探索）：最短経路アルゴリズムとして活用
$q = new SplQueue(); // キューを用意
$dist = array_fill(0, $n, -1); // 距離を格納する配列（-1の場合はその頂点が未発見）

$dist[0] = 0; // 頂点0からの距離格納配列
$q->enqueue(0); // キューに0を追加

while (!$q->isEmpty()) {
    $v = $q->dequeue();

    foreach ($g[$v] as $next_v) {
        if ($dist[$next_v] !== -1) continue; // 発見済み

        $dist[$next_v] = $dist[$v] + 1;
        $arrow[$next_v] = $v;
        $q->enqueue($next_v);
    }
}

echo 'Yes' . PHP_EOL;
for ($i = 1; $i < $n; $i++) {
    echo ($arrow[$i] + 1) . PHP_EOL;
}

Measured memory_bytes: 71280
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end())
            cout << " ";
    }
    cout << endl;
};

int main() {
    int rmax = 0, total = 0;
    string S;
    cin >> S;
    stack<int> left;
    vector<pair<int, int>> P;
    vector<int> flood;
    rep(i, S.length()) {
        if(S[i] == '\\')
            left.push(i);
        else if(S[i] == '/' && !left.empty()) {
            P.push_back(make_pair(left.top(), i));
            total += i - left.top();
            left.pop();
        }
    }
    sort(P.begin(), P.end());
    rep(i, P.size()) {
        if(P[i].second > rmax) {
            rmax = P[i].second;
            flood.push_back(P[i].second - P[i].first);
        } else {
            flood.back() += P[i].second - P[i].first;
        }
    }
    cout << total << endl << flood.size() << (flood.empty() ? "" : " ");
    vecout(flood);
}


Measured memory_bytes: 3292
#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
    std::string s, t;
    std::cin >> s >> t;

    s += s;

    if (s.find(t) != std::string::npos) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
int main()
{
  ll N, K, trick = 0; cin >> N >> K;
  vector<ll> A(N + 1, 0);
  for (ll i = 0; i < K; i++) {
  	ll d; cin >> d;
    for (ll j = 0; j < d; j++) {
    	ll a; cin >> a;
      A[a]++;
    }
  }
  for (ll i = 1; i <= N; i++) {
    if (A[i] == 0) {
    	trick++;
    }
  }
  cout << trick << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <map>
#include <algorithm>

long long int mod = 998244353;

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

        a = (a * a) % mod;
    }

    return res;
}

int main()
{
    long long int n, a, b, k;
    std::cin >> n >> a >> b >> k;

    long long int factorial[300010];
    factorial[0] = 1;
    for (int i = 1; i <= n; ++i)
        factorial[i] = factorial[i - 1] * i, factorial[i] %= mod;

    long long int ans = 0;
    for (int i = 0; i <= n; ++i)
    {
        long long int left = k - a * i;
        if (left % b != 0 || left / b > n)
            continue;
        if (left < 0)
            break;

        long long int bs = left / b;

        long long int first = factorial[n] * powmod(((factorial[n - i] * factorial[i]) % mod), mod - 2);
        long long int second = factorial[n] * powmod(((factorial[n - bs] * factorial[bs]) % mod), mod - 2);
        first %= mod;
        second %= mod;

        ans += (first * second) % mod;
        ans %= mod;
    }

    std::cout << ans;
}


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

int main() {
  int64_t N;
  cin >> N;
  int64_t M = sqrt(N);
  int A, B, B_size, x = 11;
  string B_str;
  
  for (int64_t i = 1; i <= M; i++) {
    if (N % i == 0) {
      B = N / i;
      B_str = to_string(B);
      B_size = B_str.size();
      x = min(x, B_size); 
    }
  }
  
  cout << x << endl;
}

Measured memory_bytes: 256
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int L, R, d;
    cin >> L >> R >> d;

    int ans = 0;
    FOR(i, L, R)
    {
        if (i % d == 0)
            ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3168
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/
 
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
 
typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;
 
ll inv[MAX_N], fac[MAX_N];
 
template <class T = ll> T in() { T x; cin >> x; return (x); }
inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }
 
typedef pair<int, pair<int, int>> edge;
 
class UnionFind {
private:
    vector<int> par;
public:
    vector<int> hen;
    UnionFind(int N) { par = vector<int>(N, -1LL); hen = vector<int>(N,0);}
    int find(int x);
    ll size(int x);
    void unite(int x, int y);
    bool same(int x, int y);
};

 
 
 
//----UnionFind-------------------------------
int UnionFind::find(int x) {
    if (par[x] < 0) return x;
    else return par[x] = find(par[x]);
}
 
ll UnionFind::size(int x) {
    return -par[find(x)];
}
 
void UnionFind::unite(int x, int y) {
    x = find(x);
    y = find(y);
    //大きい方に小さい方をくっ付ける
    if (size(x) < size(y)) swap(x, y);
    if (x == y) hen[x]++;
    else hen[x] += hen[y]+1;
    if (x == y) return;
    par[x] += par[y];
    par[y] = x;
}
 
bool UnionFind::same(int x, int y) {
    x = find(x);
    y = find(y);
    return x == y;
}

signed main() {
	string s; cin >> s;
	int cnt = 0;
	REP (i,s.size()) {
		if (s[i] == 'o') cnt++;
	}
	cnt += 15 - s.size();
	if (cnt >= 8) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n; cin >> n;
    ll ans = 0;
    vector<vector<int> > lis(10, vector<int>(10, 0));
    REP(i, 1, n+1){
        string s = to_string(i);
        lis[s.front()-'0'][s.back()-'0']++;
    }
    REP(i, 1, n+1){
        string s = to_string(i);
        ans += lis[s.back()-'0'][s.front()-'0'];
    }
    cout << ans << endl;
}

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

int main(){
    int n;
    cin >> n;
    while(n-- > 0){
        int x = 0, y = 0, dx, dy, ma = 0, ansx, ansy;
        while(cin >> dx >> dy, dx+dy){
            x += dx, y += dy;
            if(x*x+y*y > ma || (x*x+y*y == ma && x > ansx)){
                ma = x*x + y*y;
                ansx = x, ansy = y;
            }
        }
        cout << ansx << " " << ansy << endl;
    }
    return 0;
}


Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll mod = 1e9+7;
ll mod_pow(ll x, ll n, ll mod){
    if(n == 0)return 1;
    ll res = mod_pow(x*x%mod,n/2,mod);
    if(n&1) res = res * x % mod;
    return res;
}

vector<long long> divisor(long long n){
    vector<long long> res;
    for(long long i = 1; i*i <= n; i++){
        if(n%i==0){
            res.push_back(i);
            if(n/i != i)res.push_back(n/i);
        }
    }
    return res;
}

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

  ll res = 0;
  map<int, ll> mp;
  vector<ll> cnt(k+1,0);
  for (int i = 1; i <= k; i++) {
    auto div = divisor(i);
    for (auto e : div) mp[e]++;
  }
  
  for (int i = k; i >= 1; i--) {
    ll d = mod_pow(mp[i], n, mod);
    for (ll j = 2; j * i <= k; j++) {
      d = (d - cnt[j * i] + mod) % mod;
    }
    cnt[i] = d;
    res += d * i % mod;
    res %= mod;
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 10336
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define floop(i,a,n) for (int i=a;i<n;i++)
#define rfloop(i,a,n) for (int i=n-1;i>=a;i--)
#define mloop(it,x) for(it=x.begin();it!=x.end();it++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((ll)(x).size())
#define cases ll t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef unsigned long long int ull;
typedef vector<ll> vec;
typedef pair<ll,ll> pll;
typedef double db;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll mod=1000000007;
ll pm(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=((result%mod)*(x%mod))%mod; x=((x%mod)*(x%mod))%mod; n/=2;} return result;}
ll p(ll x,ll n) {ll result=1; while(n>0){if(n%2==1) result=result*x; x=x*x; n/=2;} return result;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll ncr(ll n,ll r) { ll p=1,k=1; if(n-r<r) r=n-r; if(r!=0) {while(r!=0) {p*=n; k*=r; ll temp=gcd(p,k); p/=temp; k/=temp; n--; r--;} } else p=1; return p;}
ll factorial[300000+1];
void fact(ll n) { factorial[0]=1; factorial[1]=1; floop(i,2,n+1) factorial[i] = (i * factorial[i-1]%mod) % mod; }
ll d,coeff1,coeff2; 
void euclid(ll a, ll b) { if(b==0) { d=a; coeff1=1; coeff2=0; } else { euclid(b,a%b); ll temp=coeff1; coeff1=coeff2; coeff2=temp-(a/b)*(coeff2); } }
ll modinv(ll a) { euclid(a,mod); return (coeff1%mod+mod)%mod; }
int prime[1000001]={};
int spf[1000001]={};
void sieve(ll n)
{
	prime[0]=1;
	prime[1]=1;
	for(ll i=2;i*i<=n;i++)
	{
		if(prime[i]==0)
		{
			for(ll j=i*i;j<=n;j+=i)
			{
				prime[j]=1;	
				if(spf[j]==j)
				spf[j]=i;	
			}		
		}
	}
}
/*
vec s(300000,0);
vec si(300000,1);
ll root(ll a)
{
	while(s[a]!=a)
	a=s[a];
	return a;
}
void uni(ll a,ll b)
{
	ll r1=root(a);
	ll r2=root(b);
	if(si[r1]<si[r2])
	{
		s[r1]=s[r2];
		si[r2]+=si[r1];
	}
	else
	{
		s[r2]=s[r1];
		si[r1]+=si[r2];
	}
}
vector<vec > adj(300000);
vec vis(300000,0);
vec dist(300000,0);
void dfs(ll t,ll n)
{
	vis[t]=1;
	floop(i,0,sz(adj[t]))
	{
		if(vis[adj[t][i]]==0)
		{
			dist[adj[t][i]]=dist[t]+1;
			vis[adj[t][i]]=1;
		//	sum[adj[t][i]]=sum[t]+c[t][adj[t][i]];
			dfs(adj[t][i],n);
		}
	}
}*/
struct my_comp
{
	bool operator()(pair<ll,pll> p1, pair<ll,pll> p2)
	{
		if(p1.fi!=p2.fi)
		return p1.fi>p2.fi;
		return p1.se.fi<p2.se.fi;
	}
};
int main()
{
	ll h,w,k;
	cin>>h>>w>>k;
	string c[h];
	floop(i,0,h)
	cin>>c[i];
	ll tot=0;
	floop(i,0,h)
	{
		floop(j,0,w)
		{
			if(c[i][j]=='#')
			tot++;
		}
	}
	ll ans=0;
	floop(i,0,p(2,h))
	{
		//ll temp=0;
		//ll temp=0;
		floop(l,0,p(2,w))
		{
			ll temp=0;
			floop(j,0,h)
			{
				//ll temp=0;
				floop(m,0,w)
				{
					if((i & (1<<j)) || (l & (1<<m)))
					{
						if(c[j][m]=='#')
						temp++;
					}
				}
			}
			//cout<<i<<" "<<l<<" "<<temp<<"\n";
			if(tot-temp==k)
			ans++;
		}
	}
	cout<<ans<<"\n";
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  int a = N % 10;
  int b = ((N - a) / 10) % 10;
  int c = ((N - a - 10 * b) / 100) % 10;
  int d = ((N - a - 10 * b - 100 * c)) / 1000;
if ( (a == b && b == c) || (b == c && c == d)) {
  cout << "Yes" << endl;
}
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
public partial class IntroductionToProgramming{
    public static void Main(){
        string[] line = System.Console.ReadLine().Split(' ');
 
        int h = int.Parse(line[0]);
        int w = int.Parse(line[1]);
 
        string es = string.Empty;
        string os = string.Empty;
        for (int i = 0; i < 300; i++)
        {
            es += i % 2 == 0 ? "#" : ".";
            os += i % 2 == 0 ? "." : "#";
        }
 
        while (!(h == 0 && w == 0))
        {
            for (int i = 0; i < h; i++ )
            {
                System.Console.WriteLine(i % 2 == 0 ? es.Substring(0, w) : os.Substring(0, w));
            }
            System.Console.WriteLine(string.Empty);
 
            string[] line2 = System.Console.ReadLine().Split(' ');
 
            h = int.Parse(line2[0]);
            w = int.Parse(line2[1]);
        }
    }
}

Measured memory_bytes: 5448
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		while(N-->0)
		{
			double xp1=in.nextDouble(),yp1=in.nextDouble();
			double xp2=in.nextDouble(),yp2=in.nextDouble();
			double xp3=in.nextDouble(),yp3=in.nextDouble();
			double xk=in.nextDouble(),yk=in.nextDouble();//enemy
			double xs=in.nextDouble(),ys=in.nextDouble();//me
			int kabe=0;
			if(judge(xp1,yp1,xp2,yp2,xk,yk,xs,ys))//壁と交差する
				kabe++;
			if(judge(xp2,yp2,xp3,yp3,xk,yk,xs,ys))
				kabe++;
			if(judge(xp3,yp3,xp1,yp1,xk,yk,xs,ys))
				kabe++;
			System.out.println(kabe==1 ? "OK":"NG");
		}
	}
	
	static boolean judge(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4)
	{
		double jc1=(x1-x2)*(y3-y1)+(y1-y2)*(x1-x3);
		double jd1=(x1-x2)*(y4-y1)+(y1-y2)*(x1-x4);
		double jc2=(x3-x4)*(y1-y3)+(y3-y4)*(x3-x1);
		double jd2=(x3-x4)*(y2-y3)+(y3-y4)*(x3-x2);
		return jc1*jd1<0 && jc2*jd2<0;
	}
}

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

int main() {
  int N, A;
  cin >> N >> A;
  
  int arg1 = N / 500;  
  int judge =  N - (500 * arg1);

  if ( judge <= A) {
    cout << "Yes" << endl; 
  } else {
    cout << "No" << endl;
  }
}

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

//Author: Ashish

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	vector<int> input(n);
	for(auto&itr:input) cin>>itr;
	int answer=1e9;
	int l=1,r=1e9;
	while(l<=r) {
		int midd=(l+r)/2;
		int count=0;
		for(auto&itr:input) {
			if(itr%midd==0) count+=itr/midd;
			else count+=itr/midd+1;
			count--;
		}
		if(count<=k) {
			answer=midd;
			r=midd-1;
		}
		else {
			l=midd+1;
		}
	}
	cout<<answer;



	return 0;
}

Measured memory_bytes: 4760
clash::Int->[Int]->Int
clash n (x:xs) | null xs = if n == x then 0 else 1 
               | n == x = clash (n+1) xs
               | otherwise = 1 + clash n xs

main = do
  getLine
  an <- map read . words <$> getLine
  print $ if all (/=1) an then -1 else clash 1 an


Measured memory_bytes: 68988
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    if (N == 1 && M == 1) System.out.println(1);
    else if (N == 1) System.out.println(M - 2);
    else if (M == 1) System.out.println(N - 2);
    else System.out.println(1L * (N - 2) * (M - 2));
  }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N; cin >> N;
    vector<int> v(N);
    REP(i,N) cin >> v[i];
    int cnt = 0;
    int minj,minv;
    REP(i,N-1) {
        minj = i;
        minv = v[i];
        FOR(j,i+1,N) if(chmin(minv,v[j])) minj = j;
        if(minj != i) {
            iter_swap(v.begin()+i,v.begin()+minj);
            cnt++;
        }
    }
    REP(i,N-1) cout << v[i] << " ";
    cout << v[N-1] << endl;
    cout << cnt << endl;

}

int main() {
    solve();
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <algorithm>
#include <string>
#include <regex>
using namespace std;
int main()
{
    string S;
    cin >> S;
    
    regex re("(dream|dreamer|erase|eraser)*");
    
    if(regex_match(S,re)){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
        
    }
    return 0;
}


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

int main()
{
    char a[100], b[26];
    int c[26];
    int i, j, k, n, flg, first, second;
    char first_c, second_c;

    while (1)
    {
        cin >> n;

        if (n == 0)
            break;
        first = 0;
        second = 0;
        k = 0;

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

        for (i = 0; i < n; i++)
        {
            flg = 0;
            for (j = 0; j < k; j++)
            { //kは既出の文字数
                if (b[j] == a[i])
                {
                    c[j]++;
                    flg = 1; //countupした
                    if (c[j] >= first)
                    {
                        if (first_c == a[i])
                            first++;
                        else
                        {
                            second = first;
                            second_c = first_c;
                            first = c[j];
                            first_c = b[j];
                        }
                    }
                    else if (c[j] > second)
                    {
                        second = c[j];
                        second_c = b[j];
                    }
                    //    cout<<first_c<<first<<i<<endl;
                }
            }

            if (flg == 0)
            {                //新しい文字
                b[k] = a[i]; //新しい文字
                c[k] = 1;
                k++;
                if (first == 0)
                {
                    first = 1;
                    first_c = a[i];
                }
                else if (second == 0)
                {
                    second = 1;
                    second_c = a[i];
                }
            }

            if ((second + (n - (i + 1))) < first)
            {
                cout << first_c << ' ' << i + 1 << endl;
                break;
            }

            if (i == n - 1)
            {
                if (first == second)
                {
                    cout << "TIE" << endl;
                }
                else
                {
                    cout << first_c << ' ' << i + 1 << endl;
                    break;
                }
            }
        }
    }
}



Measured memory_bytes: 3068
if __name__ == '__main__':
    l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    n = int(input())
    print(l[n - 1])

Measured memory_bytes: 2940
#include <stdio.h>
int main()
{
    int a,b,c,d,area1,area2;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a<1||b<1||c<1||d<1)
        return 0;
    area1=a*b;
    area2=c*d;
    if(area1>area2){
        printf("%d",area1);
    }
    else if(area2>area1){
        printf("%d",area2);

    }
    else
        printf("%d",area1);


    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

template <class T> void swap(T& a, T& b) { T t = std::move(a); a = std::move(b); b = std::move(t); }

int main(void)
{
    ll N, M;

    cin >> N >> M;

    cout << (1900*M+100*(N-M))*pow(2,M) << endl;

    return 0;
}

Measured memory_bytes: 256
str = ""
upperStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lowerStr = "abcdefghijklmnopqrstuvwxyz"
count = [0] * 26

while True:
        try:
                str += input()
        except:
                break

for n in range(len(str)):
        for i in range(26):
                if str[n] == upperStr[i] or str[n] == lowerStr[i]:
                        count[i] += 1
                        break

for i in range(26):
        print(lowerStr[i], ":", count[i])


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

int main() {

  while(1) {
    
  int n;
  cin >> n;
  if(n == 0) break;

  int w ,h;
  cin >> w >> h;

  int mp[101][101];
  for(int i=0;i<=h;i++)
    for(int j=0;j<=w;j++)
      mp[i][j] = 0;
  
  for(int i=0;i<n;i++){
    int a,b;
    cin >> a >> b;
    mp[b-1][a-1] = 1;
  }

  int s,t;
  cin >> s >>t;
  int ans = 0;
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++){      
      int cnt = 0;
      for(int k=i;k<i+t;k++)
	for(int l=j;l<j+s;l++){
	  if(w<=l || h<=k) break;
	  //  cout <<"x="<<l<<" y="<<k<<" ="<<mp[k][l]<<endl;
	  if(mp[k][l] == 1) cnt++;
	}
      //     cout << "cnt="<<cnt << endl;
      //cout <<"----------------"<<endl;
      if(cnt > ans) ans = cnt;
    }

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

Measured memory_bytes: 1200
void main()
{
    long n, z, w;
    rdVals(n, z, w);
    long[] a = rdRow;

    long result = abs(a[$-1]-w);
    if (n > 1) result = max(result, abs(a[$-2]-a[$-1]));

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 2428
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll N;
vector<ll> A;

int main(){
    cin >> N;
    cin.ignore();
    for(int i = 0; i < N; i++){
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
    }

    // きほんせんりゃく　安く買って高く売る

    // 最初はあがるか？
    ll k = 0;
    ll y = 1000;
    bool status = false; // 上がり: true 下がり: false

    for(int i = 1; i < N; i++){
        if(status){
            if(A[i] < A[i-1]){ // それまで上がっていて下がるなら全部売る
                y += A[i-1] * k;
                k = 0;
                status = false;
            }
        } else { // 下がっていて上に上がるなら全部買う
            if(A[i] > A[i-1]){
                k += y / A[i-1];
                y %= A[i-1];
                status = true;
            }
        }
    }

    // 最後 上がっていたなら売る
    y += A[N-1] * k;

    cout << y << endl;
    return 0;
}

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

using namespace std;

typedef long long llint;

const int MAXN = 100100;
const int MOD = 1000000007;

int n;
int arr[MAXN];
int pos[MAXN];

llint fact[MAXN], inv[MAXN];

int pow(llint a, int b)
{
	int ret = 1;
	while (b)
	{
		if (b % 2)
			ret = ret * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return ret;
}

int bin(int a, int b)
{
	if (a < 0 || b < 0 || b > a)
		return 0;
	return fact[a] * inv[b] % MOD * inv[a - b] % MOD;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int i;
	int l, r;
	
	cin>>n;
	
	memset(pos, -1, sizeof pos);
	fact[0] = inv[0] = 1;
	for (i = 0; i <= n; ++i)
	{
		fact[i + 1] = (i + 1) * fact[i] % MOD;
		inv[i + 1] = pow(fact[i + 1], MOD - 2);
		
		cin>>arr[i];
		if (pos[arr[i]] != -1)
			l = pos[arr[i]], r = i;
		else pos[arr[i]] = i;
	}
//	cout<<l<<' '<<r<<' '<<l<<' '<<bin(0, 1)<<'\n';
	for (i = 1; i <= n + 1; ++i)
		cout<<(bin(n + 1, i) + MOD - bin(l + n - r, i - 1)) % MOD<<'\n';
}


Measured memory_bytes: 3584
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
    int i;
    char ch;
    char a[26]="abcdefghijklmnopqrstuvwxyz";
    char A[26]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int add[26]={0};
    while ( scanf("%c", &ch)!= EOF ){
        for(i=0;i<26;i++){
            if(ch==a[i]){
                add[i]++;
            }else if(ch==A[i]){
                add[i]++;
            }
        
        }
    }
    for(i=0;i<26;i++){
        printf("%c : %d\n",a[i],add[i]);
    }
    return 0;
}

Measured memory_bytes: 540
#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)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()

using namespace std;

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

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
    int N;
    ll t;
    cin >> N;
    Vl ans(1);
    cin >> ans[0];
    FOR(i,1,N) {
        cin >> t;
        if (t <= ans[0]) ans.insert(ans.begin(),t);
        else {
            auto it = lower_bound(ALL(ans), t);
            --it;
            *it = t;
            }
        }
    cout << ans.size() << endl;
    }

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll n,L[200001],R[200001];
    cin>>n;
    rep(i,n) cin>>L[i]>>R[i];
    vector<pair<ll,ll>> A,B;
    rep(i,n) A.push_back(make_pair(L[i],R[i]));
    sort(A.begin(),A.end());
    rep(i,n-1) B.push_back(make_pair(A[i].second,A[i].first));
    sort(B.begin(),B.end());
    rep(i,n-1) swap(B[i].first,B[i].second);
    ll l=A[n-1].first,r=A[n-1].second,ans=0;
    ll m=0,a,b=0;
    rep(i,n-1) if(m<B[i].second-B[i].first+1) m=B[i].second-B[i].first+1,a=i;
    if(a==0&&n!=2) b++;
    ans=(min(r,B[b].second)-l+1)*(min(r,B[b].second)>=l)+m;
    ll l1=B[0].first,r1=B[0].second;
    B.push_back(make_pair(0,r));
    rep(i,n-1){
        ll kr=min(r,B[i+1].second);
        l1=max(l1,B[i].first),r1=min(r1,B[i].second);
        ans=max(ans,(r1-l1+1)*(r1-l1+1>0)+(kr-l+1)*(kr-l+1>0));
    }
    cout<<ans;
}

Measured memory_bytes: 7664
#include <iostream>

using namespace std;

int main()
{
	// 入力
	int N;
	cin >> N;
	
	bool isYes = false;
	// 九九の計算
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			if (N == i * j)
			{
				isYes = true;
			}
		}
	}
	
	if (isYes == true)
	{
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,k;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&k);
	if(a>=k) printf("%lld %lld\n",a-k,b);
	else printf("0 %lld\n",max(0ll,b-(k-a)));
}

Measured memory_bytes: 256
# しゃくとり法でいきます
n, m, k = gets.split.map &:to_i

# AとBの累積和を計算
prev = 0
a = [0] + gets.split.map { |s| prev += s.to_i }
prev = 0
b = [0] + gets.split.map { |s| prev += s.to_i }

# iはどこまでいける？
i = a.rindex { |x| x <= k }
x = a[i]

# jはどこまでいける？
j = b.rindex { |y| x + y <= k }

max_count = i + j

# iを1ずつ減らすと、jはどこまでいける？
i.downto(0) do |i|
  
  count = i
  x = (i >= 0) ? a[i] : 0
  
  (j+1).upto(m) do |_j|
    break if x + b[_j] > k
   	j = _j
  end
  
  count += j
  
  #STDERR.puts [i, j, count].inspect
  
  max_count = [max_count, count].max

end

p max_count


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

#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;
int mod = 1000000007;

void solve();

int main(void){
    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 d = 0;
    rep(i, M){
        while(d < N && D[d] < T[i]) d++;
        if(d < N && D[d] == T[i]) d++;
        else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
    int n,c,p[200];
    int sum=0;

    scanf("%d %d",&n,&c);
    for(int i=0;i<c;i++){
        scanf("%d",&p[i]);
        sum+=p[i];
    }
    if(sum%(n+1))printf("%d\n",sum/(n+1)+1);
    else printf("%d\n",sum/(n+1));

    return 0;
}


Measured memory_bytes: 2112
N,M=map(int,input().split(' '))
lights=[]
slist=[]

for i in range(M):
  line=input()
  
  switches=list(map(int,line.split(' ')))
  s_bit=0
  for switch in switches[1:]:
    s_bit+=1<<(switch-1)
  slist.append(s_bit)

plist=list(map(int,input().split(' ')))

#print('slist {}'.format(slist))
#print('plist {}'.format(plist))
ans=0
for state_switches in range((1<<N)):
  on_num=0
  #print('====')
  #print(state_switches)
  for k in range(M):
    s_bit=slist[k]
    s_on=s_bit&state_switches
    #print('s_bit state_swithces s_on : {} :{} : {}'.format(s_bit,state_switches,s_on))
    s_num=0
    for i in range(N):
      #print('s_on 1<<i result {} {} {}'.format(s_on,1<<i,s_on&(1<<i))) 
      s_num+=(s_on&(1<<i))>>i
    #print('s_num p {} {}'.format(s_num,plist[k]))
    if s_num%2==plist[k]:
      on_num+=1
    #print(on_num)
  if on_num==M:
    ans+=1

print(ans)


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


// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;
    int red[n+1];
    int white[n+1];
    white[0] = 0;
    red[0] = 0;
    rep(i,n)
    {
        white[i+1] = white[i];
        red[i+1] = red[i];
        if (s[i]=='W')
        {
            white[i+1] +=1;
        }
        if (s[n-1-i] == 'R')
        {
            red[i+1] += 1;
        }
    }
    if (red[n]==n || white[n]==n)
    {
        cout << 0 << endl;
        return 0;
    }

    rep(i,n+1)
    {
        if (white[i]==red[n-i])
        {
            cout << white[i] << endl;
            return 0;
        }
    }

    

}


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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];
    vector<ll> AB;
    rep(i, min(X, K)) rep (j, min(Y, K)) AB.push_back(A[i] + B[j]);
    sort(all(AB), greater<ll>());
    vector<ll> ABC;
    rep(i, min(X*Y, K)) rep(j, min(Z, K)) ABC.push_back(AB[i] + C[j]);
    sort(all(ABC), greater<ll>());
    rep(i, K) cout << ABC[i] << endl;
}

Measured memory_bytes: 42856
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define vec(a) vector<int>a
using namespace std;
//fibonacci
int binet(int n)
{
	return (pow((1+sqrt(5)),n-1)-pow((1-sqrt(5)),n-1))/(pow(2,n-1)*sqrt(5));
}


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll n,i,j,k,m,l;
	cin>>n;
	ll arr[n];
	for(i=0;i<n;i++)
		cin>>arr[i];
	k=0;
	for(i=0;i<n;i++)
	{
		for(j=i;j<n;j++)
		{
			if(i!=j)
			{
				k+=(arr[i]*arr[j]);
			}
		}
	}
	cout<<k<<"\n";
	return 0;
}

Measured memory_bytes: 3692
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
using namespace std;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int L = 0;
	for (int i = 1; i <= N; ++i) {
		int M = 0;
		int j = i;
		while (j) {
			M += j % 10;
			j /= 10;
		}
		if (A <= M && M <= B) L += i;
	}
	cout << L << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100010;
int n,m;
int tot,bian[N<<1],zhi[N<<1],col[N<<1],nxt[N<<1],head[N];
int add(int a,int b,int c,int d){
    ++tot,bian[tot]=b,col[tot]=c,zhi[tot]=d,nxt[tot]=head[a],head[a]=tot;
}
int fa[N],dep[N],top[N],hson[N],sz[N];
int dis[N];
void dfs(int x,int f){
	fa[x]=f;
	dep[x]=dep[f]+1;
	sz[x]=1;
    for(int i=head[x];i;i=nxt[i]){
        int y=bian[i];
        if(y==f)continue;
        dis[y]=dis[x]+zhi[i];
        dfs(y,x);
        sz[x]+=y;
        if(sz[y]>sz[hson[x]])hson[x]=y;
	}
}
void dfs(int x,int f,int r){
    top[x]=r;
    if(hson[x]){
        dfs(hson[x],x,r);
	}
	for(int i=head[x];i;i=nxt[i]){
	    int y=bian[i];
	    if(y==f||y==hson[x])continue;
	    dfs(y,x,y);
	}
}
int lca(int x,int y){
	while(top[x]!=top[y]){
	    if(dep[top[x]]<dep[top[y]])swap(x,y);
	    x=fa[top[x]];
	}
	if(dep[x]>dep[y])swap(x,y);
	return x;
}
int ans[N];
struct data{
    int op,col,len,id;
    data(int op=0,int col=0,int len=0,int id=0):
	    op(op),col(col),len(len),id(id){}
};
vector<data>v[N];
int sum[N],cnt[N];
void solve(int x,int f){
    for(vector<data>::iterator it=v[x].begin();it!=v[x].end();++it){
        ans[(it->id)]+=(it->op)*(cnt[(it->col)]*(it->len)-sum[(it->col)]);
	}
	for(int i=head[x];i;i=nxt[i]){
	    int y=bian[i];
	    if(y==f)continue;
	    sum[col[i]]+=zhi[i];
	    cnt[col[i]]++;
	    solve(y,x);
	    sum[col[i]]-=zhi[i];
	    cnt[col[i]]--;
	}
}
int main(){
//	freopen("1.in","r",stdin);
    cin>>n>>m;
    for(int i=1;i<n;++i){
    	int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        add(a,b,c,d);
        add(b,a,c,d);
	}
	dfs(1,0);
	dfs(1,0,1);
	for(int i=1;i<=m;++i){
	    int a,b,c,d;
	    scanf("%d%d%d%d",&a,&b,&c,&d);
	    int l=lca(c,d);
	    v[c].push_back(data(1,a,b,i));
	    v[d].push_back(data(1,a,b,i));
	    v[l].push_back(data(-2,a,b,i));
	    ans[i]=dis[c]+dis[d]-2*dis[l];
	}
	solve(1,0);
	for(int i=1;i<=m;++i){
	    printf("%d\n",ans[i]);
	}
}

Measured memory_bytes: 22004
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int[] p = new int[N + 1];

        for (int i = 1 ; i <= N ; i++) {
            p[i] = scanner.nextInt();
        }

        int count = 0;
        for (int i = 1 ; i <= N ; i++) {
            if (i != p[i]) count++;
        }

        if (count <= 2) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 35664
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return input()

n=I()
dp=[[0,0,0] for i in range(n+1)]
for i in range(n):
    a,b,c=IL()
    dp[i+1][0]=max(dp[i][1]+a,dp[i][2]+a)
    dp[i+1][1]=max(dp[i][0]+b,dp[i][2]+b)
    dp[i+1][2]=max(dp[i][0]+c,dp[i][1]+c)
print(max(dp[n]))

Measured memory_bytes: 22836
N,K = map(int,input().split())

li = [1 for i in range(N)]

for i in range(K):
    mm = int(input())
    lis = list(map(int,input().split()))

    for j in lis:
        li[j-1]=0

ans = 0
for i in range(N):
    if li[i]:
        ans += 1
print(ans)





Measured memory_bytes: 67456
N, P = map(int, input().split())
S = input()

mods = [0] * (N+1)
for i in range(N-1, -1, -1):
  mods[i] = (int(S[i])*pow(10, N-i-1, P)+mods[i+1]) % P
c = dict()
for m in mods:
  c[m] = c.get(m, 0)+1

ans = 0
if P == 2 or P == 5:
  for i, s in enumerate(S):
    s = int(s)
    if s % P == 0:
      ans += i+1
else:
  for i in range(N):
    c[mods[i]] -= 1
    ans += c[mods[i]]

print(ans)

Measured memory_bytes: 17396
using System;

class lec01_C{
  public static void Main(){
    int n,x,i,count = 0;
    n = int.Parse(Console.ReadLine());
    for(i =  0;i < n;i++){
      x = int.Parse(Console.ReadLine());
      if(Sosu(x) == true) count++;
    }
    Console.WriteLine(count);
  }
  public static bool Sosu(int x){
    if(x < 2) return false;
    else if(x == 2) return true;
    else if(x % 2 == 0) return false;

    double sqrtx = Math.Sqrt(x);
    for(int i = 3;i <= sqrtx;i += 2){
      if(x % i == 0) return false;
    }
    return true;
  }
}



Measured memory_bytes: 9132
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, P: "List[List[int]]"):
    fallen = -1
    count = 0
    P.sort(key=lambda p: p[1] * N - p[0])
    for p in P:
        if fallen==p[1]-1:
            continue
        if p[0] <= fallen:
            continue
        fallen = p[1]-1
        count += 1
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    P = [[int(), int()] for _ in range(M)]   # type: "List[List[int]]" 
    for i in range(M):
        P[i] = [int(next(tokens)), int(next(tokens))]
    solve(N, M, P)

if __name__ == '__main__':
    main()


Measured memory_bytes: 24488