akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >>n;
  int d[n];
  for(int i=0;i<n;i++)
    cin >>d[i];
  int x,y;
  long long int sum=0;
  for(int i=0;i<n;i++)
  {
      for(int j=i+1;j<n;j++)
      sum+=d[i]*d[j];
  }
  cout <<sum<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define debug(x) cerr << "\n" \
                      << #x << ": " << x << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(x) (x).begin(), (x).end()
#define INF 1e9
#define pii pair<int, int>
#define pt(xx) cout << "\n" \
                    << xx << "\n"
#define debugv(x)               \
    cout << "\n"                   \
         << #x << ": ";            \
    rep(i, x.size()) cout << x[i] << " "; \
    cout << endl
#define debug2d(x)            \
    cout << "\n"                    \
         << #x << " is: \n";        \
    rep(i,x.size())     \
    {                               \
        rep(j,x[0].size()) \
        {                           \
            cout << x[i][j] << " "; \
        }                           \
        cout << endl;               \
    }
#define nl cout << endl

#define MOD 1000000007
using namespace std;

int N, M, K;
int Q;
int ans = 0;

signed main()
{

    cin>>N;
    vector<int> d(N);
    rep(i,N)cin>>d[i];


    sort(all(d));


    vector<int> r(100001);
    // med
    // n: ぐうすう

    int med = d[N/2 - 1];
    int medi = N/2 - 1;


    if (d[medi+1] != d[medi]){
    ans = d[medi+1] - d[medi];
    }
    else ans = 0;

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int count = 0;
    for(int i = a; i <= b; i++) {
      if(c % i == 0) {
        count++;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 26340
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1000000000;

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

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
 	int n,a;
 	cin>>n;
 	vector<pair<int,int>>v;
	for(int i=0;i<n;++i){
	 	cin >> a;
	 	v.push_back(make_pair(a,i+1));
 	}
 	sort(v.begin(),v.end());
 	for(int i=0;i<n;++i){
 	 	cout<<v[i].second<< " ";
 	}
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

ll get(ll x){
	ll ans=0;
	fore(i,1,60) if(x>=i) ans++,x-=i;
	return ans;
}

int main(){FIN;
	ll n; cin>>n;
	map<ll,int> mp;
	for(ll i=2;i*i<=n;i++){
		while(n%i==0) mp[i]++,n/=i;
	}
	if(n>1) mp[n]++;
	ll ans=0;
	for(auto x:mp) ans+=get(x.snd);
	cout<<ans<<"\n";
}

Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(ll i = (ll)(n)-1;i >= 0;--i)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
signed main(){
  cioacc();
  string s,t;
  cin >> s >> t;
  ll ssz = (ll)s.size(),tsz = (ll)t.size();
  vector<vector<string>> dp(ssz+1,vector<string>(tsz+1));
  vector<string> last(tsz+1);
  REP(i,ssz){
    vector<string> now(tsz+1);
    REP(j,tsz){
      if(s[i]==t[j]) {
        now[j+1] = last[j] + s[i];
        continue;
      }
      now[j+1] = (now[j].size()>=last[j+1].size()?now[j]:last[j+1]);
    }
    last.swap(now);
  }
  cout << last[tsz] << endl;
}


Measured memory_bytes: 87280
#include<bits/stdc++.h>
using namespace std;
char n[109];
int k,dp[109][5],limit[109][5];
int main() {
	scanf("%s%d",n,&k);
	int len=strlen(n);
	dp[0][0]=1;
	dp[0][1]=n[0]-'0';
	limit[0][1]=n[0]=='0'?0:1;
	limit[0][0]=n[0]=='0'?1:0;
	for(int i=0;i+1<len;i++)
		for(int j=0;j<=min(k,i+1);j++) {
			dp[i+1][j]+=dp[i][j];
			dp[i+1][j+1]+=dp[i][j]*9-limit[i][j]*(9-n[i+1]+'0');
			limit[i+1][j]+=(n[i+1]=='0'?limit[i][j]:0);
			limit[i+1][j+1]+=(n[i+1]=='0'?0:limit[i][j]);
		}
	printf("%d\n",dp[len-1][k]);
	return 0;
}

Measured memory_bytes: 256
p = [[0 for i in xrange(10)] for i in xrange(10)]

def drop(x, y, s):
    d = [[x, y - 1], [x - 1, y], [x + 1, y], [x, y + 1], \
         [x - 1, y + 1], [x + 1, y + 1], [x - 1, y - 1], [x + 1, y - 1], \
         [x, y + 2], [x - 2, y], [x + 2, y], [x, y - 2]]
    for i in d[0:s*4]:
        if min(i) >= 0 and max(i) < 10: p[i[0]][i[1]] += 1
    p[x][y] += 1

while 1:
    try:
        x, y, s = map(int, raw_input().split(','))
        drop(x, y, s)
    except:
        break

print sum([i.count(0) for i in p])
print max([max(i) for i in p])

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	cin >> N;
	cout << (int)pow((int)sqrt(N), 2) << endl;

	return 0;
}

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

class Program {
    static void Main(string[] args) {
        string S, T;
        int N;
        Input(out N);
        Input(out S, out T);
        char[] R = new char[2 * N];
        for(int i = 0; i < 2 * N; i++) {
            if(i % 2 == 0) {
                R[i] = S[i / 2];
            } else {
                R[i] = T[i / 2];
            }
        }
        Console.WriteLine(R);
    }
    static T ChangeT<T>(string s) => (T)Convert.ChangeType(s, typeof(T));
    static void Input<A>(out A a) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
    }
    static void Input<A, B>(out A a, out B b) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
    }
    static void Input<A, B, C>(out A a, out B b, out C c) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
    }
    static void Input<A, B, C, D>(out A a, out B b, out C c, out D d) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
    }
    static void Input<A, B, C, D, E>(out A a, out B b, out C c, out D d, out E e) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
    }
    static void Input<A, B, C, D, E, F>(out A a, out B b, out C c, out D d, out E e, out F f) {
        var words = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries);
        a = ChangeT<A>(words[0]);
        b = ChangeT<B>(words[1]);
        c = ChangeT<C>(words[2]);
        d = ChangeT<D>(words[3]);
        e = ChangeT<E>(words[4]);
        f = ChangeT<F>(words[5]);
    }
    static void InputArray<T>(out T[] array) {
        array = Console.ReadLine().Split(new[] { ' ' }, options: StringSplitOptions.RemoveEmptyEntries).Select(s => ChangeT<T>(s)).ToArray();
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

void cp()
{
    int d, t, s;
    cin >> d >> t >> s;
    if(s * t < d)
        cout << "No";
    else
        cout << "Yes";
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 3648
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    vector<int>a(3);
    for(int i=0;i<3;i++)cin>>a[i];
    sort(all(a));
    int ans=0;
    while(a[1]<a[2]){
        ans++;
        a[1]++;
        a[0]++;
    }
    while(a[0]<a[1]){
        ans++;
        a[0]+=2;
    }
    if(a[0]>a[1])
        ans++;
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
//qiita参考　https://qiita.com/drken/items/fd4e5e3630d0f5859067
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

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

  reverse(S.begin(), S.end());
  for(int i = 0; i < 4; i++)reverse(divide[i].begin(), divide[i].end());

  bool can = true;
  for (int i = 0; i < S.size();){
    bool can2 = false;
    for(int j = 0; j < 4; j++){
      string d = divide[j];
      if (S.substr(i, d.size()) == d){
        can2 = true;
        i += d.size();
      }
    }
    if(!can2){
      can = false;
      break;
    }
  }

  if(can) cout<<"YES"<<endl;
  else cout <<"NO"<<endl;

}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define int int64_t
#define pr(x) cout << x << endl;
#define vi vector<int>
#define vii vector< int , vector<int> >
#define mp make_pair
#define f(i,n) for(i =0 ; i< n ; i++)
#define pb push_back
#define INF 1e9
#define SIZE 200001
#define mod 1000000007
#define int int64_t
void solve();
// class dsu
// {
//     vi rank,parents;
// public:
//     dsu(int n)
//     {
//         rank.assign(n+10,0);
//         parents.assign(n+10,0);
//         for(int i=0;i<=n;i++)
//         {
//             parents[i]=i;
//         }
//     }
//     int findparent(int a)
//     {
//         return parents[a]==a ? a : parents[a]=findparent(parents[a]);
//     }
//     bool isSameParent(int x,int y)
//     {
//         return findparent(x)==findparent(y);
//     }
//     void joindsu(int x,int y)
//     {
//         int a=findparent(x);
//         int b=findparent(y);
//         if(a!=b)
//         {
//             if(rank[a]>rank[b])
//             {
//                 parents[b]=a;
//             }
//             else
//             {
//                 parents[a]=b;
//                 if(rank[a]==rank[b])
//                     rank[b]++;
//             }
//         }
//     }
// };


int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    solve();
    return 0;
}
int32_t  k=0, l=0, i, j, n, m, a, t=0, b, w ;
void solve()
{
    // cin >> t;while(t--)
    {
        cin >> n >> m >> k;
        m = n-m;
        k -= m;
        if(k>=0)
        pr(k)

        else pr(0)
    }
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
count4=0#4の倍数
count2=0#2の倍数だが4の倍数じゃない
count1=0
for i in range(n):
    if a[i]%4==0:
        count4+=1
    elif a[i]%2==0:
        count2+=1
    else:
        count1+=1
if count2==0:
    if count1<=count4+1:
        print("Yes")
    else:
        print("No")
else:
    if count1<=count4:
        print("Yes")
    else:
        print("No")

    

    
"""
#print(count2)
if 1<=count2:
    if (n-count2//2)//2<=count or n//2<=count:
        print("Yes")
    elif count2%2==0:
        if   (n-count2)//2<count :
            print("Yes ")
        else:
            print("No")
    elif count2%2==1:
        if  (n-count2)//2<=count :
            print("Yes ")
        else:
            print("No")
else:
    if n//2<=count:
        print("Yes")
    else:
        print("No")

    """
"""    7
    2 2 2 2 3 4 3

    YES になる間違い13晩のテキスト

"""

Measured memory_bytes: 14252
#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()

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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll charToBit(char c) {return 1<<(c-'a');}

class SegmentTree {
    int _sz;
    vector<ll> v;
    ll near_pow(ll sz) {
        ll k = 1;
        while(sz>k) k*=2;
        return k;
    }

public:
    SegmentTree(int sz) {
        _sz = near_pow(sz);
        v.resize((2*_sz)-1,0);
        string s; cin >> s;
        REP(i,sz) v[_sz-1+i] = charToBit(s[i]);
        FOR(i,sz,_sz) v[_sz-1+i] = v[_sz+sz-2]; //残りを最後の要素で埋める
        // 葉以外の要素を求める。
        REPR(i,_sz-2) v[i] = v[(2*i)+1] | v[(2*i)+2];

    }
    string lltoStr(ll k) {
        string s;
        REP(i,26) if((1<<i) & k) s.push_back((char)i+'a');
        return s;
    }
    void print() {
        REP(i,v.size()) cerr << i << ": " << lltoStr(v[i]) << endl;
    }
    void update(int key,ll val) {
        // 最下位のノードにアクセス
        key += _sz-1;
        // 最下位のノードを更新
        v[key] = val;
        // 上位ノードの更新
        while(key > 0) {
            key = (key-1)/2;
            v[key] = v[(2*key)+1] | v[(2*key)+2];
        }
    }
    // 区間[a,b)の要素数を求める。 [l,r)は自分の今いるノードの区間、kは自分の今いるノードのインデックス。
    ll get(int a,int b,int l = 0,int r = -1,int k = 0) {
        // 初期化処理 最初は[l,r) = [0,N)
        if (r<0) r = _sz;

        // if(a==b) return v[_sz-1+a];

        // 欲しい区間と今いるノードの区間が交わらないなら答えに影響のない値を適当に返す
        if ( l >= b || r<= a ) return 0;

        //今いるノードの区間が全て欲しい区間の中だったらそれを答えに使う
        if ( a <= l && r <=  b) return v[k];

        // 今いるノードの区間の一部が欲しい場合は探索を進める。
        // 自分の今いるノードの区間を半分に分けて探索する。
        ll vl = get(a,b,l,(l+r)/2,2*k+1);
        ll vr = get(a,b,(l+r)/2,r,2*k+2);

        return vl | vr;
    }

};
ll count(ll k) {
    int cnt = 0;
    REP(i,26) if((1<<i) & k) cnt++;
    return cnt;
}
void solve() {
    int N;
    cin >> N;
    SegmentTree s(N);
    int Q;
    cin >> Q;
    REP(_,Q) {
        int typ;
        cin >> typ;
        if(typ == 1) {
            int i; char c;
            cin >> i >> c;
            s.update(i-1,charToBit(c));
        }
        if (typ == 2) {
            int l,r;
            cin >> l >> r;
            cout << count(s.get(l-1,r)) << endl;
        }
    }

}

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


Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=8010;
const int STALA=8002;
bitset<MAX*2>dpx[MAX];
bitset<MAX*2>dpy[MAX];
string s;
vi noms;
int32_t main()
{
  BOOST;
  int dir=0;
  int lx=0,ly=0;
  dpx[0][STALA]=true;
  dpy[0][STALA]=true;
  cin>>s;
  for (int i=0;i<sz(s);){
  	int j=i;
  	int licznik=0;
  	while (s[j]=='F')j++,licznik++;
  	i=max(i+1,j);
  	if (licznik)noms.pb(licznik);
  	else noms.pb(-1);
  }
  for (auto it:noms){
  	if(it==-1){
  		dir++;
  	} 
  	else{
  		if (dir==0){
  			lx++;
  		  for (int j=2*STALA;j>=0;j--){
  		  	if (dpx[lx-1][j])dpx[lx][j+it]=true;
  		  }
  		}
  		else if (dir%2==0){
  			lx++;
  		//	cout<<"TERAZ "<<it<<"\n";
  			for (int j=2*STALA;j>=0;j--){
  		  	if (dpx[lx-1][j] && j+it<=2*STALA)dpx[lx][j+it]=true;
  		  }
  		  
  		  for (int j=1;j<=STALA*2;j++){
  		  	if (dpx[lx-1][j] && j-it>=0)dpx[lx][j-it]=true;
  		  }
  		}
  		else{
  			ly++;
  			for (int j=2*STALA;j>=0;j--){
  		  	if (dpy[ly-1][j] && j+it<=2*STALA)dpy[ly][j+it]=true;
  		  }
  		  
  		  for (int j=1;j<=STALA*2;j++){
  		  	if (dpy[ly-1][j] && j-it>=0)dpy[ly][j-it]=true;
  		  }
  		}
  	}
  }
  int x,y;
  cin>>x>>y;
  if (dpx[lx][STALA+x] && dpy[ly][STALA+y])cout<<"Yes";
  else cout<<"No";
  return 0;
}

Measured memory_bytes: 11456
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()
ans = 1
r = 0
g = 0
b = 0

for x in a:
    ans = ans * ( (r == x) + (g == x) + (b == x) ) % (10**9+7)
    if r == x:
        r += 1
    elif g == x:
        g += 1
    else:
        b += 1
print(ans)

Measured memory_bytes: 22300
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		String s = sc.next();
		ou.print(s);
		if(s.charAt(s.length() - 1) == 's') ou.println("es");
		else ou.println("s");
		ou.flush();
	}
}

Measured memory_bytes: 35660
#include<iostream>
using namespace std;
#define max 10000
#define nil -1

struct node {
	int p = nil, l = -1, r = -1;
};
node a[max];
int n;

void preparse(int u) {
	if (u == nil) return;
	cout << " " << u;
	preparse(a[u].l);
	preparse(a[u].r);
}

void inparse(int u) {
	if (u == nil) return;
	inparse(a[u].l);
	cout << " " << u;
	inparse(a[u].r);
}

void postparse(int u) {
	if (u == nil) return;
	postparse(a[u].l);
	postparse(a[u].r);
	cout << " " << u;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		cin >> a[x].l;
		cin >> a[x].r;
		if (a[x].l != nil) a[a[x].l].p = x;
		if (a[x].r != nil) a[a[x].r].p = x;
	}

	int root = 0;

	for (int i = 0; i < n; i++) {
		if (a[i].p == nil) root = i;
	}

	cout << "Preorder\n";
	preparse(root);
	cout << endl;
	cout << "Inorder\n";
	inparse(root);
	cout << endl;
	cout << "Postorder\n";
	postparse(root);
	cout << endl;

	return 0;
}


Measured memory_bytes: 3192
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define PB push_back
constexpr int kN = int(1E5 + 10);
vector<int> ori[kN], ned[kN];
int p[kN], a[kN];
int Find(int n) {return p[n] == n ? n : p[n] = Find(p[n]);}
void merge(int l, int r) {
	p[Find(r)] = Find(l);
	return ;
}
int main() {
	int n, head;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) ori[a[i]].PB(i);
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) ned[a[i]].PB(i);
	for (int i = 1; i < kN; i++) p[i] = i;
	for (int i = 2; i < kN; i++) {
		head = 0;
		for (int j = i; j < kN; j += i) if (!ori[j].empty()) {
			if (head == 0) head = j;
			else merge(head, j);
		}
	}
	for (int i = 1; i < kN; i++) if (p[i] != i) {
		for (int j : ori[i]) ori[Find(i)].PB(j);
		for (int j : ned[i]) ned[Find(i)].PB(j);
	}
	for (int i = 1; i < kN; i++) if (p[i] == i) {
		sort(ori[i].begin(), ori[i].end());
		sort(ned[i].begin(), ned[i].end());
		if (ori[i] != ned[i]) {
			printf("0\n");
			return 0;
		}
	}
	printf("1\n");
}



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

using namespace std;
using ll = long long;
using ld = long double;

int main()
{
    int n, k;
    cin >> n >> k;
    ld res = 0;

    for(int i = 1; i <= n; i++) {
        int j, t = i;
        for(j = 0; t < k; t *= 2, j++);
        ld cur = 1.0/(1<<j);
        res += cur * ((ld)1/n);
    }
    cout << fixed <<setprecision(12) << res << endl; 
}

Measured memory_bytes: 3728
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long k = sc.nextLong();
        long d = sc.nextLong();
        long m = Math.abs(x) / d;
        long res = Math.abs(x) - m * d;
        if (m > k) {
            res += (m - k) * d;
        } else {
            if ((k - m) % 2 != 0) {
                res -= d;
            }
        }
        System.out.println(Math.abs(res));
        sc.close();
    }
}

Measured memory_bytes: 35736
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

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

    ll x, y;
    cin >> x >> y;
    if (abs(x-y) <= 1)
        cout << "Brown";
    else
        cout << "Alice";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, m;
	int i;
	int map[1024];
	int d;
	int pos;
	int ret;

	while (scanf("%d %d", &n, &m), n){
		for (i = 0; i < n; i++){
			scanf("%d", map + i);
		}

		pos = 0;
		ret = m + 1;
		for (i = 0; i < m; i++){
			scanf("%d", &d);
			pos = fmin(pos + d, n - 1);
			pos = fmin(pos + map[pos], n - 1);
			if (pos == n - 1) ret = fmin(ret, i + 1);
		}

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

	return (0);
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
bool LTE(double a,double b) { return equals(a,b) || a < b; }
bool LT(double a,double b) { return !equals(a,b) && a < b; }

#define MAX 100010

int N,M;
int p[MAX], par[MAX];

int find(int x) {
  if( x == par[x] ) return x;
  return par[x] = find(par[x]);
}

void unit(int x,int y) {
  x = find(x), y = find(y);
  if( x != y ) par[x] = y;
}

void compute() {

}

int main() {
  cin >> N >> M;
  rep(i,N) {
    cin >> p[i];
    --p[i];
  }
  rep(i,N) par[i] = i;
  int x,y;
  rep(i,M) {
    cin >> x >> y;
    --x, --y;
    unit(x,y);
  }
  map<int,set<int>> mp;
  rep(i,N) {
    mp[find(p[i])].insert(p[i]);
  }
  int cnt = 0;
  rep(i,N) {
    if( mp[find(p[i])].count(i) ) ++cnt;
  }
  cout << cnt << endl;
  compute();
  return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define mod 998244353
#define pb push_back
ll power(ll a,ll b){
    ll res=1ll;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<ll> prime;
void seive(){
    vector<bool > isprime(2000001,true);
    for(int i=2;i*i<=2000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=2000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
void swap(ll *a,ll *b) {
    ll temp=*a;
    *a=*b;
    *b=temp;
}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    ld l;
    cin>>l;
    ld x=l/3.0;
    ld vol=x*x*x;
    cout<<setprecision(16)<<vol;
    return 0; 
}


Measured memory_bytes: 256
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

int n;
ll a,b,x[100010];
ll ret;

int main(){
    I(n);
    LL(a);
    LL(b);
    REP(i,n) LL(x[i]);

    REP(i,n-1){
        ret += min(b,(x[i+1]-x[i])*a);
    }
    cout << ret << endl;
}


Measured memory_bytes: 1024
N = int(input())
for h in range(max(1, N//4), 3501):
    if 4*h - N > 0:
        for n in range(max(1, N * h // (4*h-N)), 3501):
            if 4*h*n - (h+n)*N > 0 and h*n*N % (4*h*n - (h+n)*N) == 0:
                print(h, n, h*n*N // (4*h*n - (h+n)*N))
                exit()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<stdio.h>
#include<cstdlib>
#include<queue>
#include<algorithm>
#include<cmath>
#include<vector>
#include<list>
#include<string>
#include<stack>
#include<cstring>
#include<set>
#include<map>
#include<climits>
#include<cassert>

using namespace std;

//--------------------------------------------------------------//

int main() {
	stack <int> S;
	int a, b;
	string s;

	while (cin >> s) {
		if (s[0] == '+') {
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(a + b);
		}
		else if(s[0] == '-') {
			b = S.top(); S.pop();
			a = S.top(); S.pop();
			S.push(a - b);
		}
		else if (s[0] == '*') {
			a = S.top(); S.pop();
			b = S.top(); S.pop();
			S.push(a*b);
		}
		else {
			S.push(atoi(s.c_str()));
		}
	}
	cout << S.top() << endl;
	return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }

    ll ans = 0;
    ll now = 0;
    rep(loop, n) {
        now = a[now];
        ans++;
        if(now == 1) {
            out(ans);
            re0;
        }
    }

    out(-1);
    re0;
}

Measured memory_bytes: 1024
n=gets.to_i
arr=[]
s=0
ans = 0
a = gets.chomp.split(" ").map!(&:to_i)
b = gets.chomp.split(" ").map!(&:to_i)
i=0
b.each do |v|
  if v>a[i]
    s+=v-a[i]
    ans+=1
  else
    arr.push(a[i]-v)
  end
  i+=1
end
arr.sort!.reverse!
arr.each do |v|
  break if s<=0
  s-=v
  ans+=1
end
if s<=0
  puts ans
else
  puts -1
end


Measured memory_bytes: 16536
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2,tune=native")

#include <x86intrin.h>
#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int cnt[N] = {0};
    for (int i = 1; i < N; i++) cnt[i] = cnt[i - 1] + (S.substr(i - 1, 2) == "AC" ? 1 : 0);
    int l, r;
    while (Q--) {
	cin >> l >> r;
	cout << cnt[r - 1] - cnt[l - 1] << '\n';
    }
    return 0;
}

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

const static int YEAR = 2019;

int main(void){
    std::string s;
    std::cin >> s;
    std::reverse(s.begin(), s.end());

    std::vector<int> cnt(3000);
    int tot = 0;
    int keta = 1;
    int ans = 0;

    for(int i = 0; i < s.size(); i++){
	cnt[tot]++;
	tot += (s[i] - '0') * keta;
	tot = tot % YEAR;
	// std::cout << tot << std::endl;
	ans += cnt[tot];
	keta = keta * 10 % YEAR;
    }
    std::cout << ans << std::endl;
    return 0;
}



Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	cout << char(a.at(0) + ('A' - 'a')) << char(b.at(0) + ('A' - 'a'))<< char(c.at(0) + ('A' - 'a'))<<endl;
} 

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()

int main() {
    int N;
    cin >> N;
    vector<int> W(N);
    REP(i, N) {
        cin >> W[i];
    }
    int l = 0;
    int h = accumulate(ALL(W), 0);
    int res = h;
    REP(i, N) {
        l += W[i];
        h -= W[i];
        res = min(res, abs(h - l));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //Where were you during the damn contest!!!!!!!!!!!
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int H = I.nextInt();
		int W = I.nextInt();
		int N = I.nextInt();
		int max = Math.max(H,W);
		O.pln(ceil(N,max));
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
	}
}


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

int main(void) {
    int N, M;
    cin >> N >> M;

    map<int, bool> obser;
    for (int i = 1; i <= N; i++)
        obser[i] = true;

    vector<int> H(N + 1);
    for (int i = 1; i <= N; i++)
        cin >> H.at(i);

    vector<P> route(M);
    for (int i = 0; i < M; i++)
        cin >> route.at(i).first >> route.at(i).second;

    // for (int i = 0; i < M; i++)
    //     cout << route.at(i).first << ' ' << route.at(i).second << endl;

    for (int i = 0; i < M; i++) {
        if (H.at(route.at(i).first) < H.at(route.at(i).second))
            obser.at(route.at(i).first) = false;
        else if  (H.at(route.at(i).first) > H.at(route.at(i).second))
            obser.at(route.at(i).second) = false;
        else {
            obser.at(route.at(i).first) = false;
            obser.at(route.at(i).second) = false;
        }
    }

    int count = 0;
    for (int i = 1; i <= N; i++)
        if (obser.at(i) == true)
            count++;

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 9048
#include <bits/stdc++.h>
using namespace std;
int main () {
  string A, B;
  cin >> A >> B;
  int count = 0;
  for(int i = 0; i < 3; i++){
    if(A.at(i) == B.at(i))count++;
  }
  cout << count << endl;
  return 0;
}

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

int main() {
  long long N, K;
  cin >> N >> K;
  N=N%K;
  while(N>abs(N-K)){
    N=abs(N-K);
  }
  cout << N;
}

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

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

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n; cin >> n;
  ll ans = 0;
  rep(i, n) {
    ans += ((i) * ((i%3!=0) && (i%5!=0)));
  }
  cout << ans;
}


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

int H,W;
string maze[2005];
vector<vector<int>> Up;
vector<vector<int>> Right;
vector<vector<int>> Down;
vector<vector<int>> Left;

void R(){
    for(int i=0;i<H;++i){
        int cur=0;
        for(int j=0;j<W;++j){
            if(maze[i][j]=='#') cur=0;
            else Right[i][j]=++cur;
        }
    }
}

void L(){
    for(int i=0;i<H;++i){
        int cur=0;
        for(int j=W-1;j>=0;--j){
            if(maze[i][j]=='#') cur=0;
            else Left[i][j]=++cur;
        }
    }
}

void D(){
    for(int j=0;j<W;++j){
        int cur=0;
        for(int i=0;i<H;++i){
            if(maze[i][j]=='#') cur=0;
            else Down[i][j]=++cur;
        }
    }
}

void U(){
    for(int j=0;j<W;++j){
        int cur=0;
        for(int i=H-1;i>=0;--i){
            if(maze[i][j]=='#') cur=0;
            else Up[i][j]=++cur;
        }
    }
}

int main(){
    cin>>H>>W;
    Up.assign(H,vector<int>(W,0));
    Down.assign(H,vector<int>(W,0));
    Right.assign(H,vector<int>(W,0));
    Left.assign(H,vector<int>(W,0));
    for(int i=0;i<H;++i) cin>>maze[i];

    U(); D(); R(); L();
    int ans=0;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            int t=Up[i][j]+Right[i][j]+Down[i][j]+Left[i][j]-3;
            ans=ans<t?t:ans;
        }
    }

    cout<<ans<<endl;
}

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

int main(){
  ll h,n,a,sum=0;
  cin >> h >> n;
  r(i,n){
    cin >>a;
    sum+=a;
  }
  if(sum>=h)cout<<"Yes"<<endl;
  else cout<< "No"<<endl;
}

Measured memory_bytes: 256
// Author : Chi
// created : Thursday 2020-06-04
// Sawal : Practice

//header files
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

//namespaces
using    namespace __gnu_pbds;
using    namespace std;
typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;

//macros
#define ll 		    long long
#define ss          second
#define ff          first
#define vi          vector<int>
#define vll         vector<long long>
#define pb(x)       push_back(x)
#define TEST  	    int TesT;cin>>TesT;while(TesT--)solve();
#define TEST1       solve();
#define mod         1000000007
#define aLL(x)      x.begin(),x.end()
#define r0n(i,n)    for(ll i = 0; i < n; ++i)
#define r1n(i,n)    for(ll i = 1; i <= n; ++i)
#define pdp(d,i)    fixed<<setprecision(i)<<d
#define CHI         ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define db(...)     __f(#__VA_ARGS__, __VA_ARGS__)                      //for debugging
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
//LOVE ALGO
int a[401][401];
int dp[21][1<<22];
int n;
int rec(int r,int w){
    if(r==n)
        return 1;
    if(dp[r][w]!=-1)
        return dp[r][w];
    int ans=0;
    for(int i=0;i<n;i++)
        if(((1<<i)&w) == 0&&a[r][i]==1)
            ans=(ans+rec(r+1,w|(1<<i)))%mod;
    return dp[r][w]=ans;
}
void solve(){
    cin>>n;
    memset(dp,-1,sizeof dp);
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
            cin>>a[i][j];
    cout<<rec(0,0);
    }
// Driver Code
int main(){
    CHI
    TEST1
    return 0;
}


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

using namespace std;

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

int N, M;
vector<int> vs;
string S;
string::const_iterator iter;

map<int, int> merge(map<int, int>& a, map<int, int>& b) {
  map<int, int> ret;
  rep(i, 0b10000) rep(j, 0b10000) {
    ret[i&j] += a[i] * b[j];
    ret[i|j] += a[i] * b[j];
    ret[i^j] += a[i] * b[j];
  }
  return ret;
}

map<int, int> dfs() {
  if(*iter == '(') {
    iter ++;
    auto l = dfs();
    iter ++;
    auto r = dfs();
    iter ++;
    return merge(l, r);
  }
  else {
    int a = *iter - '0'; a--;
    iter ++;
    return {{vs[a], 1}};
  }
}

int main() {

  while(1) {
    getline(cin, S);
    if(S == "END") break;
    N = S.size();
    cin >> M;
    vs.clear();
    rep(i, M) {
      int a, b, c, d; cin >> a >> b >> c >> d;
      vs.push_back(a * 8 + b * 4 + c * 2 + d);
    }
    
    iter = S.begin();
    auto s = dfs();
    
    cout << s[0b1111] << endl;
    cin.ignore();
  }
  
  return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<float.h>
using namespace std;


int main() {
    int a;
    cin >> a;
    if (a < 1200)cout << "ABC" << endl;
    else if (a < 2800)cout << "ARC" << endl;
    else cout << "AGC" << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 10000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
typedef pair<P, int> PI;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<IP, vector<IP>, greater<IP> > pvqueue;

#define N 103
#define M 10003

int n, m;
int dist[N][3];
vector<P> g[N];

int solve() {
  pvqueue que;
  rep(i, n) rep(j, 3) dist[i][j] = INF;
  dist[0][0] = 0;
  que.push(IP(0, P(0, 0)));
  while(!que.empty()) {
    IP p = que.top(); que.pop();
    int cost = p.first, v = p.second.first, s = p.second.second;
    if(dist[v][s] < cost) continue;
    rep(j, g[v].size()) {
      P &e = g[v][j];
      int to = e.first, c = e.second;
      if(s == 1) {
        if(dist[v][s] < dist[to][s+1]) {
          dist[to][s+1] = dist[v][s];
          que.push(IP(dist[to][s+1], P(to, s+1)));
        }
      } else {
        if(dist[v][s] + c < dist[to][s]) {
          dist[to][s] = dist[v][s] + c;
          que.push(IP(dist[to][s], P(to, s)));
        }
        if(s == 0 && dist[v][s] < dist[to][s+1]) {
          dist[to][s+1] = dist[v][s];
          que.push(IP(dist[to][s+1], P(to, s+1)));
        }
      }
    }
  }
  return mind(dist[n-1][0], dist[n-1][2]);
}

int main() {
  while(cin >> n >> m && n+m) {
    rep(i, n) g[i].clear();
    rep(i, m) {
      int a, b, c;
      cin >> a >> b >> c; --a; --b;
      g[a].push_back(P(b, c));
      g[b].push_back(P(a, c));
    }
    cout << solve() << endl;
  }
  return 0;
}

Measured memory_bytes: 1216
import math
import os
import sys
from collections import Counter, defaultdict

from fractions import gcd
from functools import reduce

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

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


# MOD = 998244353


def get_factors(n):
    """
    素因数分解
    :param int n:
    :rtype: list of int
    """
    if n <= 1:
        return []

    ret = []
    while n > 2 and n % 2 == 0:
        ret.append(2)
        n //= 2
    i = 3
    while i <= math.sqrt(n):
        if n % i == 0:
            ret.append(i)
            n //= i
        else:
            i += 2
    ret.append(n)
    return ret


def mod_invs(max, mod):
    """
    逆元 0, 1/1, 1/2, 1/3, ..., 1/max
    :param int max:
    :param int mod:
    """
    invs = [1] * (max + 1)
    invs[0] = 0
    for x in range(2, max + 1):
        invs[x] = (-(mod // x) * invs[mod % x]) % mod
    return invs


N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

# 最小公倍数
max_counts = defaultdict(int)
for a in A:
    counts = Counter(get_factors(a))
    for k, cnt in counts.items():
        max_counts[k] = max(max_counts[k], cnt)

lcm = 1
for k, v in max_counts.items():
    lcm *= pow(k, v, MOD)
    lcm %= MOD

invs = mod_invs(max(A), MOD)
ans = 0
for a in A:
    ans += lcm * invs[a]
    ans %= MOD
print(ans)


Measured memory_bytes: 85460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

long long A;
long long N;
long long B;
vector<long long> h(100001);

// c回の爆発で全員倒せなければtrue
bool C1(long long c) {
	ll res = 0;
	rep(i, N) {
		ll r = h[i]-B*c;
		if (r > 0) res += (r+(A-B-1))/(A-B);
	}
	return res > c;
}

int main(){	
	scanf("%lld",&N);
	scanf("%lld",&A);
	scanf("%lld",&B);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&h[i]);
	}

	long long lb = 0, ub = 0;
	rep(i, N) {
		ub += (h[i]+B-1)/B;
	}
	++ub;
	while (ub - lb > 1) {
		long long mid = (lb + ub) / 2;
		if (C1(mid)) lb = mid;
		else ub = mid;
	}
	cout << ub << endl;
	return 0;
}



Measured memory_bytes: 1024
#include <cstdio>
#include <vector>
#include <algorithm>

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

  std::vector<int> r(R);
  for (int i=0; i<R; ++i) {
    scanf("%d", &r[i]);
    --r[i];
  }

  int g[201][201]={};

  for (int i=0; i<=200; ++i)
    for (int j=0; j<=200; ++j)
      g[i][j] = 1e9;

  for (int i=0; i<M; ++i) {
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    --A, --B;

    g[A][B] = g[B][A] = C;
  }

  for (int k=0; k<N; ++k)
    for (int i=0; i<N; ++i)
      for (int j=0; j<N; ++j)
        g[i][j] = std::min(g[i][j], g[i][k]+g[k][j]);

  int res=1e9;

  std::sort(r.begin(), r.end());
  do {
    int cur=0;
    for (int i=1; i<R; ++i)
      cur += g[r[i-1]][r[i]];

    if (res > cur)
      res = cur;
  } while (std::next_permutation(r.begin(), r.end()));

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


Measured memory_bytes: 384