akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

#define MAX_N 100000

vector<vi> g(MAX_N);
vi used(MAX_N,-1);
bool x;
void dfs(int now){
    rep(i,g[now].size()){
        int ne = g[now][i];
        if(used[ne]==used[now])x = false;
        if(used[ne]==-1){
            used[ne] = 1 - used[now];
            dfs(ne);
        }
    }
}

int main(void) {
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int u, v;
        cin >> u >> v;
        u--,v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    ll a=0,b=0,c=0;
    rep(i,n)if(used[i]==-1){
        used[i] = 0;
        if(g[i].size()==0){
            a++;
        }else{
            x = true;
            dfs(i);
            if(x)b++;
            else c++;
        }
    }
   // cout << a << " " << b << " " << c << endl;
    cout << 2*b*b + 2*b*c + c*c + a*a + 2*a*(n-a) << endl;
}


Measured memory_bytes: 9984
#include <algorithm>
#include <cstring>
#include <utility>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define sub(x, y, t) ((x) < (y) ? (x) - (y) + t : (x) - (y))
#define mp std::make_pair
#define pb std::push_back
using std::set; 
using std::map; 
using std::pair; 
using std::vector; 
using std::string; 
using std::priority_queue; 
int n, k, t, x[100005], y[100005], cnt[2005]; 
char c[100005]; 
int main()
{
	// freopen("ARC089-D.in", "r", stdin); 
	scanf("%d%d", &n, &k); 
	t = k << 1; 
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d %c", x + i, y + i, c + i); 
		x[i] %= t; 
		y[i] %= t; 
	}
	int ans = 0; 
	for (register int i = 0; i < t; i++)
	{
		int cur = 0; 
		memset(cnt, 0, sizeof(cnt)); 
		for (register int j = 0; j < n; j++)
		{
			int f = (sub(x[j], i, t) < k); 
			if (f ^ (y[j] < k))
				cur += c[j] == 'B'; 
			else
				cur += c[j] == 'W'; 
			cnt[y[j]] += (f ^ (c[j] == 'W')) ? 1 : -1; 
		}
		for (register int j = 0; j < t; j++)
		{
			ans = std::max(ans, cur); 
			cur += cnt[j] - cnt[(j + k) % t]; 
		}
	}
	printf("%d\n", ans);
	return 0; 
}

Measured memory_bytes: 1024
num = raw_input().strip().split(" ")
num = map(lambda x : int(x), num)

chair = num[0] - num[2]
cnt = 0
while True:
    if (chair - (num[1]+ num[2])) >=0:
        cnt += 1
        chair -= (num[1]+num[2])
    else:
        break
print(str(cnt))

Measured memory_bytes: 2568
#include <cstdio>

using namespace std;

const int mod = 1000000007;
int a[21][21];
int dp[22][1 << 21];

int main() {
    int n, i, j, k;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    
    dp[0][0] = 1;
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < (1 << n); j++) {
            if (dp[i][j] == 0) continue;
            
            for (k = 0; k < n; k++) {
                if (a[i][k] == 0 || ((j >> k) & 1)) continue;
                
                dp[i + 1][j | (1 << k)] += dp[i][j];
                if (dp[i + 1][j | (1 << k)] >= mod) dp[i + 1][j | (1 << k)] -= mod;
            }
        }
    }
    
    printf("%d\n", dp[n][(1 << n) - 1]);
    
    return 0;
}


Measured memory_bytes: 161920
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

template<typename T> T mo(T x, T y) { x %= y; return x <= 0 ? x + y : x; }

const int MX = 5007;
const ll INF = 1e18;

ll f[MX][MX];
int a[MX];

int main() {
#ifdef FASTIO
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
    int n, A, B;
    cin >> n >> B >> A;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n + 1; j++) {
            f[i][j] = INF;
        }
    }
    f[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            int x = a[i + 1];
            if (x < j) {
                f[i + 1][j] = min(f[i + 1][j], f[i][j] + A);
            } else {
                f[i + 1][x] = min(f[i + 1][x], f[i][j]);
                f[i + 1][j] = min(f[i + 1][j], f[i][j] + B);
            }
        }
    }
    ll ans = INF;
    for (int i = 0; i <= n; i++) {
        ans = min(ans, f[n][i]);
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 195968
program t
implicit none
integer(16)::N
integer(16)::ANS
integer(16)::i
read*,N
ANS=huge(ANS)
do i=1,int(sqrt(real(N)),16)
  if((N/i)*i==N)ANS=min(ANS,i+N/i-2)
end do
print"(i0)",ANS
end program t

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

int main() {
  for (int h, w; cin >> h >> w;) {
    if (h == 0 && w == 0) break;
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++)
        if ((i + j) % 2 == 0)
          cout << "#";
        else
          cout << ".";
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 3100
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

vector<vector<int>>flag((6000), vector<int>(1 << 9));
vector<vector<pair<double,double>>>memo((6000),vector<pair<double,double>>(1<<9));
pair<double,double>  operator+(const pair<double, double>&l, const pair<double, double>&r) {
	return make_pair(l.first+r.first,l.second+r.second);
}

 pair<double,double> solve(const int a_win,const vector<int>&as, const vector<int>&bs, bitset<9>a_used, bitset<9>b_used) {
	int a_id=a_win+500*a_used.count()+500;
	int b_id=b_used.to_ulong();
	if(flag[a_id][b_id])return memo[a_id][b_id];
	else{
		flag[a_id][b_id]=true;
		pair<double,double> sum;
		int num=0;
		for (int a_next = 0; a_next < 9; ++a_next) {
			for (int b_next = 0; b_next < 9; ++b_next) {
				if (!a_used[a_next] && !b_used[b_next]) {
					a_used[a_next]=true;
					b_used[b_next]=true;
					int next_a_win=a_win;
					if (as[a_next] > bs[b_next]) {
						next_a_win+=as[a_next]+bs[b_next];
					}
					else {
						next_a_win-=as[a_next]+bs[b_next];
					}
					sum=sum+solve(next_a_win,as,bs,a_used,b_used);
					a_used[a_next]=false;
					b_used[b_next]=false;
					num++;
				}
			}
			if(!a_used[a_next])break;
		}

		if (num == 0) {
			if (a_win == 0) {
				return memo[a_id][b_id]=make_pair(0,0);
			}
			else if (a_win > 0) {
				return memo[a_id][b_id]=make_pair(1,0);
			}else{
				return memo[a_id][b_id]=make_pair(0,1);
			}
		}else{
			return memo[a_id][b_id]=make_pair(sum.first/num,sum.second/num);
		}
		
	}
}
int main() {
	int T;cin>>T;
	while (T--) {
		for (int i = 0; i < (6000); ++i) {
			for (int j = 0; j < (1 << 9); ++j) {
				flag[i][j]=false;
			}
		}
		vector<int>as,bs;
		for (int i = 0; i < 2; ++i) {
			for (int j = 0; j < 9; ++j) {
				int c;cin>>c;
				if(i)bs.emplace_back(c);
				else as.emplace_back(c);
			}
		}
		bitset<9>bs_a,bs_b;
		int a_win=0;
		auto  per=solve(a_win,as,bs,bs_a,bs_b);
		cout<<per.first<<" "<<per.second<<endl;
	}
	return 0;
}

Measured memory_bytes: 63052
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
    vector<string> s(3);
    rep (i, 3) cin >> s[i];

    vector<int> cur(3, 0);
    
    vector<int> sz(3);
    rep (i, 3) sz[i] = s[i].size();
    
    int now = s[0][0] - 'a';
    cur[0]++;
    while (1) {
        if (cur[now] == sz[now]) {
            cout << (char)(now + 'A') << endl;
            return 0;
        }
        cur[now]++;
        now = s[now][cur[now] - 1] - 'a';
    }

    return 0;
}


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

int main() {
    ll n, m;
    string s;
    cin >> n >> m >> s;

    reverse(all(s));

    vl ans;
    ll now = 0;  // いまいるマス
    while(1) {
        if(now + m >= n) {
            ans.pb(n - now);
            break;
        }
        for(ll i = m; i >= 0; i--) {
            if(i == 0) {
                out(-1);
                re0;
            }
            if(s[now + i] == '0') {
                ans.pb(i);
                now += i;
                break;
            }
        }
    }
    
    reverse(all(ans));

    rep(i, ans.size()) {
        cout << ans[i] << " ";
    }
    
    re0;
}

Measured memory_bytes: 1528
import scala.io.StdIn.readLine

object Main {
  def getSubArea(hd:Int,stack2:List[(Int,Int)],subarea:Int):List[(Int,Int)] = {
    if(stack2.length==0) (hd,subarea)::stack2
    else {
      stack2 match {
        case hd2::tl2 =>
          if(hd2._1<=hd) (hd,subarea)::stack2
          else {
            getSubArea (hd,tl2,subarea+hd2._2)
          }
        case _ => throw new Exception("unexpected")
      }
    }
  }

  def getArea(stack:List[Int],stack2:List[(Int,Int)],area:Int,s:String,i:Int):(Int,List[(Int,Int)]) = {
    if(i==s.length) (area,stack2)
    else {
      if(s(i) == '\\') getArea(i::stack,stack2,area,s,i+1)
      else if(s(i) == '/' && stack.length!=0) {
        stack match {
          case hd::tl =>
            getArea(tl,getSubArea(hd,stack2,i-hd),area+i-hd,s,i+1)
          case _ => throw new Exception("unexpected")
        }
      } else getArea(stack,stack2,area,s,i+1)
    }
  }

  def main(args:Array[String]) = {
    val s = readLine
    val n = getArea(Nil,Nil,0,s,0)
    println(n._1)
    print(n._2.length)
    if(n._2.length>0) println(" " + n._2.reverse.map(_._2).mkString(" "))
    else println
  }
}

Measured memory_bytes: 44984
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define INFLL (1LL << 60)
#define INF (1 << 30)
using namespace std;
typedef long long ll;

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

struct Edge {
	int fromX, fromY, toX, toY, cost;
	Edge(int fx, int fy, int tx, int ty, int c) {
		fromX = fx; fromY = fy; toX = tx; toY = ty; cost = c;
	}
};
using Pair = pair<int, int>;
using Graph = map<Pair, vector<Edge>>;

//コストの小さい辺から探索する。探索済みの頂点は探索しない。
//※dijkstraの場合は、累積コストの小さい辺を探索する。全域木にする必要がない。
ll prim(Graph& g, Pair start) {
	map<Pair, bool> used;
	using CostPair = pair<ll, Pair>;
	priority_queue<CostPair, vector<CostPair>, greater<CostPair>> pq;
	pq.push(CostPair(0, start));

	ll sumcost = 0;
	while (!pq.empty()) {
		CostPair cp = pq.top(); pq.pop();
		ll c = cp.first; Pair v = cp.second;
		if (used[v]) continue;
		used[v] = true;
		sumcost += c;
		for (Edge e : g[v]) {
			pq.push(CostPair(e.cost, Pair(e.toX, e.toY)));
		}
	}
	return sumcost;
}
int main()
{
	int N; cin >> N;
	vector<Pair> P(N), xy(N), yx(N);
	rep(i, N) {
		int x, y; cin >> x >> y;
		P[i].first = x; P[i].second = y;
		xy[i].first = x; xy[i].second = y;
		yx[i].first = x; yx[i].second = y;
	}
	sort(xy.begin(), xy.end());
	sort(yx.begin(), yx.end(), [](Pair a, Pair b) {
		return a.second < b.second;
		});

	Graph g;
	for (int i = 0; i < N - 1; ++i) {
		int i0x, i0y, i1x, i1y;
		i0x = xy[i].first;
		i0y = xy[i].second;
		i1x = xy[i + 1].first;
		i1y = xy[i + 1].second;
		g[xy[i]].emplace_back(Edge(i0x, i0y, i1x, i1y, i1x - i0x));
		g[xy[i + 1]].emplace_back(Edge(i1x, i1y, i0x, i0y, i1x - i0x));

		i0x = yx[i].first;
		i0y = yx[i].second;
		i1x = yx[i + 1].first;
		i1y = yx[i + 1].second;
		g[yx[i]].emplace_back(Edge(i0x, i0y, i1x, i1y, i1y - i0y));
		g[yx[i + 1]].emplace_back(Edge(i1x, i1y, i0x, i0y, i1y - i0y));
	}
	cout << prim(g, Pair(xy[0].first, xy[0].second)) << endl;
	return 0;
}


Measured memory_bytes: 30220
#include <bits/stdc++.h>
using namespace std;
const int N = 22 , OO = 0x3f3f3f3f, M = 1LL << 21 , MOD = 1e9 + 7;
typedef long long ll ;
int n ;
int grid[N][N];
ll mem[N][M + 2];
ll solve(int idx , int mask){
    if(idx == n)
        return 1;
    ll &ret = mem[idx][mask];
    if(~ret)
        return ret;
     ret = 0;
    for(int i = 0 ; i< n; ++i){
        if(grid[idx][i] && (mask & (1LL << i)) == 0){
            ret+=(solve(idx+ 1 , mask|(1LL << i)) % MOD);
        }
    }
    return ret % MOD;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem , -1 , sizeof mem);
    bool f = 1;
    cin >> n;
    for(int i = 0; i < n ; ++i) {
        bool ans = 0 ;
        for(int j = 0 ; j < n ; ++j){
            cin >> grid[i][j];
            if(grid[i][j]) ans = 1;
        }
        if(f == 1 && ans ==0){
            f = 0;
        }
    }
    if(!f) cout << 0;
    else
    cout << solve(0 , 0);
}


Measured memory_bytes: 360704
#include<stdio.h>
 
int main(void){

  int x,a,b,c,d;
  
  scanf("%d%d%d",&x,&a,&b);
  
  c=x-a;
  d=c/b;
  
  printf("%d\n",c-b*d);
   
  return 0;
}

Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
using namespace std;

int a[110],preo[110],ino[110];
vector <int> posto;
int pos;
void reco(int l,int r)
{
	if(l>=r)return;
	int root=preo[pos++];
	int i;
	for(i=0;ino[i]!=root;i++);
	reco(l,i);
	reco(i+1,r);
	posto.push_back(root);
}

int main()
{
	int n;cin>>n;
	for(int i=0;i<n;cin>>preo[i++]);
	for(int i=0;i<n;cin>>ino[i++]);
	pos=0;
	reco(0,n);
	for(int i=0;i<n;i++)
	{
		if(i)cout<<" ";
		cout<<posto[i];
	}
	cout<<endl;
	return 0;
}

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

int main() {
	int a,b;
  cin>>a>>b;
  
  if(b%a==0)cout<<a+b<<endl;
  else cout<<b-a<<endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
using namespace std;

typedef long long ll;
ll MOD = 1e9+7;
ll bur[51];
ll pat[51];

//レベルlのバーガーをちょうどすべて食べられるか
bool allbug(int l,ll x)
{
	if(x>=bur[l])
		return true;
	else
		return false;
}

//どのバーガーの2層目まで到達するか
int bugbug(int l,ll x)
{
	if(x>=bur[l-1])
		return l;
	else
		return bugbug(l-1,x-1);
}
int main()
{
	int n;
	ll x;
	ll ans=0;
	cin>>n>>x;
	bur[0]=1;
	pat[0]=1;
	for(int i=1;i<51;i++)
	{
		bur[i]=bur[i-1]*2+3;
		pat[i]=pat[i-1]*2+1;
	}
	int l=n;
	int pl=n;
	while(x>0)
	{
		cerr<<l<<" "<<x<<endl;
		if(l>=x)
		{
			break;
		}
		if(allbug(l,x))
		{
			cerr<<"all done"<<endl;
			ans+=pat[l];
			x-=bur[l];
			x-=pl-l;
			pl=l;
			continue;
		}
		l=bugbug(l,x);
		x-=pl-(l-1);
		x-=bur[l-1];
		ans+=pat[l-1];
		if(x<=0)
			break;
		x--;
		ans++;//真ん中のpat
		l--;//レベルlのバーガーの2層目で止まるので必然的にその後調べるのはレベルl未満
		pl=l;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define GYOU_MAX 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define s_pri(str) printf("%s\n",str);
#define PRINT(str) printf(#str "\n")
#define v_pri(val) printf("%d\n",val);
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define pi acos(-1.0)
#define sca(x) scanf("%d",&x);

typedef long long int ll;

/*
puts("aa");
//*/



int main(void) {


	

	int H, A;
	sca(H);
	sca(A);

	int count = 0;
	while (H> 0) {
		H -= A;
		count++;
	}

	v_pri(count);


	

	return 0;
}


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

int main() {
  int k, t;
  cin>>k>>t;
  int max_a = 0;
  for (int i=0; i<t; i++) {
    int a;
    cin>>a;
    max_a = max(max_a, a);
  }
  if ((k + 1) / 2 >= max_a) {
    cout<<0<<endl;
  } else {
    int ans = k - (k - max_a) * 2 - 1;
    cout<<ans<<endl;
  }

}

Measured memory_bytes: 256
#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<ll, ll>;
const long double PI = acos(-1.0L);
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; }

// auto mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
      if ((x += a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator-=(const mint a) {
      if ((x += mod-a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t>>1);
      a *= a;
      if (t&1) a *= *this;
      return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int n;
vector< vector<int> > graplist(100100, vector<int>());
vector< vector<mint> > dp;

mint dfs(int now, int pre) {
    for(auto to : graplist.at(now)) {
        if(to != pre) {
            dp[now][1] *= dfs(to, now);
            dp[now][0] *= dp[to][1];
        }
    }
    return dp[now][1]+dp[now][0];
}

int main() {
    cin >> n;
    for(int i = 0; i < n-1; ++i) {
        int x, y; cin >> x >> y;
        x--; y--;
        graplist.at(x).emplace_back(y);
        graplist.at(y).emplace_back(x);
    }
    dp.assign(n, vector<mint>(2, 1));

    cout << dfs(0, -1) << endl;
}

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

signed main(void)
{
	int n, cnt;
	cin >> n;
	vector<int> a(n);
	long long sum[n];
	bool flag[n];

	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	rep(i, n) sum[i] = a[i];
	rep(i, n - 1) sum[i + 1] += sum[i];
	rep(i, n) flag[i] = true;
	cnt = 0;
	rep(i, n - 1)
	{
		if (sum[i] * 2 < a[i + 1])
			flag[i] = false;
	}
	for(int i = n - 1; i >= 0; i--)
	{
		if (flag[i])
			cnt++;
		else
			break;
	}
	cout << cnt << endl;
	return 0;
}


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

const int _ = 1e5 + 7 , MOD = 998244353;
struct Edge{int end , upEd;};
int pw[300003] , N;

namespace graph3{
	Edge Ed[_ << 1]; int head[_] , cntEd , M , val[_];
	void addEd(int a , int b){Ed[++cntEd] = (Edge){b , head[a]}; head[a] = cntEd;}
	void input(){cin >> M; for(int i = 1 ; i <= M ; ++i){int x , y; cin >> x >> y; addEd(x , y); addEd(y , x);}}

	bool vis[_] , ban[_];
	void calc(){
		for(int i = 0 ; i < 512 ; ++i){
			memset(ban , 0 , sizeof(ban));
			for(int j = N ; j ; --j)
				if(!vis[j] && !ban[j]){
					val[i] = (val[i] + pw[j]) % MOD; vis[j] = 1;
					for(int p = head[j] ; p ; p = Ed[p].upEd) ban[Ed[p].end] = 1;
				}
		}
	}
}

namespace graph2{
	Edge Ed[_ << 1]; int head[_] , cntEd , M , val[_] , vl[_]; bool table[1003][1003];
	void addEd(int a , int b){Ed[++cntEd] = (Edge){b , head[a]}; head[a] = cntEd;}
	void input(){cin >> M; for(int i = 1 ; i <= M ; ++i){int x , y; cin >> x >> y; addEd(x , y); addEd(y , x);}}

	bool vis[_] , ban[_];
	void calc(){
		vector < int > pot;
		for(int i = 0 ; i < 512 ; ++i){
			memset(ban , 0 , sizeof(ban)); int sum = 0;
			for(int j = N ; j ; --j)
				if(!vis[j] && !ban[j]){
					sum = (sum + pw[j]) % MOD; vis[j] = 1;
					for(int p = head[j] ; p ; p = Ed[p].upEd) ban[Ed[p].end] = 1;
				}
			pot.push_back(sum);
		}
		for(int i = 0 ; i < 512 ; ++i)
			for(int j = 0 ; j < 512; ++j)
				val[i] = (val[i] + 1ll * pot[j] * graph3::val[i ^ j]) % MOD;
	}
}

namespace graph1{
	Edge Ed[_ << 1]; int head[_] , cntEd , M;
	void addEd(int a , int b){Ed[++cntEd] = (Edge){b , head[a]}; head[a] = cntEd;}
	void input(){cin >> M; for(int i = 1 ; i <= M ; ++i){int x , y; cin >> x >> y; addEd(x , y); addEd(y , x);}}

	bool vis[_] , ban[_];
	void calc(){
		vector < int > pot;
		for(int i = 0 ; i < 512 ; ++i){
			memset(ban , 0 , sizeof(ban)); int sum = 0;
			for(int j = N ; j ; --j)
				if(!vis[j] && !ban[j]){
					sum = (sum + pw[j]) % MOD; vis[j] = 1;
					for(int p = head[j] ; p ; p = Ed[p].upEd) ban[Ed[p].end] = 1;
				}
			pot.push_back(sum);
		}
		int sum = 0;
		for(int i = 0 ; i < 512 ; ++i)
			sum = (sum + 1ll * pot[i] * graph2::val[i]) % MOD;
		cout << sum;
	}
	
}

int main(){
	cin >> N; pw[0] = 1; pw[1] = (long long)1e18 % MOD;
	for(int i = 1 ; i <= 3 * N ; ++i) pw[i] = 1ll * pw[i - 1] * pw[1] % MOD;
	graph1::input(); graph2::input(); graph3::input();
	graph3::calc(); graph2::calc(); graph1::calc(); 
	return 0;
}


Measured memory_bytes: 9984
from collections import defaultdict
from bisect import bisect_left

N, M = map(int, input().split())
A = []
B = defaultdict(list)

for i in range(M):
    p, y = map(int, input().split())
    A.append([p, y])
    B[p].append(y)

for key in B.keys():
    B[key].sort()

for a in A:
    print("%06d%06d" % (a[0], bisect_left(B[a[0]], a[1])+1))

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

int main() {
  
	int K, X;
	cin >>K >>X;
	
	int bottom, top;
	
	bottom=X-K+1;
	top=X+K-1;
	
	for(int i=0; i<K*2-1; i++){
		
		cout <<bottom <<" ";
		bottom++;
		
	}
	
	cout <<endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cmath>
#include <set>
#include <bitset>
#include <limits>

using namespace std;

#define ll long long

int main(void){
    int x, n;
    cin >> x >> n;

    set<int> p;
    for(int i = 0;i < n;++i){
        int a;
        cin >> a;
        p.insert(a);
    }

    int ans;
    if(p.find(x) == p.end()){
        ans = x;
    }else{
        for(int i = 1;;++i){
            ans = x - i;
            if(p.find(ans) == p.end()){
                break;
            }

            ans = x+i;
            if(p.find(ans) == p.end()){
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<map>
#include<vector>
using namespace std;


int main(){

    long long a, b, c;
    cin  >> a >> b >> c;

    if( c <= a || c <= b || c <= a+b || 4*a*b >= (c-a-b)*(c-a-b)){
        cout << "No" << endl;
    } else if( 4*a*b < (c-a-b)*(c-a-b) ){
        cout << "Yes" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))

int main()
{
	int n, k;
	string s;
	cin >> n >> k >> s;
	vector<int> nums;
	int now = 1;
	int cnt = 0;
	rep(i, 0, s.size() - 1)
	{
		if (s[i] == (char)(now + '0')) ++cnt;
		else
		{
			nums.push_back(cnt);
			now = 1 - now;
			cnt = 1;
		}
	}
	nums.push_back(cnt);
	if (nums.size() % 2 == 0)nums.push_back(0);
	int add = 2 * k;
	int ans = 0;
	vector<int> sum(nums.size() + 1);
	rep(i, 0, nums.size() - 1)
	{
		sum[i + 1] = sum[i] + nums[i];
	}
	for (int i = 0; i < nums.size(); i += 2)
	{
		int temp = 0;
		int left = i;
		int right = min(left + add, (int)nums.size() - 1);
		temp = sum[right + 1] - sum[left];
		ans = max(ans, temp);
	}
	cout << ans << endl;
}



Measured memory_bytes: 1272
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=4000+5,inf=1e18+1;
ll mod=924844033;

ll n;
ll ru[M],rv[M];
ll bu[M],bv[M];
ll h[M];
bool spc[M];
ll dis[M];
vll g[M],tr[M];
ll x,y;
ll par[M];
bool acc[M];

void dfs(ll x)
{
    for (ll y:tr[x])
    {
        if (par[x]==y) continue;
        par[y]=x;
        h[y]=h[x]+1;
        dfs(y);
    }
}

bool dis3(ll x,ll y)
{
    if (h[x]>h[y]) swap(x,y);
    if (h[x]==h[y])
        return par[x]==par[y];
    else if (h[y]-h[x]==1)
        return par[y]==x;
    else return par[par[y]]==x;
}

int main()
{
	ios::sync_with_stdio(0);
    cin >> n >> x >> y;
    x--;
    y--;
    For(i,1,n)
    {
        ll u,v;
        cin >> u >> v;
        u--;v--;
        ru[i]=u;
        rv[i]=v;
    }
    For(i,1,n)
    {
        ll u,v;
        cin >> u >> v;
        u--;v--;
        bu[i]=u;
        bv[i]=v;
        tr[u].PB(v);
        tr[v].PB(u);
    }
    par[y]=y;
    dfs(y);
    For(i,1,n)
    {
        if (dis3(ru[i],rv[i]))
        {
            g[ru[i]].PB(rv[i]);
            g[rv[i]].PB(ru[i]);
        }
        else
            spc[ru[i]]=spc[rv[i]]=1;        
    }
    queue<ll> qu;
    memset(dis,1,sizeof dis);
    qu.push(x);
    dis[x]=0;
    while (SZ(qu))
    {
        ll f=qu.front();
        qu.pop();
        //ER(f);ER(dis[f]);ER(h[f]);
        if (dis[f]>=h[f])
        {
            continue;
        }
        acc[f]=1;
        for (ll y:g[f])
        {
        //ER(y);ER(dis[y]);ER(h[y]);
            if (dis[y]>dis[f]+1)
            {
                
                dis[y]=dis[f]+1;
                qu.push(y);
            }
        }
    }
    ll res=0;
    For(i,0,n)
    {
        if (acc[i])
        {
            smax(res,h[i]);
            if (spc[i]) RET(-1);
        }
    }
    RET(2*res);
}    

Measured memory_bytes: 38784
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// solution 
use std::collections::HashMap;
#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut dic = HashMap::new();
    for &ai in a.iter() {
        let mut entry = dic.entry(ai).or_insert(0);
        *entry += 1;
    }

    let mut maxlength1 = 0;
    let mut maxlength2 = 0;
    for (a, count) in dic.into_iter() {
        if count < 2 {
            continue
        } else if a > maxlength1 {
            if count < 4 {
                maxlength2 = maxlength1;
                maxlength1 = a;
            } else {
                maxlength1 = a;
                maxlength2 = a;
            }
        } else if a > maxlength2 {
            maxlength2 = a;
        }
    }
    println!("{}", maxlength1*maxlength2);
}


Measured memory_bytes: 12540
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
const int maxn=1e5+5;
int i,j,n,m,k[maxn],ne[maxn],g[maxn],num;
int k1[maxn],ne1[maxn],g1[maxn],cnt,num1;
int d[maxn];
bool bz[maxn],bk;ll ans,s[3],size;
void add(int x,int y){
	ne[++num]=k[x],k[x]=num,g[num]=y;
	ne1[++num1]=k1[y],k1[y]=num1,g1[num1]=x;
}
void dfs(int x,int y){
	int i;
	bz[x]=1,s[d[x]=y]++;
	y=(y+1)%3;
	for(i=k[x];i;i=ne[i]){
		cnt++;
		int go=g[i];
		if (!bz[go]) dfs(go,y);else bk|=d[go]!=y; 
	}
	y=(y+1)%3;
	for(i=k1[x];i;i=ne1[i]){
		int go=g1[i];
		if (!bz[go]) dfs(go,y);else bk|=d[go]!=y; 
	}
}
int main(){
	n=read(),m=read();
	fo(i,1,m) {
		int x=read(),y=read();
		add(x,y);
	}num=0;
	fo(i,1,n) if (!bz[i]) {
		cnt=bk=s[0]=s[1]=s[2]=0,dfs(i,0);
		if (bk) {
			size=s[0]+s[1]+s[2],ans+=size*size;continue;
		}
		if (!s[0]||!s[1]||!s[2]){
			ans+=cnt;continue;
		}
		ans+=s[0]*s[1]+s[1]*s[2]+s[2]*s[0];
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 7808
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sum = 0;
		for (int i = a; i <= b; i++) {
			int c = 1;
			String s = String.valueOf(i);
			for (int j = 0; j < 5 / 2; j++) {
				if (s.charAt(j) != s.charAt(5 - j - 1)) {
					c = 0;
				}
			}
			if (c != 0) {
				sum++;
			}
		}
		System.out.println(sum);
		sc.close();
	}

}


Measured memory_bytes: 28756
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int N; cin >> N;
  map<string, int> S;
  for(int i = 0; i < N; i++) {
    string s; cin >> s;
    S[s]++;
  }
  int M; cin >> M;
  map<string, int> T;
  for(int i = 0; i < M; i++) {
    string s; cin >> s;
    T[s]++;
  }

  int imax = 0;
  for(auto& spair : S) {
    for(auto& tpair : T) {
      if(spair.first == tpair.first) {
        spair.second -= tpair.second;
      }
    }
    imax = max(imax, spair.second);
  }

  cout << imax << endl;
}


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

#define all(v) v.begin(), v.end()
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    string s; cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int compare_char(const void* left, const void* right)
{
	char *left_char = (char *)left;
	char *right_char = (char *)right;

	return strcmp(left_char, right_char);
}
int main(void)
{
	int n, count = 1;
	char kigou;
	scanf("%d", &n);
	char s[n][11];
	scanf("%c", &kigou);
	for (int i = 0; i < n; i++) {
		gets(s[i]);
	}
	qsort(s, n, sizeof(s[0]), compare_char);
	for (int i = 1; i < n; i++) {
		if (strcmp(s[i], s[i - 1]) != 0) {
			count++;
		}
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 5708
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <set>
#include <numeric>
using namespace std;
using ll = long long;
using ld = long double;

const ll MOD = 998244353;
const ll INF = 1e+9;
const ld PI = acos((long double)(-1));

#define no "no"
#define No "No"
#define NO "NO"
#define yes "yes"
#define Yes "Yes"
#define YES "YES"
#define next '\n'
#define sp " "
#define print(x) cout << (x) << endl;
#define rep(i, n) for(int (i) = (0); (i) < (n); (++i))
#define FOR(i, start, end) for(int (i) = (start); (i) < (end); (++i))
#define foreach(elem, _list) for(auto& (elem) : (_list))
#define view(_list) foreach(e, _list){ cout << e << sp; } cout << next
#define FAST ios::sync_with_stdio(false); cin.tie(nullptr)
#define size(s) (s).size()
#define ALL(vec) (vec).begin(), (vec).end()
#define pb(e) push_back(e)
#define EPS 0.00000001

int main() {
    FAST;

    map<ll, ll> mp;
    ll n;
    cin >> n;
    rep(i, n){
        int a; cin >> a;
        if(mp[a] == 0){
            mp[a]++;
        }else{
            mp[a] = 0;
        }
    }
    
    ll ans = 0;
    foreach(e, mp){
        ans += e.second;
    }

    print(ans);
}


Measured memory_bytes: 9676
def check(i):
	tot=k
	while(tot%i==0):
		tot//=i
	if(tot%i==1):
		setl.add(i)
import math
k=int(input())
setl = set()
setl.add(k); setl.add(k-1)
for x in range(2,int(math.sqrt(k))+1):
	check(x)
	check(k//x)
if(setl.__contains__(1)):
	setl.remove(1)
print(len(setl))

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


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

Measured memory_bytes: 3092
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define Maxn 800
#define Inf 0x3f3f3f3f
int h,w,k,dist[Maxn+5][Maxn+5],sx,sy,d[5]={0,1,0,-1,0},ans;
char s[Maxn+5][Maxn+5];
queue<pair<int,int> > q;
int mn(int a,int b){
	return a<b?a:b;
}
int Get(int i,int j){
	int tmp=(i+k-2)/k;
	tmp=min(tmp,(j+k-2)/k);
	tmp=min(tmp,(h-i+k-1)/k);
	tmp=min(tmp,(w-j+k-1)/k);
	return tmp;
}
int main(){
	ans=Inf;
	scanf("%d%d%d",&h,&w,&k);
	for(int i=1;i<=h;i++){
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=h&&!sx;i++){
		for(int j=1;j<=w&&!sx;j++){
			if(s[i][j]=='S'){
				sx=i;
				sy=j;
			}
		}
	}
	memset(dist,0x3f,sizeof(dist));
	dist[sx][sy]=0;
	q.push(make_pair(sx,sy));
	while(!q.empty()){
		int x=q.front().first,y=q.front().second;
		q.pop();
		if(dist[x][y]==k){
			continue;
		}
		for(int i=1;i<=4;i++){
			int cx=x+d[i-1],cy=y+d[i];
			if(cx<1||cy<1||cx>h||cy>w||dist[x][y]+1>=dist[cx][cy]||s[cx][cy]=='#'){
				continue;
			}
			dist[cx][cy]=dist[x][y]+1;
			q.push(make_pair(cx,cy));
		}
	}
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(dist[i][j]<Inf){
				ans=mn(ans,Get(i,j)+1);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n, 0);
    vector<int> order(n, 0), index(n, 0);

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

    reverse(a.begin(), a.end());
    for (int i = 0; i < n; ++i) {
        order[a[i] - 1] = i;
    }

    set<int> st;
    st.insert(-1);
    st.insert(n);

    for (int i = 0; i < n; ++i) {
        auto itr = st.lower_bound(order[i]);
        itr--;
        index[a[order[i]]] = *itr;
        st.insert(order[i]);
    }

    vector<ll> dp(n, 0);
    for (int i = 0; i < n; ++i) {
        int j = index[a[i]];
        if (j == -1) dp[i] = a[i] * (i + 1);
        else dp[i] = a[i] * (i - j) + dp[j];
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += dp[i];
    }

    cout << ans << endl;
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const long long mod = 1000000007;
char s[100005];
long long dp[2][13]= {0};
int main() {
    int num=0,j,k;
    int t=0;
    scanf("%s",s);
    int n = strlen(s);
    dp[1][0]=1;
    for(int i=0; i<n; ++i) {
        for(j=0; j<13; ++j) {
            dp[t][(j*10)%13]=dp[t^1][j];
        }
        t^=1;
        for(j=0; j<13; j++) {
            dp[t][j] = 0;
        }
//        for(int i=0;i<13;i++)
//            cout << dp[t^1][i] << " \n"[i==12];
        if(s[i]!='?') {
            num=s[i]-'0';
            for(j=0; j<13; j++) {
                dp[t][(j+num)%13]=dp[t^1][j];
            }
        } else {
            for(j=0; j<13; j++) {
                for(k=0; k<10; ++k) {
                    dp[t][(j+k)%13]=(dp[t][(j+k)%13]+dp[t^1][j])%mod;
                }
            }
        }
        t^=1;
        for(j=0; j<13; j++) {
            dp[t][j] = 0;
        }
//        for(int i=0;i<13;i++)
//            cout << dp[t^1][i] << " \n"[i==12];
    }
    cout << dp[t^1][5] << endl;
    return 0;
}


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  /* your code */
  NodePointer cur = nil->next;
  while( cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  /* your code */
  if ( t == nil ) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  /* your code */
  NodePointer t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  /* your code */
  deleteNode(listSearch(key));
}


void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;

  /* 

   your code 


  */
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' ) deleteFirst();
	else if ( com[6] == 'L' ) deleteLast();
      } else {
	delete(key); nd++; 
      }
      size--;
    }
  }

  printList();
  return 0;
}



Measured memory_bytes: 33036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pl;


int main(){
  string s,ans;
  cin>>s;

  if(s=="Sunny")
  ans="Cloudy";
  else if(s=="Cloudy")
  ans="Rainy";
  else
  ans="Sunny";

  cout<<ans<<endl;


}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES // for C++  
#include <cmath> 
using namespace std;
int main(){
	long n,min,max,sum;
	min=1000000;
	max=-1000000;
	sum=0;
	
	cin>>n;
	
	int a[n];
	
	for(int o=0;o<n;o++){
		cin>>a[o];
		
	}
	
	for(int i=0;i<n;i++){
		sum=sum+a[i];
		if(min>a[i]){
		min=a[i];}
		
		if(max<a[i]){
			max = a[i];

		}
	}
	cout<<min<<' '<<max<<' '<<sum<<endl;
	
	
}


Measured memory_bytes: 3136
#include <iostream>
#include <string>
using namespace std;
int main(){
  string A,B,C;
  cin >> A >> B >> C;
  if(A[A.size()-1] == B[0] && B[B.size()-1] == C[0]){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <stdio.h>
#include <string.h>
using namespace std;
#define MFOR(i,end) for(size_t i = 0, end_i = (end); i < end_i; ++ i)
 
int main()
{
	uint64_t A, B, C;
	std::cin >> A >> B >> C;
	if ((A % 2 == 0) || (B % 2 == 0) || (C % 2 == 0) ){
		std::cout << "0\n";
		return 0;
	}
 
	auto AB = A*B;
	auto BC = B*C;
	auto CA = C*A;
	const uint64_t& min_ = std::min({ AB, BC, CA });
	std::cout << min_ << "\n";
	return 0;
}

Measured memory_bytes: 512
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => {
  const x = parseInt(input.split(" ")[0]);
  const y = parseInt(input.split(" ")[1]);  
  const area = x * y;
  const perimeter = 2 * (x + y);
  console.log(area, + " " + perimeter);
});


Measured memory_bytes: 15284
N,M,X = map(int,input().split())
books = list()
for i in range(N):
    books.append(list(map(int,input().split())))

lis = ["0"*(N-len(format(i,"b")))+format(i,"b") for i in range(1,2**N)]

minimam = 10**9
##pattern
for i in lis:
    tmp = [0] *(M+1)
    flag = 0
    ##adds
    for j in range(len(i)):
        if i[j] == "1":
            for k in range(M+1):
                tmp[k] += books[j][k]
    for k in range(1,M+1):
        if tmp[k] < X:
            flag = 1
            break
    if flag == 0:
        minimam = min(minimam,tmp[0])

if minimam == 10**9:
    print(-1)
else:
    print(minimam)



Measured memory_bytes: 9348
#include<bits/stdc++.h>
using namespace std;
long long dp[100001];
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n,W;
    cin>>n>>W;
    for(int i=0;i<=100*1000;i++)
        dp[i]=W+1;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        int w,v;
        cin>>w>>v;
        for(int j=100*1000;v<=j;j--)
            dp[j]=min(dp[j],dp[j-v]+w);
    }
    int res=0;
    for(int i=1;i<=100*1000;i++)
        if(dp[i]<=W)
            res=i;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <cmath>
#include <climits>
#include <cstdint>
using namespace std;

inline namespace atcoder {
    template <typename T, size_t Depth>
    struct vector_helper { using type = vector<typename vector_helper<T, Depth - 1>::type>; };
    template <typename T>
    struct vector_helper<T, 0> { using type = T; };
    template <typename T, size_t Depth>
    using vector_t = typename vector_helper<T, Depth>::type;

    template <typename T> using vec = vector_t<T, 1>;
    template <typename T> using vvec = vector_t<T, 2>;
    template <typename T> using vvvec = vector_t<T, 3>;
}

int main() {
    constexpr int mod = 1000000000 + 7;

    int n; cin >> n;
    vec<int64_t> a(n);
    for (auto &e : a) cin >> e;

    vec<int64_t> sum(n, 0); sum[0] = a[0];
    for (int i = 0; i < n - 1; ++i) {
        sum[i + 1] = (sum[i] + a[i + 1]) % mod;
    }

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        auto subsum = sum.back() - sum[i];
        if (subsum < 0) {
            subsum += mod;
        }

        ans = (ans + ((a[i] * subsum) % mod)) % mod;
    }

    cout << ans << endl;
}



Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;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>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

struct UnionFind {
    vector< int > data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

struct info {
    int cost, first, second;

    bool operator<(const info &a) const { return a.cost < cost; }
};

signed main() {
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    vector<int> ans;
    for (int i = 0; i < S.length() - 1;) {
        int move = 0;
        for (int j = M; j >= 1; j--) {
            if (i + j >= S.length()) continue;
            if (S[i + j] == '0') {
                move = j;
                break;
            }
        }
        if (move == 0) {
            cout << -1 << endl;
            return 0;
        }
        ans.push_back(move);
        i += move;
    }
    reverse(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
    }
}


Measured memory_bytes: 1528
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <cmath>

using namespace std;

typedef unsigned long long ull;

vector<int> T;

struct State{
  int cost, state, zero;
  State(int _cost, int _state, int _zero){
    cost = _cost;
    state = _state;
    zero = _zero;
  }
  bool const operator < (State s) const{
    return s.cost < cost;
  }
};

set<int> S;
int cx, cy;
int s, g ;

int dijkstra(){
  int dx[] = {-1, 1, -3, 3};
  int cost[] = {cx, cx, cy, cy};

  int zero;
  int tmp = s;
  for(int i = 8 ; i >= 0 ; i--){
    if(tmp % 10 == 0){
      zero = i;
      break;
    }
    tmp /= 10;
  }
  
  priority_queue<State> que;
  que.push(State(0, s, zero));
  
  while(!que.empty()){
    State q = que.top(); que.pop();
    if(q.state == g) return q.cost;
    
    if(S.find(q.state) != S.end()) continue;
    S.insert(q.state);
    
    for(int i = 0 ; i < 4 ; i++){
      int pos = q.zero + dx[i];      
      if(pos < 0) pos += 9;
      if(pos >= 9) pos -= 9;
      int vv = q.state;
      vv /= T[pos];
      vv %= 10;
      
      int v = q.state;
      v -= T[pos] * vv;
      v += T[q.zero] * vv;
      
      que.push(State(q.cost + cost[i], v, pos));
    }
  }
}

int main(){
  for(int i = 1 ; i <= 100000000 ; i *= 10){
    T.push_back(i);
  }
  reverse(T.begin(), T.end());

  while(cin >> cx >> cy, cx | cy){
    S.clear();
    s = g = 0;
    int v;
    for(int i = 0 ; i < 9 ; i++){
      cin >> v;
      s *= 10;
      s += v;
    }
    for(int i = 0 ; i < 9 ; i++){
      cin >> v;
      g *= 10;
      g += v;
    }
    
    cout << dijkstra() << endl;
    
  }
  return 0;
}

Measured memory_bytes: 25432