akhauriyash/Code-Regression huggingface dataset:
S = input()
ans = 0
for i in range(len(S)):
    for j in range(1,len(S)+1):
        if i < j:
            OK = True
            for k in range(i, j):
                if not S[k] in "ACGT":
                    OK = False
            if OK:
                ans = max(ans, j-i)
print(ans)

Measured memory_bytes: 38256
from functools import lru_cache

@lru_cache(None)
def solve(n,k) :
  if n<=9:
    if k==0: return 1
    if k==1: return n
    return 0
  m, r = divmod(n, 10)
  return r*solve(m, k-1)+(9-r)*solve(m-1, k-1)+solve(m, k)

N = int(input())
K = int(input())
print(solve(N, K))

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

int main() {
    string S; // 4 UPPERCASE ENGLISH LETTERS
    cin >> S;
    string A;
    if (S[0] == S[1] && S[1] != S[2] && S[2] == S[3]) A = "Yes";
    else if (S[0] == S[2] && S[1] != S[2] && S[1] == S[3]) A = "Yes";
    else if (S[0] == S[3] && S[2] != S[3] && S[1] == S[2]) A = "Yes";
    else A = "No";
    cout << A << endl; 
    
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
using namespace std;
int n = 0;
char a[4];
int main()
{
	cin >> a;
	for (int i = 0; i < 4; i++)
	{
		if (a[i] == '-')
			n--;
		else
			n++;
	}
	cout << n;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=(1LL<<63) - 600;
const ll mod=1e9+7 ;


int main(){
  int N; string S; int Q; cin >> N >> S >> Q; 
  ll dd=0, mm=0, zenbu=0;
  rep(i, N){
    if(S[i]=='D') dd++;
    if(S[i]=='M') mm+=dd;
    if(S[i]=='C') zenbu+=mm;
  }
  //cout << zenbu << endl;
  rep(i, Q){
    int k; cin >> k; k++; ll cntm[N] = {}; ll cnt=0, ans=0;
    if(S[N-1]=='M'){
      cnt++; cntm[N-1]=1;
    }
    for(int i=N-2; i>=0; i--){
      if(S[i]=='M'){
        cntm[i] = cntm[i+1]+1; cnt++;
      }
      else cntm[i] = cntm[i+1];
    }
    //rep(i, N){
      //if(S[i]=='D') cout << cntm[i] << endl;
    //}
    ll rui[N] = {}; if(S[0]=='D') rui[0] = cntm[0];
    for(int i=1; i<N; i++){
      if(S[i]=='D') rui[i] = rui[i-1]+cntm[i];
      else rui[i] = rui[i-1];
    }
    ll cntd=0;
    for(int i=k-1; i<N; i++){
      if(S[i-k+1]=='D'){
        cntd++;
      }
      if(S[i]=='C'){
        ans+=rui[i-k+1];
        //cout << rui[i-k+1] << " " << i << endl;
        ans-=cntm[i]*cntd;
        //cout << cntm[i] << " " << cntd << endl;
      }
    }
    cout << zenbu-ans << endl;
  }
}

Measured memory_bytes: 17028
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        // int b = stdIn.nextInt();
        // int c = stdIn.nextInt();
        // String s = stdIn.next();
        boolean flag = true;
         
        // if(a == b && b == c){
        //     flag = false;
        // } 
        
        // if(a != b && a != c && b != c){
        //     flag = false;
        // }
        
        int num[] = new int[n];
        
        for(int i = 0; i < n; i++){
            num[i] = stdIn.nextInt();
            
            if(num[i] % 2 == 0){
                if(num[i] % 3 == 0 || num[i] % 5 == 0){
                    
                }else{
                    flag = false;
                }
            }
        }
        
        // char c[] = s.toCharArray();
        
        // for(int i = 0; i < s.length(); i++){
        //     c[i];
        // }
        
        if(flag){
            System.out.println("APPROVED");
        }else{
            System.out.println("DENIED");
        }
        
        // System.out.println();
        // System.out.print();
    }
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  cin >> a;
  cin >> b;
  if (a % 2 != 0  && b % 2 != 0){
   cout << "Odd" ;
  }
  else{
    cout << "Even" ;
  }
}

Measured memory_bytes: 256
S = input()
T = input()

import math
res = math.inf

from collections import Counter

mt = list(map(ord, list(T)))
for i in range(len(S) - len(T) + 1):
    # print(S[i: i + len(T)], [a - b for a, b in zip(map(ord, list(S[i: i + len(T)])), mt)])
    res = min(res, len(T) - Counter([a - b for a, b in zip(map(ord, list(S[i: i + len(T)])), mt)])[0])
print(res)

Measured memory_bytes: 9332
#include <iostream>

bool isLeapYear(int year);
template <class Callback>
bool findLeapYears(int from, int to, Callback callback);

int main()
{
    bool is_first_data = true;
    while (true) {
        int from, to;
        std::cin >> from >> to;
        if (from == 0 && to == 0) {
            break;
        }
        if (!is_first_data) {
            std::cout << '\n';
        }
        bool leap_year_found = findLeapYears(from, to, [](int year) {
            std::cout << year << std::endl;
        });
        if (!leap_year_found) {
            std::cout << "NA" << std::endl;
        }
        is_first_data = false;
    }
    return 0;
}

bool isLeapYear(int year)
{
    if (year % 400 == 0) {
        return true;
    }
    if (year % 4 == 0 && year % 100 != 0) {
        return true;
    }
    return false;
}

template <class Callback>
bool findLeapYears(int from, int to, Callback callback)
{
    bool leap_year_found = false;
    for (int y = from; y <= to; ++y) {
        if (isLeapYear(y)) {
            leap_year_found = true;
            callback(y);
        }
    }
    return leap_year_found;
}

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

int abs( int a )
{
    return a > 0 ? a : -a;
}

int main()
{
    int n;

    cin >> n;

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

    for( int i = 0; i < n - 1; i++ )
        for( int j = i + 1; j < n; j++ )
            if( abs( a[i] - a[j] ) % ( n - 1 ) == 0 )
            {
                cout << a[i] << " " << a[j] << endl;
                return 0;
            }

    return 0;
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
const i64 MOD = 1e9+7;
const i64 INF = 1e18+7;


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

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


void solve(string s){
    struct Data{
        Data(int a, int v) : r(a), v(v){}
        int r, v;
    };
    function<Data(int)> f;

    array<int, 3> res{0, 0, 0};

    f = [&](int l){
        if(s[l] == '0')
            return Data(l + 1, 0);
        if(s[l] == '1')
            return Data(l + 1, 1);
        if(s[l] == '2')
            return Data(l + 1, 2);
        if(s[l] == 'P')
            return Data(l + 1, res[0]);
        if(s[l] == 'Q')
            return Data(l + 1, res[1]);
        if(s[l] == 'R')
            return Data(l + 1, res[2]);
        if(s[l] == '-'){
            auto a = f(l + 1);
            return Data(a.r, 2 - a.v);
        }
        if(s[l] == '('){
            auto a = f(l + 1);
            auto b = f(a.r + 1);
            int v = 0;
            if(s[a.r] == '*'){
                v = min(a.v, b.v);
            }
            if(s[a.r] == '+'){
                v = max(a.v, b.v);
            }
            // cout << a.v << " " << b.v << " " << s.substr(l, b.r + 1 - l) << endl;
            return Data(b.r + 1, v);
        }
    };
    int ans = 0;
    for(int i = 0; i < 27; ++i){
        res[0] = i % 3;
        res[1] = (i / 3) % 3;
        res[2] = (i / 9) % 3;
        ans += (f(0).v == 2);
    }
    cout << ans << endl;
}


signed main(){
    string s;
    cin >> s;
    while(s != "."){
        solve(s);
        cin >> s;
    }
}



Measured memory_bytes: 3072
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

vector<vector<int > >graph(100100);

queue<int>que;
int main(){
    ll n,x,y;
    cin>>n>>x>>y;
    vector<ll>answer(n);
    REP(i,n)answer[i]=0;
    REP(i,n-1){
        graph[i].push_back(i+1);
        graph[i+1].push_back(i);
    }
    graph[x-1].push_back(y-1);
    graph[y-1].push_back(x-1);

    REP(j,n){
        vector<int>dist(n,-1);
        que.push(j);
        dist[j]=0;
        while (!que.empty()) {
            int v = que.front(); // キューから先頭頂点を取り出す
            que.pop();

            // v から辿れる頂点をすべて調べる
            for (int nv : graph[v]) {
                if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

                // 新たな白色頂点 nv について距離情報を更新してキューに追加する
                dist[nv] = dist[v] + 1;
                que.push(nv);
            }
        }
        REP(i,n){
            answer[dist[i]]++;
        }
    }
    FOR(i,1,n){
        cout << answer[i] / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;

int n, k; 
int a[N];

bool ok(int mid) {
    int need = 0;
    for (int i = 0; i < n; i++) {
        need += (a[i] - 1) / mid;
    }
    return need <= k;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int l = 1, r = 1e9;
    while (r - l > 1) {
        int mid = (l + r) / 2;
        if (ok(mid)) r = mid;
        else l = mid;
    }
    cout << (ok(l) ? l : r) << "\n";
}

Measured memory_bytes: 4324
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);

    int all;

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

    all = a[0];
    for (int i = 1; i < n; i++) {
        all = all ^ a[i];
    }

    for (int i = 0; i < n; i++) {
        int ans = all ^ a[i];
        cout << ans;
        if (i < n - 1)
            cout << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	deque<char> que;
	string s;
	int i,q,t,f,r=0; char c;
	vector<char> str;
	vector<char> en;
	cin>>s>>q;
	for(i=0;i<s.length();i++) que.push_back(s[i]);
	while(q--)
	{
		cin>>t;
		if(t==1) r=(r+1)%2;
		else 
		{
			cin>>f>>c;
			if((f==1 && !r)|| (f==2 && r)) que.push_front(c);
			else que.push_back(c);
		}
	}
		s="";
		for(auto j:que) s.push_back(j);
		if(r){
			for(i=s.length()-1;i>-1;i--) cout<<s[i];
		}
	else cout<<s;
}

Measured memory_bytes: 1280
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    string S,T;
    cin >> S >> T;
    ll n = S.size();
    if(T.substr(0,n) == S){
        print("Yes");
    }else{
        print("No");
    }
    

}

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

Measured memory_bytes: 3652
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;

int main(void){
    int N;
    cin >> N;
    int place[N]={};
    rep(i,N) place[i]=INF;
    string S[N];
    rep(i,N) cin >> S[i];
    lint ans=0;
    int cnt[N]={};
    rep(i,N){
        bool period=false;
        int save=0;
        rep(j,S[i].length()){
            if(period) cnt[i]++;
            if(S[i][j]=='.') period=true,save=j,place[i]=j;
        }
    }
    rep(i,N) if(place[i]!=INF) S[i].erase(place[i],1);
    lint A[N];
    rep(i,N) A[i]=stoll(S[i]);
    int two[N]={};
    int five[N]={};
    rep(i,N){
        while(A[i]%2==0) two[i]++,A[i]/=2;
        while(A[i]%5==0) five[i]++,A[i]/=5;
    }
    lint num[10][48][21]={};
    rep(i,N) num[cnt[i]][two[i]][five[i]]++;
    rep(i,10) rep(j,48) rep(k,21){
        rep(i2,10) rep(j2,48) rep(k2,21){
            if(min(j+j2,k+k2)>=i+i2){
                ans+=num[i][j][k]*num[i2][j2][k2];
            }
        }
    }
    rep(i,10) rep(j,48) rep(k,21) if(min(j,k)>=i) ans-=num[i][j][k];
    ans/=2;
    cout << ans << endl;
}

Measured memory_bytes: 14636
/// Bismillahir Rahmanir Rahim
/* Author: Mohammad Morsalin
    Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define f0(n) for(int i=0;i<n;i++)
#define tc(t) int t;cin>>t; while(t--)
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int,vector<int>,greater<int> >
#define ms(x) memset(x,0,sizeof(x))
#define ins insert
#define ALL(v) v.begin(),v.end()
#define ii pair<int,int>
#define vii vector<ii>
#define fi first
#define se second
#define none(n)  __builtin_popcount(n);
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define PI acos(-1)
#define IOS ios::sync_with_stdio(false);
using namespace std;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
int main()
{
    IOS
    int h1,m1,h2,m2,k;
    while(cin>>h1>>m1>>h2>>m2>>k){
        if(h1>h2)h2+=24;
        cout << (h2*60 +m2)-(h1*60 +m1)-k << endl;
    }
    return 0;
}
///Alhamdulillah



Measured memory_bytes: 3584
#include <stdio.h>

int ans[10000], size;

int main(void) {
	int i;
	int n;

	scanf("%d", &n);

	i = 1;
	while (n >= i) {
		ans[size++] = i;
		n -= i;
		i++;
	}

	i = size - 1;
	while (n--)
		ans[i--]++;

	for (i = 0; i < size; i++)
		printf("%d\n", ans[i]);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(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--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MAXIN(x) max_element(ALL(x)) - x.begin();
#define MIN(x) *min_element(ALL(x))
#define MININ(x) min_element(ALL(x)) - x.begin();
#define INF 1000000000000
#define MOD 100000070

#define MAXR 100000
#define PI 3.14159265358979323846

using namespace std;

signed main() {
    int a, b;
    cin >> a >> b;
    cout << a*b <<endl ;

    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

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

  double ans=0;
  ans = 2.0*r*M_PI;
  printf("%lf\n",ans);
  
  return 0;
}


Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//その桁が1つ増えると余りがいくつ増えるか用意
//1桁増えるごとに、0-12の13通りが何個あるか加算？
//いや、何ループ増えるかを加算？
//？じゃない場合困る
//??の場合
//0-9まで1個ずつ
//10のとき1~9に+10したのを加算
//1桁目だけ普通に加算？
//まちがえた。11のとき、1と11を加算とか変なことになってる
//1?1?
//130?
//13?
int main(){
  string S; cin>>S;
  ll ssz=S.size(),tmp=1, MOD=1e9+7;  
  vector<vector<ll>> DP(ssz+1, vector<ll>(13,0));
  DP[0][0]=1;
  vector<ll> DG(ssz+1,0);
//桁ごとのあまり増加量
  for(int i=0; i<ssz; i++){
    tmp%=13;
    DG[i]=tmp;
    tmp*=10;
  }
  for(int i=ssz-1; i>=0; i--){
    if(S[i]!='?'){
      ll up=DG[ssz-1-i]*(S[i]-'0');
      up%=13;
      for(int j=0; j<13; j++)
        DP[ssz-i][(j+up)%13]=DP[ssz-i-1][j];
    }
    else{
      for(int j=0; j<=9; j++){
      ll up=DG[ssz-1-i]*j;
      up%=13;
        for(int k=0; k<13; k++){
          ll ku=(k+up)%13;
          DP[ssz-i][ku]+=DP[ssz-i-1][k];
          DP[ssz-i][ku]%=MOD;
        }
      }
    }
  }
  cout<<DP[ssz][5]<<endl;
}

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

int main(){

    int N, M, X, Y;
    int x[100], y[100];
    cin >> N >> M >> X >> Y;
    for( int i = 0; i < N; i++ ) cin >> x[i];
    for( int i = 0; i < M; i++ ) cin >> y[i];

    
    bool war = true; //戦争が起きるかどうか

    for( int Z = X+1; Z <= Y; Z++ ){
        bool x_cond = false, y_cond = false; //それぞれの条件を満たすZがあるか
        for( int i = 0; i < N; i++ ){
            if( Z <= x[i] ) break;
            if( i == N-1 ) x_cond = true;
        }
        for( int j = 0; j < M; j++ ){
            if( y[j] < Z ) break;
            if( j == M-1 ) y_cond = true;
        }
        if( x_cond && y_cond ){
            cout << "No War" << endl;
            war = false;
            break;
        }
    }

    if( war ) cout << "War" << endl;

    return 0;

}

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

#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#define fi first
#define se second
#define pb push_back
#define last(s) (s)[(s).length()-1]
#define all(a) (a).begin(),(a).end()
#define elif else if
#define left asdasd
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

using llong = long long;
using ld = long double;
using ii = pair<int,int>;
using ull = unsigned long long;
using pll = pair<llong, llong>;

const llong over999 = 1e16;
const llong md = 1e9+7;
const ld eps = 1e-9;
const ld Pi = acos(-1);

/*asdasdasdasdasdasdasdasdasd*/


llong n, a[100010], A, B;

int32_t main()
{
    kchay;
    
    cin >> n;
    
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    sort(a, a+n);
    reverse(a, a+n);
    bool flag = false;
    for(int i = 0; i < n-1; i++)
    {
        if(a[i] == a[i+1])
        {
            if(!flag)A = a[i]; else B = a[i];
            if(flag)break;
            flag = true;
            i++;
        }
    }
    
    cout << A*B << endl;
    return 0;
}

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

int main() {
    char a, b;
    cin >> a >> b;
    if (a == 'H'){
        if (b == 'H'){
            cout << "H" << endl;
            return 0;
        }
    } else {
        if (b == 'D'){
            cout << "H" << endl;
            return 0;
        }
    }
    cout << "D" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int search(int S[], int n, int key) {
  S[n] = key; // sentinel
  int i = 0;
  while (S[i] != key) { i++; }

  return i != n;
}

int main() {
  int n, S[10000+1], q, key, ans = 0;

  scanf("%d", &n);
  for (int i=0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  
  scanf("%d", &q);
  for (int i=0; i < q; i++) {
    scanf("%d", &key);
    if ( search(S, n, key) ) {
      ans++;
    };
  }

  printf("%d\n", ans);
}



Measured memory_bytes: 2768
N, M, X, Y = map(int, raw_input().split())
x = map(int, raw_input().split())
y = map(int, raw_input().split())

pos_cls = [[i, 'x'] for i in x]
pos_cls.append([X, 'x'])
pos_cls.extend([[i, 'y'] for i in y])
pos_cls.append([Y, 'y'])
pos_cls = sorted(pos_cls, key=lambda x:x[0])
if 'y' in [i[1] for i in pos_cls[:N+1]] or pos_cls[N][0] == pos_cls[N+1][0]:
	print 'War'
else:
	print 'No War'


Measured memory_bytes: 2568
using System;
using System.Collections.Generic;
using System.Linq;

public struct Point
{
    public int X;
    public int Y;

    public Point(Point p)
    {
        X = p.X;
        Y = p.Y;
    }

    public Point(int x, int y)
    {
        X = x;
        Y = y;
    }

    public static bool operator ==(Point a, Point b)
    {
        return (a.X == b.X && a.Y == b.Y);
    }

    public static bool operator !=(Point a, Point b)
    {
        return !(a == b);
    }

    //objと自分自身が等価のときはtrueを返す
    public override bool Equals(object obj)
    {
        if (!(obj is Point))
        {
            return false;
        }

        Point p = (Point)obj;
        return (X == p.X && Y == p.Y);
    }

    //Equalsがtrueを返すときに同じ値を返す
    public override int GetHashCode()
    {
        return (X << 16) ^ Y;
    }

    public Point Clone()
    {
        return new Point(X, Y);
    }

    public void Reverse()
    {
        X = -X;
        Y = -Y;
    }

    public static Point operator +(Point a, Point b)
    {
        return new Point(a.X + b.X, a.Y + b.Y);
    }

    public static Point operator -(Point a, Point b)
    {
        return new Point(a.X - b.X, a.Y - b.Y);
    }

    public static Point operator *(Point a, int i)
    {
        return new Point(a.X * i, a.Y * i);
    }

    public static Point operator /(Point a, int i)
    {
        return new Point(a.X / i, a.Y / i);
    }
    public static Point operator +(Point a)
    {
        return new Point(+a.X, +a.Y);
    }

    public static Point operator -(Point a)
    {
        return new Point(-a.X, -a.Y);
    }

    public override string ToString()
    {
        return string.Format("({0},{1})", X, Y);
    }
}

public static class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var H = vals[0];
        var W = vals[1];
        var M = vals[2];
        var yCount = new int[H];
        var xCount = new int[W];
        var exist = new HashSet<Point>();
        for (int i = 0; i < M; i++)
        {
            vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x) - 1).ToArray();
            var p = new Point(vals[1], vals[0]);
            yCount[p.Y]++;
            xCount[p.X]++;
            exist.Add(p);
        }

        var yMax = yCount.Max();
        var xMax = xCount.Max();
        var yIndexes = Enumerable.Range(0, H).Where(i => yCount[i] == yMax).ToList();
        var xIndexes = Enumerable.Range(0, W).Where(i => xCount[i] == xMax).ToList();
        int minus = -1;
        foreach (var y in yIndexes)
        {
            foreach (var x in xIndexes)
            {
                if (!exist.Contains(new Point(x, y)))
                {
                    minus = 0;
                    break;
                }
            }
            if (minus == 0)
            {
                break;
            }
        }

        var max = yMax + xMax + minus;
        Console.WriteLine(max);
    }
}

Measured memory_bytes: 56964
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
ll A,B,V,W,T,C;
string S;
int main() {
    cin >> A >> V >> B >> W >> T;
    C = abs(A-B);
    if(V-W<=0){
        cout << "NO" << endl;
    }else if(C>(V-W)*T){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
    while (true) {
        int n, p[1000], d[1000];
        long long dsum = 0, sum1 = 0, dist[1000];
        vector<int> edge_to[1000];
        vector<int> edge_cost[1000];
        cin >> n;
        if (!n) break;
        
        for (int i = 1; i < n; ++i) {
            cin >> p[i];
            --p[i];
        }
        for (int i = 1; i < n; ++i) {
            cin >> d[i];
            dsum += d[i];
        }
        
        for (int i = 1; i < n; ++i) {
            edge_to[i].push_back(p[i]);
            edge_cost[i].push_back(d[i]);
            edge_to[p[i]].push_back(i);
            edge_cost[p[i]].push_back(d[i]);
        }
        int now = -1;
        queue<int> q;
        for (int i = 0; i < n; ++i) {
            dist[i] = -1;
            if (edge_to[i].size() > 1){
                now = i;
            }
            else{
                sum1 += edge_cost[i][0];
            }
        }
        if (now == -1){
            cout << dsum * 3 - sum1 * 2 << "\n";
            continue;
        }
        q.push(now);
        dist[now] = 0;
        while (!q.empty()) {
            int p = q.front();
            q.pop();
            for (int j = 0; j < edge_to[p].size(); ++j) {
                int to = edge_to[p][j];
                int cost = edge_cost[p][j];
                if (edge_to[to].size() < 2 || dist[to] > -1) continue;
                
                dist[to] = dist[p] + cost;
                q.push(to);
            }
        }
        long long ma = -1;
        for (int i = 0; i < n; ++i) {
            if (ma < dist[i]){
                ma = dist[i];
                now = i;
            }
            dist[i] = -1;
        }
        q.push(now);
        dist[now] = 0;
        while (!q.empty()) {
            int p = q.front();
            q.pop();
            for (int j = 0; j < edge_to[p].size(); ++j) {
                int to = edge_to[p][j];
                int cost = edge_cost[p][j];
                if (edge_to[to].size() < 2 || dist[to] > -1) continue;
                
                dist[to] = dist[p] + cost;
                q.push(to);
            }
        }
        ma = -1;
        for (int i = 0; i < n; ++i) {
            if (ma < dist[i]){
                ma = dist[i];
            }
        }
        cout << dsum * 3 - sum1 * 2 - ma << "\n";
    }
    return 0;
}

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

const int dx[] = { -1 , 0 , 1 , 0 } ;
const int dy[] = { 0 , 1 , 0 , -1 } ;

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    string s ;
    cin >> s ;

    # define pf push_front

    deque < char > q ;
    for ( auto &i : s )
        q.pb ( i ) ;

    int qry ;
    cin >> qry ;

    int x = 0 ;
    while ( qry -- )
    {
        int p ;
        cin >> p ;

        if ( p == 1 )
        {
            x ^= 1 ;
            C ;
        }

        cin >> p ;
        char c ; cin >> c ;

        if ( x == 0 )
        {
            if ( p == 1 )
                q.pf ( c ) ;
            else
                q.pb ( c ) ;
        }

        else
        {
            if ( p == 1 )
                q.pb ( c ) ;
            else
                q.pf ( c ) ;
        }
    }

    string ans = "" ;

    while ( q.empty() == false )
    {
        auto c = q.back() ;
        q.pop_back() ;

        ans += c ;
    }

    if ( x == 0 ) reverse ( all ( ans ) ) ;

    cout << ans ; line

}

int main()
{fast
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 1368
var s:string;
n:qword;
i:integer;
begin 
	readln(s);
	read(n);
	if n=1 then begin write(s[1]);exit;end;
	i:=1;
	while s[i]='1' do
	begin 
		if n=1 then begin write('1');exit; end;
		inc(i);
		dec(n);
	end;
	write(s[i]);
end.

Measured memory_bytes: 128
def main():
    n = int(input())
    inlis = list(map(int, input().split()))

    num2 = 0
    num4 = 0

    for i in range(n):
        a = inlis[i]
        if a % 4 == 0:
            num4 += 1
        elif a % 2 == 0:
            num2 += 1
    if n <= 3:
        if num4 >=1:
            print('Yes')
        elif num2 == n:
            print('Yes')
        else:
            print('No')
    else:
        if num2 + (2*num4) >= n:
            print("Yes")
        else:
            if n % 2 != 0 and num2 + (2*num4 +1) >= n:
                print('Yes')
            else:
                print('No')





if __name__ == "__main__":
    main()

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=1,ans=1,a[10000000],b[10000000],c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

        cin>>n;
        ans=n;
        rep(i,n)cin>>a[i];
        sort(a,a+n);
        rep(i,n-1){
                if(a[i]*2>=a[i+1]){
                        a[i+1]+=a[i];
                        cnt++;
                }else{
                        a[i+1]+=a[i];
                        ans-=cnt;
                        cnt=1;
                        //Cout(ans);
                }
        }
        Cout(ans);
return 0;
}


Measured memory_bytes: 2304
c = 0 # counts of paper to be ok to use
r = 0
t = []
for l in raw_input():
	if l == 'g':
		if c:
			r +=1
			c -=1
		else:
			c+=1
	elif l == 'p':
		if c:
			c-=1
		else:
			r -=1
			c +=1

print r


Measured memory_bytes: 85048
#include <iostream>
#include <array>
#include <string>

using namespace std;

constexpr int SURFACE_NUM = 6;
enum {TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM};

class Dice {
private:
    array<int, SURFACE_NUM> m_surface;

public:
    // constructor
    Dice(array<int, SURFACE_NUM> surface)
        : m_surface(surface) {}

    // getter
    int surface(int i) const
    {
        return m_surface.at(i);
    }

    // roll and spin
    void roll(char direction)
    {
        switch (direction) {
        case 'N':
            roll(TOP, FRONT, BOTTOM, BACK);
            break;
        case 'S':
            roll(TOP, BACK, BOTTOM, FRONT);
            break;
        case 'E':
            roll(TOP, LEFT, BOTTOM, RIGHT);
            break;
        case 'W':
            roll(TOP, RIGHT, BOTTOM, LEFT);
            break;
        }
    }

    void roll(int i, int j, int k, int l)
    {
        int tmp = m_surface.at(i);
        m_surface.at(i) = m_surface.at(j);
        m_surface.at(j) = m_surface.at(k);
        m_surface.at(k) = m_surface.at(l);
        m_surface.at(l) = tmp;
    }

    void spin()
    {
        int tmp = m_surface.at(FRONT);
        m_surface.at(FRONT) = m_surface.at(LEFT);
        m_surface.at(LEFT) = m_surface.at(BACK);
        m_surface.at(BACK) = m_surface.at(RIGHT);
        m_surface.at(RIGHT) = tmp;
    }

    int right(int top, int fr)
    {
        if (m_surface.at(RIGHT) == top || m_surface.at(LEFT) == top) {
            (*this).roll('E');
        }
        while (m_surface.at(TOP) != top) {
            (*this).roll('N');
        }
        while (m_surface.at(FRONT) != fr) {
            (*this).spin();
        }

        return m_surface.at(RIGHT);
    }

    // debug
    void printDice() const
    {
        cout << surface(TOP) << surface(FRONT)
             << surface(RIGHT) << surface(LEFT)
             << surface(BACK) << surface(BOTTOM) << endl;
    }
};

int main()
{
    array <int, SURFACE_NUM> init;
    for (auto i = 0; i < SURFACE_NUM; i++) {
        cin >> init.at(i);
    }
    Dice one(init);

    int n;
    cin >> n;
    while (n--) {
        int top, fr;
        cin >> top >> fr;
        cout << one.right(top, fr) << endl;
    }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,a,b) for(int i=a;i>b;i--)
#define cases() ll t;cin>>t;while(t--)
int main()
{
    ll n;
    cin>>n;
    ll z=0;
    if(n%2==0)
    {
      ll j=5;
      while(1)
      {
          z=z+(ll)(n/(j*2));

          j=j*5;
          if((ll)(n/j)==0)
            break;
      }
      cout<<z;
    }
    else
        cout<<0;
    return 0;
}


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

int main (void) {
    string s;
    long long k;
    cin >> s;
    cin >> k;
    char current = s[0];
    long long curCount = 1, replace = 0;
    bool sameFlag = false;
    for (int i = 1, len = s.size(); i <= len; i++) {
        if (s[i] == current) {
            curCount++;
        }
        else {
            replace += curCount / 2;
            current = s[i];
            if (curCount == len)
                sameFlag = true;
            curCount = 1;
        }
    }

    // cout << "replace in t: " << replace << endl;
    long long extra = 0;

    if (sameFlag) {
        if (s.size() % 2) {
            extra = k / 2;
        }
    }
    else if (s[0] == s[s.size() - 1]) {
        int countF = 0, countL = 0, flagF = 1, flagL = 1;
        for (int i = 0, len = s.size(); i < len && (flagF || flagL); i++) {
            if (flagF) {
                if (s[i] == s[0]) {
                    countF++;
                }
                else {
                    flagF = 0;
                }
            }
            if (flagL) {
                if (s[len - i - 1] == s[0]) {
                    countL++;
                }
                else {
                    flagL = 0;
                }
            }
        }
        // cout << "countF: " << countF << endl << "countL: " << countL << endl;
        if ((countF % 2) && (countL % 2)) {
            extra = k - 1;
        }
    }

    replace *= k;
    replace += extra;
    cout << replace << endl;    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
	int n, m, a[101] = { 0 }, b[101] = { 0 }, k[101][101] = { 0 }, s;
	cin >> n >> m;
	for (int i = 1;i <= m;i++) { cin >> a[i]; }
	for (int i = 0;i < m;i++) {
		for (int j = 0;j < n;j++) {
			cin >> k[i][j];
		}
	}
	for (int i = 0;i < m;i++) {
		for (int j = 0;j < n;j++) {
			s = 0;
			if (a[i + 1] == k[i][j])
				b[j + 1] += 1;
			else { s += 1; }
			b[a[i + 1]] += s;
		}
	}
	for (int i = 0;i < n;i++)
		cout << b[i + 1] << endl;
	int f;
	cin >> f;
	return 0;
}


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

int main() {
    long n, ans = 0;
    cin >> n;
    map<string, long> mp;
    rep(i, n) {
        string str;
        cin >> str;
        sort(str.begin(), str.end());
        mp[str]++;
        ans += mp[str] - 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
options = [None] * N
for i in range(N):
    options[i] = tuple(int(x) for x in readline().split())


def solve():
    da, db, dc = 0, 0, 0
    for i in range(N):
        xa, xb, xc = options[i]
        xa += da
        xb += db
        xc += dc
        da, db, dc = max(xb, xc), max(xa, xc), max(xa, xb)
    print(max(da, db, dc))


if __name__ == "__main__":
    solve()


Measured memory_bytes: 54012
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int N, H, W; cin >> N >> H >> W;
	cout << (N - H + 1)*(N - W + 1) << endl;


	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;

int MOD = 998244353;

ll v[200100] = {0};
vector<ll> G[200010];
int used[200010] = {0};

ll s_cnt[26] = {0};
ll t_cnt[26] = {0};

ll nex[200010][26] = {0};

signed main(){

    string s,t;
    cin >> s >> t;
    ll n = s.size();
    ll m = t.size();

    rep(i,n)s_cnt[s[i]-'a']++;
    rep(i,m)t_cnt[t[i]-'a']++;

    rep(i,26){
        if(t_cnt[i] != 0 && s_cnt[i] == 0){
            cout << -1 << endl;
            return 0;
        }
    }

    rep(i,26){
        nex[n][i] = INF;
        for(int j = n-1;j >= 0;j--){
            nex[j][i] = nex[j+1][i] + 1;
            if(s[j] == i+'a')nex[j][i] = 0;
        }   
    }

    // rep(i,26){
    //     cerr << (char)(i+'a') << " : ";
    //     rep(j,n){
    //         if(nex[j][i] > 3000000)cerr << "x ";
    //         else cerr << nex[j][i] << " ";
    //     }cerr << endl;
    // }


    ll tp = 0,sp = 0;
    ll ans = 0;

    while(tp < m){
        if(nex[sp][t[tp]-'a'] < 300000){
            ans += nex[sp][t[tp]-'a']+1;
            sp += nex[sp][t[tp]-'a']+1;
        }else{
            ans += n-sp;
            sp = 0;
            tp--;
        }
        tp++;
        // cerr << ans << endl;
    }
    cout << ans << endl;




    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc138.contest.atcoder.jp/tasks/abc138_b

Measured memory_bytes: 29184
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define MOD 1000000007

using namespace std;

int main()
{
  int m, n;
  int a[1000];
  int b[1000];
  cin >> n >> m;
  REP(i, n)
  {
    cin >> a[i];
  }
  REP(i, m)
  {
    cin >> b[i];
  }

  sort(a, a + n);
  sort(b, b + m);

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

  REP(i, m - 1)
  {
    if (b[i] == b[i + 1])
    {
      cout << 0 << endl;
      return 0;
    }
  }

  ll result = 1;

  for (int i = n * m; i > 0; i--)
  {
    int ai = lower_bound(a, a + n, i) - a;
    int bi = lower_bound(b, b + m, i) - b;

    if (a[ai] == i && b[bi] == i)
    {
      continue;
    }
    if (a[ai] == i)
    {
      result = result * (m - bi) % MOD;
      continue;
    }
    if (b[bi] == i)
    {
      result = result * (n - ai) % MOD;
      continue;
    }
    result = result * ((n - ai) * (m - bi) - (m * n - i)) % MOD;
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;
ll a[100001];
ll t[2][100001]={};
ll r[2]={};
int main() {
	int n;
	cin>>n;
	for(int i=0;i<n;++i){
		cin>>a[i];
	}
	t[0][0]=a[0];
	if(a[0]==0){
		t[0][0]=-1;
		t[1][0]=1;
		r[0]=1;
		r[1]=1;
	}
	if(a[0]>0){
		t[1][0]=-1;
		r[1]=t[0][0]+1;
	}
	if(a[0]<0){
		t[1][0]=1;
		r[1]=-t[0][0]+1;
	}
	for(int i=0;i<2;++i){
		for(int j=1;j<n;++j){
			t[i][j]=t[i][j-1]+a[j];
			if(t[i][j-1]<0&&t[i][j]<=0){
				r[i]+=1-t[i][j];
				t[i][j]=1;
			}
			if(t[i][j-1]>0&&t[i][j]>=0){
				r[i]+=1+t[i][j];
				t[i][j]=-1;
			}
		}
	}
	cout<<min(r[0],r[1])<<endl;
	return 0;
}


Measured memory_bytes: 2560
/* vishal shrivastava
     185023
     nit hamirpur
   */
  #include <bits/stdc++.h>
  using namespace std;
  #define minpq priority_queue <int, vector<int>, greater<int> >;
  #define maxpq  priority_queue <int>;
  #define F first
  #define S second
  #define mp make_pair
  #define pb push_back
  #define f(i,x,n) for(int i=x;i<n;i++)
  #define all(c) c.begin(),c.end()
  #define ll long long
  #define pll pair<ll,ll>
  #define pii pair<int,int>
  const int mod = 1e9+7, N = 1e5 + 10;
  int solve()
  {

     ll n;
     cin>>n;
     int a[n];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
     }
     sort(a,a+n);
     a[1]=a[1]+a[0];
     double sum=0;
     for(int i=1;i<n;i++)
     {    double p=pow(2,n-i);
         sum=sum+(a[i]/p);
     }
     cout<<setprecision(12)<<fixed<<sum;
  }

  int32_t main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int test=1;
    //cin>>test;
    while(test--)
    {
      solve();
    }
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {

	int n, m;
	cin >> n >> m;
	vi k(m), p(m);
	vvi s(m);
	rep(i, m) {
		cin >> k[i];
		rep(j, k[i]) {
			int sw;
			cin >> sw;
			sw--;
			s[i].push_back(sw);
		}
	}
	rep(i, m)cin >> p[i];
	
	int ans = 0;
	rep(bit, 1 << n) {
		bool ok = true;

		rep(i, m) {
			int on = 0;
			rep(j, k[i])if ((bit >> s[i][j]) & 1)on++;
			if (on % 2 != p[i])ok = false;
		}
		if (!ok)continue;
		ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3636
// 2次元の友達リストとブロックリストを作りグラフとする
//
// 友達候補: 友達リストにもブロックリストにも含まれず、
//          友達グラフ上で到達可能
//
// グラフ作成は O(N)
// 友達候補が誰か探すのに O(N^2) 掛かりそう
//
// ↑
//
// やばそうだから 友人関係2次元表を作る
// 友人関係なら +1, ブロック関係なら -1, 友達候補の候補なら 0　とする
// 友達候補とわかったら2とかにする
// 最終的に2の数を数える
// これなら友達候補を探すときに O(N) でわかる
//
// 2次元の表にすると友達候補かどうかも 表をたどればわかる
//
// 友達関係となる条件を満たしているかの走査に O(N) をN人に対して行うので O(N^2)
//
// 間に合わなくね
//
//とりあえずTLEなるか試す
//
// 答えすら合わなかった
// 解説みる
//
// 連結成分の個数を求めるという視点が足りていなかった
// 連結成分をどのように管理するかの問題
//
// DFSでO(N + M + K) らしい

#include <bits/stdc++.h>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<bool> used;
vector<ll> connect;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

void dfs(vector<vector<ll>> &g, ll v, ll c) {
  if (used[v]) return;
  used[v] = true;
  connect[v] = c;
  for(ll next: g[v]) {
    if (used[next]) continue;
    dfs(g, next, c);
  }
}

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

  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(m), b(m), c(k), d(k);
  vector<vector<ll>> friends(n);
  vector<vector<ll>> block(n);
  used.resize(n);
  connect.resize(n, LONG_LONG_MAX);
  
  vector<ll> ans(n, 0);

  rep(i, m) {
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
    friends[a[i]].push_back(b[i]);
    friends[b[i]].push_back(a[i]);
  }
  rep(i, k) {
    cin >> c[i] >> d[i];
    --c[i];
    --d[i];
    block[c[i]].push_back(d[i]);
    block[d[i]].push_back(c[i]);
  }

  rep(i, n)  {
    dfs(friends, i, i);
  }
  map<ll, ll> mp;
  rep(i, n) {
    //cout << connect[i] << endl;
    mp[connect[i]]++;
  }

  rep(i, n) {
    //printf("i: %d, connect: %lld, friends: %lld\n", i, mp[connect[i]], ll(friends[i].size()));
    ans[i] = mp[connect[i]]-friends[i].size()-1;
    // ブロックしてるやつが同じ連結成分だったらデクリメント
    for(ll kirai: block[i]) {
      if (connect[i] == connect[kirai]) ans[i]--;
    }
  }

  rep(i,n) {
    printf("%lld%c", ans[i], i==n-1?'\n':' ');
  }
  return 0;
}


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

int main() {
	int k, n;
  	cin >> k >> n;
    vector<int> a(n);
  	for (int i=0;i<n;i++) cin >> a[i];
  	vector<int> b(n);
  //
  	for (int i=0;i<n;i++) {
      if (i == n-1) b[i] = k + a[0] - a[n-1];
      else b[i] = abs(a[i] - a[i+1]);
      //cout << b[i] << endl;
    }
  //
  	int total = 0;
  	int maxV = 0;
  	for (int i=0;i<n;i++) {
      total += b[i];
      maxV = max(maxV, b[i]);
    }
  	cout << total - maxV << endl;
  	
}

Measured memory_bytes: 1792
n, m, c=map(int,input().split())
b = [int(i) for i in input().split()]
a = []
for _ in range(n):
    a.append([int(i) for i in input().split()])
    
k = 0
for i in range(n):
    ans = c
    for j in range(m):
        ans += a[i][j] * b[j]
    if ans > 0:
        k += 1
print(k)

Measured memory_bytes: 3060