akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) > (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin >> n;
    string tmps;
    map<char, int> result,tmpmp;
    for (char c = 'a'; c <= 'z';c++){
        result[c] = 0;
    }
        cin >> tmps;
    for(char &s:tmps){
        result[s]++;
    }
    FOR(i,1,n){
        cin >> tmps;
        for (char c = 'a'; c <= 'z';c++){
            tmpmp[c] = 0;
        }
        for(char &s:tmps){
            tmpmp[s]++;
        }
        for (char c = 'a'; c <= 'z';c++){
            result[c] = min(result[c],tmpmp[c]);
        }
    }
    for (char c = 'a'; c <= 'z';c++){
        REP(i,result[c]){
            printf("%c", c);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <cstdlib>
using namespace std;
int h, w; 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

int bfs(const vector<vector<char>>& v){
    queue<pair<pair<int, int>, int>> q;
    q.push(make_pair(make_pair(0, 0), 0));
    vector<vector<bool>> visited(w, vector<bool>(h, false));
    visited[0][0] = true;

    while(!q.empty()){
        int x = q.front().first.first;
        int y = q.front().first.second;
        int d = q.front().second;
        q.pop();

        if(x == w - 1 && y == h - 1) return d;
        
        for(int i = 0; i < 4; ++i){
            if(x+dx[i] < 0 || x+dx[i]>=w) continue;
            if(y+dy[i] < 0 || y+dy[i]>=h) continue;
            if(visited[x+dx[i]][y+dy[i]]) continue;
            if(v[x+dx[i]][y+dy[i]] == '#') continue;
            visited[x+dx[i]][y+dy[i]] = true;
            q.push(make_pair(make_pair(x+dx[i], y+dy[i]), d+1));
        }
    }

    return -1;
}

int main(){
    cin >> h >> w;
    int num_of_b = 0;
    vector<vector<char>> v(w, vector<char>(h));
    for(int y = 0; y < h; ++y){
        for(int x = 0; x < w; ++x){
            cin >> v[x][y];
            if(v[x][y] == '#') num_of_b++;
        }
    }
    
    int d = bfs(v);
//    cout << d << endl;

    if(d == -1) cout << -1 << endl;
    else cout << w * h - num_of_b - d - 1 << endl;

    return EXIT_SUCCESS;
}


Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.Char
import Data.List

import Data.Array
import Data.Array.IO


-- space delimited integers
getVals::IO [Int]
getVals = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine


main::IO()
main = do
    n:m:_ <- getVals
    (connection::IOArray Int [Int]) <- newArray (1,n) []
    forM_ [1..m] (\ _ -> do 
        a:b:_<-getVals
        ls_a <- readArray connection a 
        ls_b <- readArray connection b
        writeArray connection a  (b:ls_a)
        writeArray connection b  (a:ls_b))
    (groupIds::IOArray Int Int) <- newArray (1,n) (-1)
    let (marking::Int -> Int -> IO())  = (\ i -> \ g ->  do
        (flag::Int) <-readArray groupIds i
        when (flag == -1) $ do
            writeArray groupIds i g
            this_adj <- readArray connection i
            forM_ this_adj (\ j -> do marking j g))
    forM_ [1..n] (\ (i::Int) -> do marking i i)
    ids <- getElems groupIds 
    print $ (maximum.(map length).group.sort) ids


Measured memory_bytes: 51356
//بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيمِ
//لا إله إلا الله محمد رسول الله


    //لا إله إلا الله
//  ________
    //| الله |
    //| رسول |
    //| محمد |
//  --------

#include <bits/stdc++.h>

#pragma GCC optimize("Ofast")

#define ll long long
#define pb push_back
#define fr first
#define sc second
#define in freopen("input.txt", "r" , stdin)
#define out freopen("snakes.out", "w", stdout)
using namespace std;
ll n;
double dp[3005][3005];
double p[3005];
int main(){
    //in;
    //out;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> p[i];
    }

    dp[0][0] = 1;

    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= i; j++) {
            if (j == 0) {
                dp[i][j] = dp[i-1][j] * (1.0 - p[i]);
            }
            else dp[i][j] = dp[i-1][j] * (1.0 - p[i]) + dp[i-1][j-1] * p[i];
        }
    }

    double ans = 0;
    for (int i = n / 2 + 1; i <= n; i++) {
        ans += dp[n][i];
    }

    cout << fixed << setprecision(12)<< ans;
}




Measured memory_bytes: 69120
N, K = map(int, input().split())
p = list(map(int, input().split()))
rui = [0] * (N + 1)

for i in range(1, N + 1):
    rui[i] += rui[i - 1] + ((((p[i - 1] + 1) * p[i - 1]) // 2) / p[i - 1])

ans = rui[K]
for i in range(K, N + 1):
    ans = max(ans, rui[i] - rui[i - K])

print(ans)

Measured memory_bytes: 25060
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
bc =[list(map(int,input().split())) for i in range(m)]
bc.sort(key=lambda x:x[1],reverse=True)
now = 0
for i in range(n):
    while bc[now][1] <=a[i]:
        now += 1
        if now == m:
            break
    if now == m:
        break
    a[i] = bc[now][1]
    bc[now][0] -= 1
    if bc[now][0] == 0:
        now += 1
    if now == m:
        break

print(sum(a))

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

int main() {
    int a, b;
    cin >> a >> b;

    if (a < b) {
        cout << "a < b" << endl;
    } else if (a > b) {
        cout << "a > b" << endl;
    } else {
        cout << "a == b" << endl;
    }

    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<int>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int MOD = 1000000007;

long exp_mod(long long a, long long b, long m) {
	long long res = 1;
	while (b > 0) {
		if (b&1)
			res = (res * a)%m;
		a = (a * a)%m;
		b >>= 1;
	}
	return (long)res;
}

long fact_mod(long n, long m) {
	long long res = 1;
	for (long i=n; i>0; --i)
		res = (res * i)%m;
	return (long)res;
}

long comb_mod(long n, long r) {
	long long res = 1;
	for (long i=0; i<r; ++i)
		res = (res * (n - i) )%MOD;
	return ( res * exp_mod(fact_mod(r, MOD), MOD-2, MOD) ) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

struct Pony
{
    int x,y;

    Pony(int x_, int y_)
    {
        x = x_;
        y = y_;
    }

    bool operator<(const Pony &another) const
    {
        return x < another.x;
    };
};

long modinv(long a, long m) {
    long b = m, u = 1, v = 0;
    while (b) {
        long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

  long w, h, x, y;

  cin >> w >> h >> x >> y;

  cout << (double)(w*h)/2.0 << " " << (x*2 ==w && y*2 == h ? 1 : 0) << endl;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x <= 1) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll h;
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> h;
 	ll cur = 0,ans = 0;
	while(h){
 		if(h == 1){
 			ans += (1LL << cur);
 			break;
 		}
 		ans += (1LL << cur);
 		h /= 2;
 		cur++;
 	}
 	cout << ans << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
const int inf = 1e5;
//typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
  int n;  cin>>n;
  vector<ll> v(n);
  ll of=0;
  rep(i,0,n) cin>>v[i], v[i]*=2;
  rep(i,0,n){
    of = v[i] - of;
  }
  ll res=of/2;
  rep(i,0,n){
    cout << res << " ";
    res = v[i] - res;
  }
  cout << endl;
  return 0;
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

void solve() {
  string s, t;
  cin >> s >> t;
  vector<vector<int>> ids(26, vector<int>()), idt(26, vector<int>());
  for (int i = 0; i < s.size(); i++) { ids[s[i] - 'a'].push_back(i); }
  sort(all(ids));
  for (int i = 0; i < t.size(); i++) { idt[t[i] - 'a'].push_back(i); }
  sort(all(idt));
  for (int i = 0; i < ids.size(); i++) {
    if (ids[i] != idt[i]) {
      cout << "No" << endl;
      return;
    }
  }
  cout << "Yes" << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


Measured memory_bytes: 2964
import sys

n = int(input())
dn = list(map(int, input().split()))
m = int(input())
tn = list(map(int, input().split()))

num_dict = {}

for i in range(n):
    if str(dn[i]) in num_dict.keys():
        num_dict[str(dn[i])] += 1
    else:
        num_dict[str(dn[i])] = 1

for i in range(m):
    if str(tn[i]) in num_dict.keys():
        num_dict[str(tn[i])] += -1
    else:
        print("NO")
        sys.exit()

result_list = list(num_dict.values())
for i in range(len(result_list)):
    if result_list[i] < 0:
        print("NO")
        sys.exit()
print("YES")

Measured memory_bytes: 54412
#include<iostream>
#include<string>
#include<cctype>
#include<cstdlib>
using namespace std;

int change(char c);

int main(){
    string inp;
    int ans = 0;
    while(cin >>inp){
        int keta = 1;
        for(int i = (inp.size() - 1); i >= 0; i--){
            if(isdigit(inp[i]) != 0){
                int tmp = change(inp[i]);
                ans += (tmp * keta);
                keta *= 10;
            } else if(keta != 1){
                keta = 1;
            }
        }
    }
    cout <<ans <<endl;
    return 0;
}

int change(char c){
    return (c - '0');
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    cout << (s.find('7') == -1 ? "No" : "Yes");
    return 0;
}


Measured memory_bytes: 3612
data = list(map(int,input().split()))
a = data[0]
b = data[1]
k = data[2]
del data
result = []
for i in range(1,(a<=b)*a+(a>b)*b+1):
        if a%i == 0 and b%i == 0:
                result.append(i)
print(result[len(result)-k])

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

int main() {
  int N, L;
  cin >> N >> L;
  
  vector <string> vec(N);
  for ( int i = 0 ; i < N ; i++ ){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  for (int i = 0 ; i < N ; i++ ){
    cout << vec.at(i);
  }
}
    
  

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

const int maxn = 2e5 + 20;

int n, k, l, a, b;
int visited[2][maxn], ar[maxn];
vector<int> graph[2][maxn];
vector<vector<int>> ans[maxn];

void roadComponent(int i, int CPcnt) {
    visited[0][i] = CPcnt;
    for (int x : graph[0][i])
        if (!visited[0][x])
            roadComponent(x, CPcnt);
}
void railComponent(int i, int CPcnt) {
    visited[1][i] = CPcnt;
    if (ans[visited[0][i]].size() != 0 && ans[visited[0][i]][ans[visited[0][i]].size() - 1][0] == -CPcnt)
        ans[visited[0][i]][ans[visited[0][i]].size() - 1].push_back(i);
    else {
        vector <int> need;
        need.push_back(-CPcnt);
        need.push_back(i);
        ans[visited[0][i]].push_back(need);
    } 
    ar[i] = ans[visited[0][i]].size() -1;
    for (int x : graph[1][i])
        if(!visited[1][x])
            railComponent(x, CPcnt);
}

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

    cin >> n >> k >> l;
    for (int i = 0; i < k; i ++){
        cin >> a >> b;
        graph[0][a].push_back(b);
        graph[0][b].push_back(a);
    }
    for (int i = 0; i < l; i ++){
        cin >> a >> b;
        graph[1][a].push_back(b);
        graph[1][b].push_back(a);
    }

    int CPcnt = 1;
    for(int i = 1; i <= n;i++)
        if (!visited[0][i])
            roadComponent(i, CPcnt++);
    CPcnt = 1;
    for(int i = 1; i <= n;i++)
        if (!visited[1][i])
            railComponent(i, CPcnt++);
    for(int i = 1; i <= n;i++)
        cout << ans[visited[0][i]][ar[i]].size() - 1 << " ";
    cout << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
 
#define FS              ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll              long long int
#define ld              long double
#define pb              push_back
#define bp              __builtin_popcount
#define sz              size()
#define ff              first
#define ss              second
#define vll             vector<ll>
#define vbool           vector<bool>
#define vpll            vector<pair<ll,ll>>
#define pll             pair<ll,ll>
#define vllv            vector<vector<ll>>
#define setpri(x)       cout<<setprecision(x)<<fixed;
#define all(v)          v.begin(),v.end()
#define allr(v)         v.rbegin(),v.rend()
#define yesr {cout<<"YES"<<endl;return;}
#define nor {cout<<"NO"<<endl;return;}
// getline (std::cin,name);
ll MOD=1e9+7;
ll ceil1(ll n,ll x){return (n-1)/x+(n>0);}

ll gcd(ll a,ll b){return __gcd(a,b);}
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

ll pow1(ll n,ll m ,ll mod=MOD );
ll pow2(ll n,ll k);

ll modinv(ll n,ll mod){  return pow1(n,mod-2,mod);}

bool func(pair<ll,ll> &a,pair<ll,ll> &b ){
        if(a.ff != b.ff)return a.ff < b.ff;
        return a.ss > b.ss;
}
ll const N=(ll)2e5+111;
ll const LG=(ll)log2(N)+1;



void solve(){
        ll i,j,k,l,n,m,x,y,z,r;
        
        cin>>n;
        for(i=1;;i++){
                if((n*i)%360==0){
                        cout<<i<<endl;
                        return;
                }
        }
        
        
}       
int main(){
        FS;
        
        ll i,j,k,n,m,x,y,z,q;
        q=1;
        // cin>>q;
        while(q--){
                solve();
        }
        return 0;
}


ll pow1(ll n,ll m,ll mod){
        if(m==0)return 1;
        
        if(m%2==0)return pow1((n*n)%mod,m/2,mod);
    	
    	return (pow1((n*n)%mod,m/2,mod)*n)%mod;
}

ll pow2(ll n,ll k){
        ll ans=1;
            while(k>0){
                if(k%2==1)ans=ans*n;
                n=n*n;
                k/=2;
            }
            return ans;
}


Measured memory_bytes: 3652
N = int(input())
l=[]
for i in range(N):
  L=list(map(int,input().split()))
  l.append(L)
dp = [[0 for i in range(3)] for j in range(N)]
for i in range(3):
  dp[0][i] = l[0][i]
if N >= 2:
  for i in range(1,N):
    for j in range(3):
      for k in range(3):
        if j != k:
          dp[i][j] = max(dp[i][j], dp[i-1][k] + l[i][j])
print(max(dp[N-1]))

Measured memory_bytes: 47472
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int h, w, k;
    long long MOD = 1000000007;
    long long c[9] = {1, 1, 2, 3, 5, 8, 13, 21, 34};

    std::cin >> h >> w >> k;

    long long dp[200][200] = {};
    dp[0][1] = 1;
    for(int i = 0; i < h; i++){
        for(int j = 1; j <= w; j++){
            dp[i + 1][j] += dp[i][j] * c[j - 1] % MOD *c[w - j] % MOD;
            dp[i + 1][j] %= MOD;

            if(j - 1 >= 1){
                dp[i + 1][j - 1] += dp[i][j] * c[j - 2] % MOD * c[w - j] % MOD;
                dp[i + 1][j - 1] %= MOD;
            }

            if(j + 1 <= w){
                dp[i + 1][j + 1] += dp[i][j] * c[j - 1] % MOD * c[w - (j + 1)] % MOD;
                dp[i + 1][j + 1] %= MOD;
            }
            //std::cout << "ij:" << i << j << ":" << dp[i][j] << std::endl;
        }
    }
    std::cout << dp[h][k] << std::endl;
    return 0;
}


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

typedef long long ll;
const int N = (int)2e5 + 50;
const ll mod = (ll)1e9 + 7;

int n, m, k;
ll fac[N], facinv[N];
ll inv[N];

ll fp(ll x, ll k){
    if(k == 0) return 1;
    ll hf = fp(x, k/2);
    return k % 2 ? hf * hf % mod * x % mod: hf * hf % mod;
}

ll ginv(ll x) {
    return fp(x, mod - 2);
}

ll comb(int n, int k){
    return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll sum(ll len) {
    return (len + 1) * len % mod * inv[2] % mod;
}

int main(){
    inv[1] = 1;
    for(int i = 2; i < N; i++) inv[i] = (mod - (mod / i) * inv[mod % i] % mod) % mod;
    fac[0] = 1;
    for(int i = 1; i <= N-1; i++) fac[i] = fac[i-1] * i % mod;
    facinv[N-1] = fp(fac[N-1], mod - 2);
    for(int i = N-1 - 1; i >= 0; i--) facinv[i] = facinv[i+1] * (i+1) % mod;

    cin >> n >> m >> k;
    ll res = 0;
    for(int i = 1; i <= n; i++) {
        ll denom = m * inv[n * m - 1] % mod;
        res += inv[n] * denom % mod * (sum(i - 1) + sum(n - i)) % mod;
        res %= mod;
    }
//    cout << res << endl;
    for(int i = 1; i <= m; i++) {
        ll denom = n * inv[n * m - 1] % mod;
        res += inv[m] * denom % mod * (sum(i - 1) + sum(m - i)) % mod;
        res %= mod;
    }
    res = comb(n * m, k) % mod * k % mod * (k - 1) % mod * inv[2] % mod * res % mod;
    res = (res % mod + mod) % mod;
    cout << res << endl;

}


Measured memory_bytes: 4992
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	int dfs(int zx, int zy, boolean map[][], int gx, int gy, int depth,String debug) {
		int[] ddx = { 1, 0, -1, 0 };
		int[] ddy = { 0, 1, 0, -1 };
		int ret = Integer.MAX_VALUE;
		if(depth == 11){
			return Integer.MAX_VALUE;
		}
		for (int i = 0; i < 4; i++) {
			int x = zx;
			int y = zy;
			int dx = ddx[i];
			int dy = ddy[i];
			boolean b = false;
			if(map[y+dy][x+dx]){
				continue;
			}
			for (; !map[y][x];) {
				x += dx;
				y += dy;
				if (x == gx && y == gy) {

					ret = depth;
					b = true;
					break;
				}
			}
			if (b) {
				continue;
			}
			if (y == 0 || y == map.length - 1) {
				continue;
			}
			if (x == 0 || x == map[0].length - 1) {
				continue;
			}
			map[y][x] = false;
			ret = Math.min(dfs(x- dx, y - dy, map, gx , gy, depth + 1 , debug+"["+dx+","+dy+"]"), ret);
			map[y][x] = true;
		}
		return ret;
	}

	void run() {
		/*
		 * 6 6 1 0 0 2 1 0 1 1 0 0 0 0 0 0 0 0 0 3 0 0 0 0 0 0 1 0 0 0 0 1 0 1 1
		 * 1 1 1
		 */
		for (;;) {
			int w = sc.nextInt();
			int h = sc.nextInt();
			if((w|h)==0){
				break;
				
			}
			boolean map[][] = new boolean[h + 2][w + 2];
			int start_x = 0;
			int start_y = 0;
			int goal_x = 0;
			int goal_y = 0;
			for (int i = 0; i < h + 2; i++) {
				Arrays.fill(map[i], true);
			}
			for (int i = 1; i < h + 1; i++) {
				for (int j = 1; j < w + 1; j++) {
					int buf = sc.nextInt();
					map[i][j] = (buf == 1);
					if (buf == 2) {
						start_x = j;
						start_y = i;
					}
					if (buf == 3) {
						goal_x = j;
						goal_y = i;
					}
				}
			}
			String debug = "";
			int z = dfs(start_x, start_y, map, goal_x, goal_y, 1 ,debug);
			if (z == Integer.MAX_VALUE)
				z = -1;
			System.out.println(z);
		}
	}

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
}

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

int main (void){
	int	N;
	int	i,j;
	int	t[250],v[150];	/*tの値とvの値を格納*/
	double	gragh[1000000];	
	int	sumt;
	double	tmp;

	scanf("%d",&N);

	t[0] = 0;

	/*tの入力*/
	for(i=0;i<N;i++)
    	scanf("%d",&t[i+1]);

	/*tの配列を累積時間にする*/
	for (i = 2;i < N+1;i++)
 		t[i] += t[i-1];

	/*累積最終時間が終了時間*/
	sumt = t[N];

	/*vの入力*/
	for(i=0;i<N;i++){
 		scanf("%d",&v[i]);
	}

	/*graghの最初の状態をつくる*/
	for (i=1;i < sumt*2+1;i++){ 

		if (i < sumt+1){
 			gragh[i] = (double)i/2;
 		}

		else{
 			gragh[i] = gragh[i-1] - 0.5;
 		}

	}

	for(j=0;j<N;j++){
	for(i=1;i<sumt*2+1;i++){
		if (t[j]*2 > i){
			tmp = ((double)t[j]+(double)v[j]-(double)i/2);
			if (gragh[i] > tmp){
				gragh[i] = tmp;
			}
		}
		else{if ((t[j]*2 <= i) && (i <= (t[j+1]*2))){
			if (gragh[i] > (double)v[j]){
				gragh[i] = (double)v[j];
			}
		}
		else {
			tmp = ((double)v[j]+0.5*(double)(i-t[j+1]*2));
			if (gragh[i] > tmp){
				gragh[i] = tmp;
			}
		}
		}
	}
	}

	double val = 0.0;
	for(i=0;i<sumt*2;i++){
		if (gragh[i] != gragh[i+1]){
			val += ((gragh[i]+gragh[i+1]) * 0.25);
		}
		else{
			val += ((gragh[i]) * 0.5);
		}
	}

	/*答えの出力*/
	printf("%lf\n",val);
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

const int INF = 1<<29;
const int MAX_V = 110;
const int MAX_E = 1100;

int N, M;
int a[MAX_E], b[MAX_E], c[MAX_E]; // 各辺
int dist[MAX_V][MAX_V]; // Floyd-Warshall 用

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

    // Floyd-Warshall でよくやる初期化
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            dist[i][j] = INF;
        }
        dist[i][i] = 0; // ここがポイント
    }

    // 入力
    for (int i = 0; i < M; ++i) {
        cin >> a[i] >> b[i] >> c[i];
        --a[i], --b[i];
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    // Floyd-Warshall
    for (int k = 0; k < N; ++k)
        for (int i = 0; i < N; ++i)
            for (int j = 0; j < N; ++j)
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);

    // 集計
    int res = 0;
    for (int i = 0; i < M; ++i) {
        if (c[i] > dist[a[i]][b[i]]) ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int main(int argc, char *argv[])
{
    int N;
    ll sum = 0;

    cin >> N;
    for (int i = 1; i <= N; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
package main

import (
	"fmt"
	"sort"
)

type point struct {
	x, y, z int
}

type projection struct {
	idx, val int
}

type projections []projection

func (a projections) Len() int           { return len(a) }
func (a projections) Less(i, j int) bool { return a[i].val < a[j].val }
func (a projections) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func main() {
	var n, m int
	fmt.Scanln(&n, &m)
	pts := make([]point, n)
	for i := 0; i < n; i++ {
		fmt.Scanln(&pts[i].x, &pts[i].y, &pts[i].z)
	}
	ans := 0
	sign := []int{1, -1}
	for _, sx := range sign {
		for _, sy := range sign {
			for _, sz := range sign {
				proj := make(projections, n)
				for i, p := range pts {
					proj[i].idx = i
					v := sx*p.x + sy*p.y + sz*p.z
					proj[i].val = v
				}
				sort.Sort(projections(proj))
				sum_x, sum_y, sum_z := 0, 0, 0
				for i := n - 1; i > n-m-1; i-- {
					idx := proj[i].idx
					sum_x += pts[idx].x
					sum_y += pts[idx].y
					sum_z += pts[idx].z
				}
				temp := abs(sum_x) + abs(sum_y) + abs(sum_z)
				if temp > ans {
					ans = temp
				}
			}
		}
	}
	fmt.Println(ans)
}


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

#define ll long long
#define mtv(kit) cout<<#kit<<" - "<<kit<<"\n";
#define ff first
#define ss second
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
#define pii pair<ll , ll>
#define all(x) x.begin(),x.end()
#define nl "\n"
#define ump unordered_map

void doit(){
    ll n,q,i,a1 = 0, a2 = 0;
    ump<ll, ll>mpAC,mpWA;
    string s;
    cin >> n >> q;
    while(q--){
        ll k;
        cin >> k >> s;
        if(s == "WA"){
            if(mpAC.find(k) == mpAC.end())mpWA[k]++;
        }
        else {
            if(mpAC.find(k) == mpAC.end()){
                a2 += mpWA[k];
                a1++;
            }
            mpAC[k] = 1;
        }
    }
    cout << a1 << " " << a2 << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt","r",stdin);
    freopen("output1.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t = 1;
    // cin >> t;
    for(ll i = 1; i <= t; i++){
        doit();
    }
}


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

void solve(int N, vector<int> a)
{
    int all = 0;
    for (int i = 0; i < N; i++)
    {
        all ^= a.at(i);
    }
    for (int i = 0; i < N - 1; i++)
    {
        cout << (all ^ a.at(i)) << " ";
    }
    cout << (all ^ a.at(N - 1)) << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a.at(i);
    }
    solve(N, move(a));
    return 0;
}


Measured memory_bytes: 3960
N = int(input())
S = input()
a = '('
b = ')'

i = 0
cntA = 0
ans = S
for s in S:
    if s == a:
        cntA += 1
    else:
        if cntA == 0:
            ans = '(' + ans
        else:
            cntA -= 1
else:
    ans = ans + ')' * cntA

print(ans)


Measured memory_bytes: 3060
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  string s;
  cin >> s;
  int N = s.size();
  ll sum = 0;
  for (int i = 0; i < 1 << N - 1; i++) {
    ll now = s[0] - '0';
    for (int j = 0; j < N - 1; j++) {
      if (i >> j & 1) {
        sum += now;
        now = s[j + 1] - '0';
      } else {
        now *= 10;
        now += s[j + 1] - '0';
      }
    }
    sum += now;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
bool isprime(int n)
{
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)
		return false;

	}
	return true;
}

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

int l;
cin>>l;
long long int res=0;
int rem=l%3;
long long int  x=0;
 printf("%.12f\n",(double)l*l*l/27); 

}


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

int main(){
	int a, b, c, d;
	d=0;
	cin >> a >> b >> c;
	for(int i=a ;i<=b; i++){
		if(c%i==0){
			d=d+1;
		}
	}
	cout << d <<endl;
	return 0;
}

Measured memory_bytes: 3100
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();
        
        String s = sc.next();
        
        for (int i = 0; i < a; i++) {
            if (s.charAt(i) == '-') {
                print("No");
                return;
            }
        }
        
        if (s.charAt(a) != '-') {
            print("No");
            return;
        }
        
        for (int i = a + 1; i < s.length(); i++) {
            if (s.charAt(i) == '-') {
                print("No");
                return;
            }
        }        
        print("Yes");
    }
    
    static void print(String str) {
        System.out.println(str);
    }
}

Measured memory_bytes: 22996
N = gets.chop.to_i

# if N % 4 == 0
#     puts 'Yes'
# elsif N % 7 == 0
#     puts 'Yes'
# else
#     (1..24).each ||
# end

flag = false
(0..25).each do |i|
    (0..15).each do |j|
        flag = true if 4 * i + 7 * j == N
    end
end

if flag
    puts "Yes"
else
    puts "No"
end


Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
ll a[100000];
int main() {
	int N, x;
	ll ans = 0;
	cin >> N >> x;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[i] > x) {
			ans += a[i] - x;
			a[i] = x;
		}
	}
	for (int i = 0; i + 1 < N; i++) {
		if (a[i] + a[i + 1] > x) {
			ll t = a[i] + a[i + 1] - x;
			ans += t;
			a[i + 1] -= t;
		}
	}
	cout << ans << endl;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int h,n; cin >> h >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  sort(a.begin(),a.end());

  rep(i,n){
    h-=a[i];
  }

  bool flag = false;
  if(h<=0) flag = true;

  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3776
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
using ull = unsigned long long;
using P = pair<int, int>;


ull E = 1000000007;


int main() {
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    if(n % 2 == 1){
        cout << "No" << "\n";
        return 0;
    }
    string t = s.substr(0,n/2);
    if(s == t + t){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }
    return 0;
}


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

int main()
{
  string s;
  getline(cin,s);
  for(int i=0;i<s.length();i++)
    {
      if('a'<=s[i]&&s[i]<='z')
	{
	  s[i]=(char)(s[i]+'A'-'a');
	}
      else if('A'<=s[i]&&s[i]<='Z')
	{
	  s[i]=(char)(s[i]+'a'-'A');
	}
    }

  cout << s << endl;

return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
using namespace std;
#define lim 999999999
#define on 100005
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR for(int i=1;i<=n;i++)
typedef long long int lo; 
typedef pair<int,int> PII;
int n,m,a[200005],cev,buy,kuc,say,k,cevv;
char c;
string s;
stack<int> st;
vector<int> v;
int main(){
	scanf("%d %d %d",&n,&k,&m);
	cev=max(n,max(k,m));
	if(n==cev){
		cevv=max(k,m);
	}
	else if(k==cev)
		cevv=max(n,m);
	else if(m==cev)
		cevv=max(n,k);
	int mn=min(n,min(k,m));
	printf("%d",(cev*10)+cevv+mn);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main() {
    ios::sync_with_stdio(0),cin.tie(0);
    int n,u,v;
    cin >> n >> u >> v;
    vector <int> g[n+1];
    for(int i=1;i<n;i++){
        int x,y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    int par[n+1],l[n+1];
    queue <int> q;
    par[v]=0,l[v]=0;
    q.push(v);
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int i:g[c]){
            if(i==par[c])continue;
            par[i]=c;
            l[i]=l[c]+1;
            q.push(i);
        }
    }
    int k=(l[u]-1)/2;
    while(k--)u=par[u];
    int ans=l[u]-1,m=0;
    for(int i=0;i<=n;i++)l[i]=0;
    q.push(u);
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int i:g[c]){
            if(i==par[c])continue;
            l[i]=l[c]+1;
            m=max(m,l[i]);
            q.push(i);
        }
    }
    cout << ans+m;
}

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

#define INF 1e18

using ll = long long;

int a[20];

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

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

    ll ans=INF;

    int sz=1<<n;
    for(int p=0;p<sz;p++)
    {
        int m=0;
        int cnt=0;
        ll cost=0;
        for(int i=0;i<n;i++)
        {
            if(cnt>=k)continue;
            if(m<a[i])
            {
                m=a[i];
                cnt++;
                continue;
            }
            if(p&(1<<i))
            {
                m=m+1;
                cost+=m-a[i];
                cnt++;
            }
        }

        if(cnt>=k)ans=min(ans,cost);
    }

    cout<<ans<<"\n";

    return 0;
}


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

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

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

    // insertion sort
    for (int i = 1; i < n; i++) {
        // output
        for (int j = 0; j < n; j++) cout << a[j] << (j < n - 1 ? " " : "");
        cout << endl;
        // sort
        if (a[i] > a[i - 1]) continue;
        for (int j = i; j > 0 && a[j] < a[j - 1]; j--) {
            swap(a[j], a[j - 1]);
        }
    }

    for (int i = 0; i < n; i++) cout << a[i] << (i < n - 1 ? " " : "");
    cout << endl;

    return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    int n, s;
    cin >> n >> s;
    vi a(n);
    rep (i, n) cin >> a[i];

    vll dp(n + 1, vl(s + 1));
    dp[0][0] = 1;
    ll ans = 0;
    rep (i, n) {
        rep (j, s + 1) {
            (dp[i + 1][j] += dp[i][j]) %= MOD;
            if (j + a[i] <= s) {
                if (j != 0) {
                    (dp[i + 1][j + a[i]] += dp[i][j]) %= MOD;
                }
                else {
                    (dp[i + 1][j + a[i]] += dp[i][j] * (i + 1) % MOD) %= MOD;
                }
            }
        }
        (ans += dp[i + 1][s]) %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 70784
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
    char s[11];
    scanf("%s",s);

    int i,j;

    long long ans=0;
    long long tmp;
    for(i=0;i<( 1 << ( strlen(s) - 1 ) );i++){
      tmp = s[0] - '0';
      for(j=0;j<( strlen(s) - 1 );j++){
        if( i & ( 1 << j ) ){
          ans += tmp;
          tmp = 0;
        }
        tmp = tmp*10 + (s[j+1] - '0');
      }
      ans += tmp;
    }

    printf("%lld",ans);

    return 0;
}

Measured memory_bytes: 128
import itertools

l, r = map(int, input().split())
if(r - l) > 2019:
    ans = 0
else:
    ans = 2018
    combs = list(itertools.combinations_with_replacement(range(l, r + 1), 2))
    for comb in combs:
        if comb[0] != comb[1]:
            a = (comb[0] * comb[1]) % 2019
            if ans > a:
                ans = a

print(ans)

Measured memory_bytes: 148516
#include <bits/stdc++.h>
using namespace std;
char S[101010];
bool hoge(int a,int x)
{
	return a==x||a==x+1;
}
bool test(int a, int b, int c)
{
	int mn=min(a,min(b,c));
	return hoge(a,mn)&&hoge(b,mn)&&hoge(c,mn);
}
int main()
{
	scanf("%s",S);
	int a=0,b=0, c=0;
	for (int i=0; S[i]; ++i)
		if (S[i]=='a')++a;
		else if(S[i]=='b')++b;
		else ++c;
	return puts(test(a,b,c)?"YES":"NO"),0;
}

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

using namespace std;

const int N = 50;

int P[N];

int n, m, K, mat[N][N], a[N][N];

int go(){
    int sum = 0;
    int cnt;
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            if(a[i][j]){
                cnt = 0;
                for(int k=j; k<=m; k++){
                    if(a[i][k] == a[i][j]){
                        cnt++;
                    } else {
                        break;
                    }
                }
                if(cnt >= K){
                    for(int k=j+1; k<=m; k++){
                        if(a[i][k] != a[i][j])  break;
                        a[i][k] = 0;
                    }
                    sum = sum + cnt * a[i][j];
                    a[i][j] = 0;
                }
            }
        }
    }

    for(int j=1; j<=m; j++){
        for(int i=n; i>=1; i--){
            if(a[i][j] == 0){
                for(int k=i-1; k>=1; k--){
                    if(a[k][j]){
                        swap(a[k][j], a[i][j]);
                        break;
                    }
                }
                if(!a[i][j]){
                    break;
                }
            }
        }
    }

    return sum;
}

int solve(int x, int y){
    for(int i=1; i<=n; i++){
        for(int j=1; j<=m; j++){
            a[i][j] = mat[i][j];
        }
    }
    for(int i=x; i>1; i--){
        a[i][y] = a[i-1][y];
    }
    a[1][y] = 0;
    int ret = 0;
    for(int g=0; ;g++){
        int v = go();
        if(!v){
            break;
        }
        ret = ret + P[g] * v;
    }
    return ret;
}

char s[N];

int main(){
    P[0] = 1;
    for(int i=1; i<N; i++){
        P[i] = P[i-1] << 1;
    }
    while(~scanf("%d %d %d", &n, &m, &K)){
        for(int i=1; i<=n; i++){
            scanf("%s", s);
            for(int j=1; j<=m; j++){
                mat[i][j] = s[j-1] - '0';
            }
        }
        int ans = 0;
        for(int i=1; i<=n; i++){
            for(int j=1; j<=m; j++){
                ans = max(ans, solve(i, j));
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}


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

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  int a,b,c;
  a=A.size();
  b=B.size();
  c=C.size();
  if(A.at(a-1)==B.at(0) && B.at(b-1)==C.at(0)){
    cout << "YES" << endl;}
  else{
    cout << "NO" << endl;}
}

Measured memory_bytes: 256
h, w = map(int, input().split())
n = int(input())
a = [int(x) for x in input().split()]

ans = [[0]*w for _ in range(h)]

key = 0
for i in range(h):
  if i%2 == 0:
    for j in range(w):
      ans[i][j] = key+1
      a[key] -= 1
      if not a[key]:
        key += 1
  else:
    for j in range(w-1, -1, -1):
      ans[i][j] = key+1
      a[key] -= 1
      if not a[key]:
        key += 1

for i in range(h):
  print(*ans[i])

Measured memory_bytes: 3920
n,x,y=map(int,input().split())
x,y=x-1,y-1
c=[0 for i in range(n-1)]

for i in range(n):
  for j in range(i+1,n):
    l=min(j-i,abs(i-x)+abs(j-y)+1)
    c[l-1]+=1

for i in range(n-1):
  print(c[i])

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

int main() {
	// your code goes here
	int x;
	cin >> x;
	int ans=0;
	if(360%x==0){
	    ans=360/x;
	}
	else{
	    int temp=x;
	    ans++;
	    while(temp%360!=0){
	        temp+=x;
	        ans++;
	    }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define MOD 1000000007
#define Nmax 500005
#define pii pair<int,int>
using namespace std;

int n,fr[Nmax],m,x,y;

int main()
{
    cin >> n >> m;
    for (int i=1;i<=m;i++){
        cin >> x >> y;
        fr[x]++; fr[y]++;
    }
    for (int i=1;i<=n;i++){
        if (fr[i]%2){
            cout << "NO\n";
            return 0;
        }
    }
    cout << "YES\n";
    return 0;
}


Measured memory_bytes: 640
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0057
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			System.out.println((1 + n * (n + 1) / 2));
		}
	}
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	rep(i,0,3) cout<<s[i];
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 3608
n=int(input())
apai=1
ans=0
a =list(map(int,input().split()))
for i in a:
	apai*=i
for i in range(n):
	A=a.copy()
	A[i]=1
	data = 1
	for j in A:
		data*=j
	ans+=data
print(round(apai/ans,6))



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

int main(){
  int N,W;
  cin>>N>>W;

  int v[N];
  int w[N];
  for(int i=0; i<N; i++)
    cin>>v[i]>>w[i];

  int DP[N+1][W+1];
  for(int i=0; i<W+1; i++)
    DP[0][i]=0;

  for(int i=1; i<=N; i++)
    for(int j=0; j<=W; j++)
      if(j<w[i-1])
        DP[i][j]=DP[i-1][j];
      else{
        if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1])
          DP[i][j]=DP[i-1][j];
        else
          DP[i][j]=DP[i][j-w[i-1]]+v[i-1];
      }
  cout<<DP[N][W]<<endl;
  return 0;
}

Measured memory_bytes: 6960