akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class D { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		var S = GetString().Select(x => (long)(x - '0')).ToArray();

		long ans = 0;
		var cnt = new Dictionary<long, long>();
		cnt[0] = 1;
		long num = 0;
		long pow = 1;
		for(long i = S.Length - 1; i >= 0; i--)
		{
			num = (num + pow * S[i]) % 2019;
			pow = (pow * 10) % 2019;
			
			cnt.TryGetValue(num, out long c);
			ans += c;
			cnt[num] = c + 1;
		}

		WriteLine(ans);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 30800
// Hierarchical Democracy
import java.util.*;

public class Main {
	static int pos;
	static String str;

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		for (int i = 0; i < n; i++) {
			pos = 0;
			str = scanner.next();
			int result = formura();
			System.out.println(result);
		}
		scanner.close();
	}

	static int formura() {
		pos++;
		char c = str.charAt(pos);
		int result = 0;
		if (c == '[') {
			List<Integer> numList = new ArrayList<Integer>();
			while (str.charAt(pos) == '[') {
				numList.add(formura());
			}
			Collections.sort(numList);
			for (int i = 0; i < numList.size() / 2 + 1; i++) {
				result += numList.get(i);
			}
		} else {
			while (Character.isDigit(str.charAt(pos))) {
				result *= 10;
				result += Character.getNumericValue(str.charAt(pos));
				pos++;
			}
			result = result / 2 + 1;
		}
		pos++;
		return result;
	}
}

Measured memory_bytes: 38700
z=lambda:raw_input().split()
while True:
    t={}
    c=input()
    if c==0:break
    for i in range(c):
        f,q=z()
        t[f]=int(q)
    for i in range(input()):
        f=z()
        m=sum([t[j] if j in t else 0 for j in f[2:]])
        q=t[f[0]]
        t[f[0]]=q if m>q else m
    print t[raw_input()]

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

using namespace std;

#define forn(a, e) for (int a = 0; a < (int)(e); a++)
#define forr(a, s, e) for (int a = s; a < (int)(e); a++)
#define fore(e, a) for (auto& e : a)

#ifdef LOCAL
#define logv(a) {cerr << #a << " = "; fore(e, a) {cerr << e << " ";} cerr << "\n";}
#define logvp(a) {cerr << #a << " = "; fore(e, a) {cerr << "(" << e.first << ", " << e.second << ") ";} cerr << "\n";}
#define logvv(a) {cerr << #a << " = \n"; fore(r, a) { fore(e, r) {cerr << e << " ";} cerr << "\n";} }
#define logvf(a, field) {cerr << #a"."#field << " = \n"; fore(e, a) { cerr << e.field << " ";} cerr << "\n"; }
#define logs(a) cerr << #a << " = " << (a) << "\n";
#define logss(a, b) cerr << #a << " = " << (a) << ", " << #b << " = " << (b) << "\n";
#define logp(a) cerr << #a << " = " << "(" << a.first << ", " << a.second << ")" << "\n";
#define cond(pred, stmt) if (pred) { stmt }
#else
#define logv(a)
#define logvp(a)
#define logvv(a)
#define logvf(a, field)
#define logs(a)
#define logss(a, b)
#define logp(a)
#define cond(pred, stmt)
#endif

using i64 = long long;
using iip = pair<i64, i64>;
using ivec = vector<int>;
using llvec = vector<i64>;
using svec = vector<string>;

template<typename T, typename Dim>
auto make_vec(T value, Dim dim) { return vector<T>(dim, value); }
template<typename T, typename Dim1, typename... Dim>
auto make_vec(T value, Dim1 dim1, Dim... dims) { return make_vec(make_vec(value, dims...), dim1); }

template<typename T>
bool uax(T& v, const T& newv) { if (v < newv) { v = newv; return true; } else return false; }
template<typename T>
bool uin(T& v, const T& newv) { if (v > newv) { v = newv; return true; } else return false; }

template<typename T>
istream& operator>>(istream& is, vector<T>& c) { for (auto& e : c) is >> e; return is; }

// template<typename ...T>
// istream& read(T&... args) { return (cin >> ... >> args); }

static mt19937 rande(123123);
template<typename T>
T rand_int(T from, T to) { uniform_int_distribution<T> distr(from, to); return distr(rande); }

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


    int n;
    while (cin >> n) {
        ivec a(n);
        cin >> a;
        sort(a.begin(), a.end());

        i64 ans = 0;
        forr(i, 1, n) {
            forr(j, i + 1, n) {
                int c = a[j] - a[i];
                int pos = upper_bound(a.begin(), a.begin() + i, c) - a.begin();
                ans += i - pos;
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int a[11];
bool dfs(int i,int l,int r){
	if(i==10)return true;
	if(dfs(i+1,a[i],r)&&a[i]>l)return true;
	if(dfs(i+1,l,a[i])&&a[i]>r)return true;
	return false;
}
int main(){
	int T;
	cin>>T;
	while(T--){
	for(int i=0;i<10;i++)
		cin>>a[i];
	if(dfs(0,0,0))cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	}
	return 0;
}


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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const int MAX_N = 200000;
int n;
vi g[MAX_N];
int d[MAX_N];

void dfs(int u, int p, int lv) {
  d[u] = lv;

  for (int v : g[u]) {
    if (v != p) dfs(v,u,lv+1);
  }
}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n;

  int a,b;
  forn1(i,n-1) {
    cin >> a >> b;
    a--,b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  dfs(0,-1,0);

  int u = max_element(d,d+n) - d;

  dfs(u,-1,0);

  int di = *max_element(d,d+n);

  // 余り1を強制できる方が勝ち
  if (di % 3 == 1)
    cout << "Second\n";
  else
    cout << "First\n";

  return 0;
}


Measured memory_bytes: 21376
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 long long a,b,v,w,t,x,y;
 cin >> a>>v>>b>>w>>t;
 if(a<b&&v<=w){
   cout << "NO" << endl;
   return 0;
 }
 x=(a+v*t);
 y=(b+w*t);
 if(a<b&&x>=y){
   cout << "YES" << endl;
   return 0;
 }
 if(a>b&&v<=w){
   cout << "NO" << endl;
   return 0;
 }
 x=(a-v*t);
 y=(b-w*t);
 if(a>b&&x<=y)
   cout << "YES" << endl;
 else
    cout << "NO" << endl;
}

Measured memory_bytes: 3596
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <map>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int n;
	
	cin >> n;

	int t[n];

	map<int, int> m;

	rep(i, n)
	{
		cin >> t[i];
		m[t[i]] = 1 - m[t[i]];
	}

	int count = 0;

	map<int, int>::iterator it = m.begin();
	
	for(; it != m.end(); it++)
	{
		if(it->second)
		{
			count += 1;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<numeric>
#include<set>
#include<climits>
using namespace std;

typedef long long ll;

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

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

    ll bef[n+1], aft[n+1];
    ll sum = accumulate(a, a+n, 0ll);
    bef[0] = sum;
    
    multiset<int> s;
    for(int i = 0; i < n; i++)  s.emplace(a[i]);
    multiset<int>::iterator it = s.begin();

    for(int i = n; i < 2*n; i++){
        s.emplace(a[i]);
        if(a[i] >= (*it)){
            sum += a[i]-(*it);
            it++;
        }
        bef[i-n+1] = sum;
    }

    s.clear();
    for(int i = 0; i < n; i++)  s.emplace(a[3*n-1-i]);
    it = s.end(); it--;
    sum = accumulate(a+2*n, a+3*n, 0ll);
    aft[n] = sum;

    for(int i = 2*n-1; i >= n; i--){
        s.emplace(a[i]);
        if(a[i] < (*it)){
            sum += a[i]-(*it);
            it--;
        }
        aft[i-n] = sum;
    }

    ll ans = LLONG_MIN;
    for(int i = 0; i < n+1; i++){
        ans = max(ans, bef[i]-aft[i]);
    }

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

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 4e3 + 5;

int ans[MAXN];

bool make_query(int a, int b){
	printf("? %d %d\n", a, b);
	fflush(stdout);
	char c[10];
	scanf("%s", &c[0]);
	return (c[0] == 'Y');
}

void solve(){
	int n, a, b;
	scanf("%d%d", &a, &b);
	if (a <= b){
		printf("Impossible\n");
		fflush(stdout);
		return;	
	}
	n = a + b;
	stack<int> stk;
	REP(i, 0, n){
		if (stk.empty()){
			stk.push(i);
		} else {
			int a = stk.top();
			int v = make_query(a, i);
			if (!v){
				stk.pop();
			} else {
				stk.push(i);
			}
		}
	}
	
	int s = stk.top();
	ans[s] = 1;
	REP(i, 0, n){
		if (i != s && make_query(s, i)){
			ans[i] = 1;
		}
	}
	
	printf("! ");
	REP(i, 0, n){
		printf("%d", ans[i]);
	}
	putchar('\n');
	fflush(stdout);
}   

int main(){
/*#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif*/
    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 724
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair

int main(){
    int n; cin >> n;
    long long ans = 0;
    for (long long i=1; i!=n+1; i++){
        ans += i * (n-i+1);
    }
    for (long long i=1; i!=n; i++){
        long long a, b; cin >> a >> b;
        ans -= min(a, b) * (n - max(a, b)+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1005;
char mp[N][N];int n,m,a,b;
int main(){
	scanf("%d%d%d%d",&n,&m,&a,&b);
	fp(i,1,b)fp(j,1,m)mp[i][j]=1;
	fp(i,1,n)fp(j,1,a)mp[i][j]^=1;
	fp(i,1,n){
		fp(j,1,m)putchar(mp[i][j]+'0');
		putchar('\n');
	}
	return 0;
}

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

main(){
  int n;
  cin>>n;
  int Cx,Cy,H;
  vector<int> x(n),y(n),h(n);
  rep(i,n) cin>>x[i]>>y[i]>>h[i];
  bool flag=0;
  for(int i=0; i<=100; i++){
    for(int j=0; j<=100; j++){
      bool ok=1;
      H=0;
      int limit=INT_MAX;
      rep(k,n){
        if(H==0){
          if(h[k]!=0){
            H=h[k]+abs(i-x[k])+abs(j-y[k]);
            if(H>limit) ok=0;
          }
          else limit=min(limit,h[k]+abs(i-x[k])+abs(j-y[k]));
        }else{
          if(h[k]!=max(H-abs(i-x[k])-abs(j-y[k]),0LL)) ok=0;
        }
      }
      if(ok){
        flag=1; Cx=i; Cy=j; break; 
      }
    }
    if(flag)break;
  }
  cout<<Cx<<" "<<Cy<<" "<<H<<endl;
}


Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000
typedef long long ll;

int main(void){
    ll N, K;
    cin >> N >> K;
    
    ll h[N];
    for(ll i=0; i<N; i++){
        cin >> h[i];
    }

    ll cost[N];
    for(int i=0; i<N; i++){
        cost[i] = INF;
    }
    cost[0] = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<min(i+K+1, N); j++){
            cost[j] = min(cost[j], cost[i] + abs(h[i] - h[j]));
        }
    }
    cout << cost[N-1] << endl;
    return 0;
}

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

# from scipy.special import comb
# a = comb(n, r)

MOD = 10**9 + 7
ans = 0
for k in range(K,N+2):
    # print(k)
    right = (N+N-k+1)*k // 2
    left = (k-1)*k // 2 
    ans += right - left + 1
    ans %= MOD
    # print(ans)
    # ans += comb(N+1, k, exact=True)
    # print(ans)


print(ans)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;
	int A[M], B[M], C[M];
	rep(i,M){
		cin >> A[i] >> B[i] >> C[i];
		--A[i]; --B[i];
		C[i] = -C[i];
	}
	vector<int> dist(N, INF);
    dist[0] = 0;
	rep(loop,N-1){
		rep(i,M){
            if(dist[A[i]] == INF) continue;
            if(dist[B[i]] > dist[A[i]] + C[i]){
                dist[B[i]] = dist[A[i]] + C[i];
            }
        }
	}
	vector<bool> negativeCycle(N, false); // 負閉路の影響を受ける点(最短経路が-INFに向かう点)をtrueにする。
    rep(loop, N){
        rep(i,M){
            if(dist[A[i]] == INF) continue;
            if(dist[B[i]] > dist[A[i]] + C[i]){
                negativeCycle[B[i]] = true;
            }
            if(negativeCycle[A[i]]) negativeCycle[B[i]] = true;
        }
    }
	if(negativeCycle[N-1]) cout << "inf" << endl;
    else cout << -dist[N-1] << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 2147483647;
const ll MOD = 998244353;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

ll n, k[100005], uku[100005], ma, ans = 1;
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		++uku[k[i]];
		ma = max(ma, k[i]);
	}
	if (k[0] != 0 || uku[0] != 1) { cout << 0 << endl; return 0; }

	for (int i = 1; i <= ma; ++i) {
		if (uku[i] == 0) { cout << 0 << endl; return 0; }

		for (int j = 0; j < uku[i]; ++j) {
			ans = ans * uku[i - 1] % MOD;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include <set>
typedef long long ll;
using namespace std;
int main()
{
	ll n;
	cin>>n;
	if(n&1)
	cout<<2*n;
	else
	cout<<n;
	
}

Measured memory_bytes: 256
/*
 * Created by Dipta Das on 30-06-2019
 * Title: 
 * Problem Link: 
 * Editorial: 
 * Source Code: 
 * Comments: 
*/

#include <bits/stdc++.h>
#include <stdio.h>
#define fin freopen("input", "r", stdin)
#define whatis(x) cerr << #x << ": " << x << endl;

using namespace std;
using ll = long long;
ll h, w;
char grid[1003][1003];
int dp[1003][1003];
ll MOD = 1e9 + 7;

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

    cin >> h >> w;

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >> grid[i][j];
        }
    }

    dp[0][0] = grid[0][0] == '.';

    for (int i = 1; i < w; ++i) {
        if (grid[0][i] == '#') dp[0][i] = 0;
        else dp[0][i] = dp[0][i-1];
    }
    for (int i = 1; i < h; ++i) {
        if (grid[i][0] == '#') dp[i][0] = 0;
        else dp[i][0] = dp[i-1][0];
    }

    for (int i = 1; i < h; ++i) {
        for (int j = 1; j < w; ++j) {
            if (grid[i][j] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    }

    cout << dp[h-1][w-1] << endl;

    


    return 0;
}



Measured memory_bytes: 5120
#include <stdio.h>

int main(){
    int n;
    char s[10001], al[27];
    scanf("%d %s", &n, s);
    for(int i = 0; i < 26; i++){
        al[i] = 'A' + i;
    }
    
    for(int i = 0; s[i] != '\0'; i++){
        s[i] = al[(s[i] - 'A' + n) % 26];
    }

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

Measured memory_bytes: 128
def make_digit x
    digit, min, max = 0, 0, 1
    while (x.positive? && x > max) || (x.negative? && x < min)
        digit += 1
        max += 2 ** digit if digit.even?
        min += (-2) ** digit if digit.odd?
    end
    return digit
end
 
n = gets.to_i
if n == 0
    puts 0
else
    arr = []
    x = n
    while x != 0
        arr << make_digit(x)
        x = x - (-2) ** arr.last
    end
    answer = Array.new(arr.max + 1, "0")
    arr.each{|i| answer[arr.max - i] = "1"}
    puts answer.join
end

Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;
    cin >> n >> m;

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

    vector<ll> elm = {0,2,5,5,4,5,6,3,7,6};

    vector<pair<ll,ll>> e;
    for(int i = 0; i < m; i++){
        e.push_back(make_pair(elm[a[i]],a[i]));
    }

    sort(e.begin(),e.end());
    ll s = e.size();
    for(int i = 0; i < s - 1; i++){
        if(e[i].first == e[i+1].first){
            e.erase(e.begin() + i);
            i--;
            s--;
        }
    }

    vector<pair<ll,ll>> tmp;
    for(int i = 0; i < s; i++){
        tmp.push_back(make_pair(e[i].second,e[i].first));
    }

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

    e = tmp;
    for(int i = 0; i < s; i++){
        auto x = e[i];
        e[i].first = x.second;
        e[i].second = x.first;
    }

    vector<vector<ll>> dp(s+1,vector<ll>(n+1,0));
    dp[0][0] = 1;

    for(int i = 1; i < s+1; i++){
        for(int j = 0; j < n+1; j++){
            dp[i][j] = dp[i-1][j];
        }
        for(int j = 0; j < n+1; j++){
            if(j - e[i-1].first >= 0 && dp[i][j-e[i-1].first] > 0){
                dp[i][j] = max(dp[i][j], dp[i][j-e[i-1].first] + 1);
            }
        }
    }

    vector<ll> num(s,0);

    ll nowi = s;
    ll nowj = n;

    while(nowi != 0 && nowj != 0){
        if(nowj - e[nowi-1].first >= 0 && dp[nowi][nowj] == dp[nowi][nowj-e[nowi-1].first] + 1){
            nowj -= e[nowi-1].first;
            num[nowi-1]++;
        }else{
            nowi--;
        }
    }

    string ans = "";

    bool flag = true;
    while(flag){
        flag = false;
        ll max = 0;
        ll maxi = 0;
        for(int i = 0; i < s; i++){
            if(num[i] > 0 && max < e[i].second){
                max = e[i].second;
                maxi = i;
                flag = true;
            }
        }
        while(num[maxi] > 0){
            ans += ('0' + e[maxi].second);
            num[maxi]--;

        }
    }

    cout << ans << endl;

    
    return 0;
}

Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func count(N int) int {
	cnt := 0
	for i := 1; i <= N; i++ {
		if N%i == 0 {
			cnt++
		}
	}
	return cnt
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	cnt := 0
	for i := 1; i <= N; i += 2 {
		if count(i) == 8 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
a = list(map(int,input().split()))

a.sort()

count = 0

if ((a[2]-a[1])%2 == 1) and ((a[2]-a[0])%2 == 1) :
  count += 1
elif ((a[2]-a[1])%2 == 1) or ((a[2]-a[0])%2 == 1) :
  count += 2

count += ((a[2]-a[1])//2)
count += ((a[2]-a[0])//2)

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<vector<int>> g(N);

    if (N % 2 == 0) {
        REP(i, N) {
            int ng = N - i - 1;
            REP(j, N) {
                if (i == j) continue;
                if (j == ng) continue;
                g[i].pb(j);
            }
        }
    } else {
        REP(i, N - 1) {
            int ng = (N - 1) - i - 1;
            REP(j, N) {
                if (i == j) continue;
                if (j == ng) continue;
                g[i].pb(j);
            }
        }
        REP(j, N - 1) {
            g[N - 1].pb(j);
        }
    }
    
    vector<pii> ans;
    REP(i, N) {
        FORE(w, g[i]) {
            ans.pb({i + 1, w + 1});
        }
    }

    cout << SZ(ans) / 2 << endl;
    set<pii> u;
    FORE(x, ans) {
        int a, b;
        tie(a, b) = x;
        if (a > b) swap(a, b);
        if (CONTAIN(u, pii(a, b))) continue;
        u.insert({a, b});
        cout << a << " " << b << endl;
    }
    return (0^_^0);
}



Measured memory_bytes: 892
from sys import stdin

s = str(stdin.readline().rstrip())
len_s = len(s)

half_a = s[0:int((len_s - 1)/2)]
rev_half_a = half_a[::-1]
half_b = s[:int((len_s - 1)/2):-1]
rev_half_b = half_b[::-1]

if half_a == half_b:
    if rev_half_a == half_a:
        if rev_half_b == half_b:
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 2e18

int main(){
    ll x;
    cin >> x;
    ll tmp = 100;
    int cnt = 0;
    while(x > tmp){
        cnt++;
        tmp = (ll)(1.01 * tmp);
    }
    
    cout << cnt << endl;
    // printf("%d\n", N);
    return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin>>n;
  vector<int> v(n),c(n);
  rep(i,n) cin>>v.at(i);
  rep(i,n) cin>>c.at(i);
  int ans=0;
  rep(i,n) if(v.at(i)>c.at(i)) ans+=v.at(i)-c.at(i);
  cout<<ans<<endl;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

typedef tuple<int, int, int> T;

struct BipartiteMatching
{
  vector<vector<int>> graph;
  vector<int> match, used;
  int timestamp;

  BipartiteMatching(int n) : graph(n), used(n, 0), match(n, -1), timestamp(0) {}

  void add_edge(int u, int v)
  {
    dump(u, v);
    graph[u].push_back(v);
    graph[v].push_back(u);
  }

  bool dfs(int idx)
  {
    used[idx] = timestamp;
    for (auto& to : graph[idx]) {
      int to_match = match[to];
      dump(idx, to, to_match);
      if (to_match == -1 || (used[to_match] != timestamp && dfs(to_match))) {
        match[idx] = to;
        match[to] = idx;
        dump(match);
        return true;
      }
    }
    return false;
  }

  int bipartite_matching()
  {
    int ret = 0;
    for (int i = 0; i < graph.size(); i++) {
      if (match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
        dump(timestamp, ret, match);
      }
    }
    return ret;
  }

  void output()
  {
    for (int i = 0; i < graph.size(); i++) {
      if (i < match[i]) {
        cout << i << "-" << match[i] << endl;
      }
    }
  }
};

int cmp(const P& a, const P& b)
{
  int dx = b.first - a.first;
  int dy = b.second - a.second;
  if (0 < dx && 0 < dy)
    return dx + dy;
  else
    return 0;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  int N;
  cin >> N;
  vector<P> b(N);
  vector<P> r(N);
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    r[i] = P(x, y);
  }
  for (int i = 0; i < N; i++) {
    int x, y;
    cin >> x >> y;
    b[i] = P(x, y);
  }
  BipartiteMatching bm(N + N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (cmp(r[j], b[i])) {
        bm.add_edge(i, N + j);
      }
    }
  }
  cout << bm.bipartite_matching() << endl;
  // bm.output();

  return 0;
}

Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-06-26
**/

#include <bits/stdc++.h>
using namespace std;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x;
    cin >> x;
    
    int sum = 0, t = 0;
    while (sum < x) {
        t++;
        sum += t;
    }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3640
// C - Candles
// https://abc107.contest.atcoder.jp/tasks/arc101_a

import scala.io.StdIn.readLine
import math.{min, abs}

object Main extends App {

  val Array(n, k) = readLine.split(" ").map(_.toInt)
  val xs: Array[Int] = readLine.split(" ").map(_.toInt)

  case class Pair(head: Int, last: Int)
  val pairs: List[Pair] = (0 to n-k).toList.map(i => Pair(xs(i), xs(i+k-1)))
  val lengths = pairs.map(p => p.last - p.head + min(abs(p.head), abs(p.last)))

  println(lengths.min)

}

Measured memory_bytes: 44440
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        boolean res = true;

        for (int i = 0; i < N; i++) {
            int A = sc.nextInt();
            if (A != 0 && A % 2 != 0) {
                continue;
            }
            if (A % 3 == 0 || A % 5 == 0) {
                continue;
            }
            res = false;
        }
        if (res) {
            System.out.println("APPROVED");
        } else {
            System.out.println("DENIED");
        }
    }

}

Measured memory_bytes: 23252
def main():
    n = int(input())
    dp = [float('inf')]*(n+1)
    dp[0] = 0

    ls = [1, 6, 9]
    ks = [1]

    for l in ls[1:]:
        i = 1
        while True:
            if l ** i <= n:
                ks.append(l**i)
            else:
                break
            i += 1

    for k in ks:
        for i in range(len(dp)):
            if i+k >= len(dp):
                break
            if dp[i]+1 < dp[i+k]:
                dp[i+k] = dp[i]+1
    print(dp[n])

main()


Measured memory_bytes: 6884
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << a[N-1]-a[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a, b;
  if (N % 2 == 0){
    for (int i = 1; i <= N; i++){
      for (int j = i + 1; j <= N; j++){
        if (i + j != N + 1){
          a.push_back(i);
          b.push_back(j);
        }
      }
    }
  } else {
    for (int i = 1; i <= N; i++){
      for (int j = i + 1; j <= N; j++){
        if (i + j != N){
          a.push_back(i);
          b.push_back(j);
        }
      }
    }
  }
  int M = a.size();
  cout << M << endl;
  for (int i = 0; i < M; i++){
    cout << a[i] << ' ' << b[i] << endl;
  }
}

Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    for (int i = 0; i <= 100; ++i)
    {
        for (int j = 0; j <= 100; ++j)
        {
            if (i * 4 + j * 7 == n)
            {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";
    return 0;
}


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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

string S;

signed main()
{
  cin >> S;
  int ans = 0;
  int white = 0;
  for(int i = S.size()-1; 0 <= i; i--) {
    if(S[i] == 'W') {
      white++;
    } else {
      ans += white;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	/* ローカル変数 */
	int l_i_one_cards;  /* 1が書かれたカード枚数 */
	int l_i_zero_cards;  /* 0が書かれたカード枚数 */
	int l_i_minus_one_cards;  /* -1が書かれたカード枚数 */
	int l_i_get_cards;  /* 選ぶカード枚数 */
	int l_i_remaining_get_cards;  /* 残りの選ぶカード枚数 */
	int l_i_get_one_cards;  /* 1を選んだ枚数 */
	int l_i_get_zero_cards;  /* 0を選んだ枚数 */
	int l_i_get_minus_one_cards;  /* -1を選んだ枚数 */
	int l_i_max;  /* 最大値 */

	/* 各値を入力 */
	scanf("%d %d %d %d", &l_i_one_cards, &l_i_zero_cards, &l_i_minus_one_cards, &l_i_get_cards);

	/* 残りの選ぶカード枚数を取得 */
	l_i_remaining_get_cards = l_i_get_cards;

	/* 1のカードを選ぶ */
	if (l_i_remaining_get_cards < l_i_one_cards) {
		l_i_get_one_cards = l_i_remaining_get_cards;
	}
	else {
		l_i_get_one_cards = l_i_one_cards;
	}
	l_i_remaining_get_cards -= l_i_get_one_cards;

	/* 0のカードを選ぶ */
	if (l_i_remaining_get_cards < l_i_zero_cards) {
		l_i_get_zero_cards = l_i_remaining_get_cards;
	}
	else {
		l_i_get_zero_cards = l_i_zero_cards;
	}
	l_i_remaining_get_cards -= l_i_get_zero_cards;

	/* -1のカードを選ぶ */
	if (l_i_remaining_get_cards < l_i_minus_one_cards) {
		l_i_get_minus_one_cards = l_i_remaining_get_cards;
	}
	else {
		l_i_get_minus_one_cards = l_i_minus_one_cards;
	}
	l_i_remaining_get_cards -= l_i_get_minus_one_cards;

	/* 最大値を算出 */
	l_i_max = l_i_get_one_cards - l_i_get_minus_one_cards;

	/* 表示 */
	printf("%d", l_i_max);

	return 0;
}


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

int main() {
  // ここにプログラムを追記
  int a;
  int b;
  cin >> a >> b;
  double z = (a+b);
  double x= z /2;
  int y = static_cast<int>(x);
  if(y < x){
  	cout << y +1  << endl;
  }else{
  	cout << y << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
#define NMAX 22
bool visited[NMAX];
int n,m,x1,x2,y1,y2;
int dist[NMAX][NMAX];
class Node{
public:
	int p,cost;
	Node(int _p, int _cost):p(_p),cost(_cost){
	}
	bool operator < (const Node &o)const{
		return cost>o.cost;
	}
};
int dijkstra(int from,int to){
	fill(visited,visited+NMAX,false);
	priority_queue<Node> pq;
	pq.push(Node(from,0));
	while(!pq.empty()){
		Node cur=pq.top();pq.pop();
		if(cur.p==to)return cur.cost;
		if(visited[cur.p])continue;
		visited[cur.p]=true;
		for(int i=1;i<=n;i++){
			if(cur.p==i||dist[cur.p][i]==-1)continue;
			pq.push(Node(i,cur.cost+dist[cur.p][i]));			
		}
	}
}
void solve(){
	cout<<y1-y2-dijkstra(x1,x2)-dijkstra(x2,x1)<<endl;
}
void init(){
	for(int i=0;i<=NMAX;i++)fill(dist[i],dist[i]+NMAX,-1);	
}
int main(){
	int a,b,c,d;
	cin>>n>>m;
	char dmy;
	init();
	for(int i=0;i<m;i++){
		cin>>a>>dmy>>b>>dmy>>c>>dmy>>d;
		dist[a][b]=c;
		dist[b][a]=d;
	}
	cin>>x1>>dmy>>x2>>dmy>>y1>>dmy>>y2;
	solve();
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

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

    int N;
    cin >> N;
    vector<string> v(N);
    int o, c;
    o = c = 0;
    int ope = 0;
    vector<P> up, down;
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
        int dif = 0;
        int mx = 0;
        int oo = 0, cc = 0;
        for(int j = 0; j < v[i].size(); ++j) {
            if(v[i][j] == '(') {
                ++o; ++oo; ++dif;

            } else {
                ++c; ++cc; --dif;

            }
            mx = min(mx, dif);

        }
        if(mx < 0) {
            if(dif > 0) up.pb(MP(mx, -dif));
            else down.pb(MP(mx - dif, -dif));

        } else {
            ope += oo - cc;

        }
    }

    if(c != o) {
        cout << "No" << endl;
        return 0;

    }

    sort(rall(up));
    for(int i = 0; i < up.size(); ++i) {
        if(ope + up[i].F < 0) {
            cout << "No" << endl;
            return 0;

        }
        ope += -up[i].S;
    }

    sort(rall(down));
    ope = 0;
    for(int i = 0; i < down.size(); ++i) {
        if(ope + down[i].F < 0) {
            cout << "No" << endl;
            return 0;

        }
        ope += down[i].S;

    }
    cout << "Yes" << endl;
    return 0;
}



Measured memory_bytes: 38648
#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>;


struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int deg[100005];
vector<int> to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    int ans = uf.size(i)-1-deg[i];
    for (int u : to[i]) {
      if (uf.same(i,u)) --ans;
    }
    printf("%d%c", ans, i==n-1?'\n':' ');
  }
  return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n, r;
    while (cin >> n >> r, n) {
        stack<int> st;
        for (int i = 0; i < n; i++) {
            st.push(i + 1);
        }
        int p, c;
        while (r--) {
            cin >> p >> c; p--;
            stack<int> a[2];
            while (p--) { a[0].push(st.top()); st.pop(); }
            while (c--) { a[1].push(st.top()); st.pop(); }
            for (int i = 0; i < 2; i++) {
                while (!a[i].empty()) {
                    st.push(a[i].top());
                    a[i].pop();
                }
            }
        }
        cout << st.top() << endl;
    }
    return 0;
}

Measured memory_bytes: 3032
#include <iostream>
#include <queue>
using namespace std;
    queue<int> Q;
int u[1000][1000];
int d[1000],color[1000];
// white 0 gray 1 black 2
void BFS(int s,int n){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            color[i]=0;
            d[i]=-1;
        }
    }
    color[s]=1;
    d[s]=0;
    Q.push(s);
    while(Q.size()!=0){
        int tmp=Q.front();
        Q.pop();
        for(int j=1;j<=n;j++){
            if(color[j]==0 && u[tmp][j]==1){
                color[j]=1;
                d[j]=d[tmp]+1;
                Q.push(j);
            }
        }
        color[tmp]=2;
    }
}
int main(){
    int n,l,k,m;
    cin>>n;
    u[100][100]={};
    for(int i=0;i<n;i++){
        cin>>l>>k;
        for(int j=1;j<=k;j++){
            cin>>m;        
            u[l][m]=1;
        }
    }
    BFS(1,n);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<d[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3420
n = int(input())
d, x = map(int, input().split())
a = []
for i in range(n):
	a.append(int(input()))

chocolate = x

for i in a:
	chocolate += 1
	days = 1
	while(True):
		days += i
		if days <= d:
			chocolate += 1
		else:
			break

print(chocolate)


Measured memory_bytes: 3060
// ABC101C - Minimization

#include <bits/stdc++.h>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		int t;
		cin >> t;
	}

	int ans;
	ans = ((N - K) + (K - 2))/ (K - 1) + 1;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<array>
#include<algorithm>
#include <random>
std::random_device seed_gen;
std::mt19937 engine(seed_gen());
std::uniform_int_distribution<> dD {0, 364};

int const INF = 1e9;
int const M = 12500;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(int& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(int& si: s[d]) std::cin >> si;
  }
  
  // greedy
  std::vector<int> t(D);
  int ans = 0;
  int last[26];
  std::fill_n(last, 26, -1);
  for(int d = 0; d < D; ++d) {
    int ma = -INF;
    t[d] = 0;
    for(int T = 1; T <= 26; ++T) {
      int cur = s[d][T-1];
      int sv = last[T-1];
      last[T-1] = d;
      for(int cx = 0; cx < 26; ++cx) {
        cur -= (d-last[cx])*c[cx];
      }
      last[T-1] = sv;
      if(cur > ma) { ma = cur; t[d] = T; }
    }
    ans += ma;
    last[t[d]-1] = d;
  }
  
  auto score = [&]()->int {
    int ans = 0;
    int last[26];
    std::fill_n(last, 26, -1);
    for(int d = 0; d < D; ++d) {
      ans += s[d][t[d]-1];
      last[t[d]-1] = d;
      for(int cx = 0; cx < 26; ++cx) {
        ans -= (d-last[cx])*c[cx];
      }
    }
    return ans;
  };
  
  // modify
  for(int m = 0; m < M; ++m) {
    int d = dD(engine);
    int sv = t[d], tx = 0;
    for(int T = 1; T <= 26; ++T) if(T != sv) {
      t[d] = T;
      int new_ans = score();
      if(new_ans > ans) { ans = new_ans; tx = T; }
    }
    if(tx == 0) t[d] = sv;
    else t[d] = tx;
  }
  for(int ti: t) std::cout << ti << "\n";
  
  return 0;
}


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

typedef unsigned long long int ULLI;


int main()
{
	ULLI sum = 0;
	int k;
	int count = 0;
	char c;

	while ((c = getchar()) != '\n') {
		sum += c - '0';
	}




	if (sum % 9 == 0)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 1532
($%,@_)=<>;(pop@_)=~$";map{push@{$`+~-$_*$%},$'+$_%3*$%for/ /..3}@_;@d[@q=$`]=3;map$d[$_]//=((push@q,$_),$d[$q]+1),@{$q=$_}for@q;print$d[$']/3-1

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

int n,c,a[410],b[410];
const long long mod=1e9+7;
long long dp[410][410],s[410][410];
inline long long ksm(long long x,long long y,long long mod)
{
	long long res=1;
	while(y)
	{
		if(y&1)
		res=(res*x)%mod;
		x=x*x%mod;
		y>>=1;
	}
	return res;
}
int main()
{
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;++i)
	scanf("%d",&a[i]);
	for(int i=1;i<=n;++i)
	scanf("%d",&b[i]);
	for(int i=1;i<=400;++i)
	{
		for(int j=0;j<=400;++j)
		s[i][j]=(s[i-1][j]+ksm(i,j,mod))%mod;
	}
	for(int i=0;i<=c;++i)
	dp[1][c-i]=(s[b[1]][i]-s[a[1]-1][i]+mod)%mod;	
	for(int i=2;i<=n;++i)
	{
		for(int j=0;j<=c;++j)
		{
			for(int k=0;k<=j;++k)
			{
				dp[i][j-k]=(dp[i][j-k]+dp[i-1][j]*((s[b[i]][k]-s[a[i]-1][k]+mod)%mod))%mod;
			}
		}
	}
	printf("%lld\n",dp[n][0]);
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const ll mod = 1e9+7;
ll n;

int main() {
    cin >> n;
    vector<ll> A(n, 0);
    for(int i = 0; i < n; ++i) {
        cin >> A.at(i);
    }

    vector<ll> zero(65, 0);
    vector<ll> nzero(65, 0);

    for(int i = 0; i < n; ++i) {
        for(ll j = 0; j < 63; ++j) {
            if(A.at(i)&((ll)1<<j)) {
                nzero.at(j)++;
            }else {
                zero.at(j)++;
            }
        }
    }

    ll ans = 0;
    ll now = 1;
    for(int i = 0; i < 63; ++i) {
        ll next = nzero.at(i)*zero.at(i);
        next %= mod;
        next *= now;
        next %= mod;
        now *= (ll)2;
        now %= mod;
        ans += next;
        ans %= mod;
        // cout << "i " << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560