akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

const int maxN = 2005, maxK = 10003;
pair<int, int> a[2][1000005];
string str[maxN];
char ans[maxK];
bitset<maxK> can[maxN];

int main() {
	ios::sync_with_stdio(false);cin.tie(0);
	int N, K; cin >> N >> K;
	for(int i = 1; i <= N; ++i) cin >> str[i];
	can[N + 1][0] = 1;
	for(int i = N; i >= 1; --i) can[i] = can[i + 1] | (can[i + 1] << str[i].length());
	int cnt[2] = {0, 0};
	for(int i = 1; i <= N; ++i) if((str[i].length() <= K) && can[i + 1][K - str[i].length()]) 
		a[0][++cnt[0]] = make_pair(i, 0);
	int nw = 0;
	//cout << cnt[0] << "********"<<endl; 
	for(int i = 1; i <= K; ++i) {
		char minn = 'z';
		cnt[nw] = min(cnt[nw], maxK);
		for(int j = 1; j <= cnt[nw]; ++j) {
			int t1 = a[nw][j].first, t2 = a[nw][j].second;
			minn = min(minn, str[t1][t2]);
		//	cout << t1 <<' ' << t2 << endl;
		}
		ans[i] = minn;
		//cout << (minn - 'a') << endl;
		int idx = 100000000;
		for(int j = 1; j <= cnt[nw]; ++j) {
			int t1 = a[nw][j].first, t2 = a[nw][j].second;
			if(minn != str[t1][t2]) continue;
			if(t2 == str[t1].length() - 1) idx = min(idx, t1 + 1);
			else {
				a[nw ^ 1][++cnt[nw ^ 1]] = make_pair(t1, t2 + 1);
			}
		}
		for(int j = idx; j <= N; ++j) {
			//cout <<minn<<endl; 
			if(str[j].length() + i <= K && can[j + 1][K - str[j].length() - i])
				a[nw ^ 1][++cnt[nw ^ 1]] = make_pair(j, 0);
		}
		cnt[nw] = 0;nw ^= 1; 
	}
	cout << ans + 1 << endl;
	return 0;
 }

Measured memory_bytes: 7552
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    ll N, K;
    cin >> N >> K;
    vector<int> a(N);
    rep(i, N){
        int num;
        cin >> num;
        num--;
        a[i] = num;
    }
    //ループの始まりを見つける
    map<int, int> m;
    int maxnum = 0;
    int nowpos = 0;
    rep(i, 500000){
        m[nowpos]++;
        maxnum = max(m[nowpos], maxnum);
        nowpos = a[nowpos];
        
    }
    int s_index = 0;
    for(auto x: m){
        if(maxnum == x.second){
            s_index = x.first;
            break;
        }
    }
    nowpos = 0;
    int f = -1, loop = 0;
    rep(i, N * 10){//1ループいくつか測定
         if(f != -1 && nowpos == s_index){
            loop = i - f;
            break;
        }else if(f == -1 && nowpos == s_index){
            f = i;
        }
        nowpos = a[nowpos];
        if(K == i + 1){
            cout << nowpos + 1 << endl;
            return 0;
        }
    }
    // cout << "loop " << loop << " s_index: " << s_index<< " K: " << K<< endl;
    if(loop == 0){
        nowpos = 0;
        rep(i, N){
            nowpos = a[nowpos];
            if(K == i + 1){
                cout << nowpos + 1 << endl;
                return 0;
            }
        }
        cout << nowpos + 1 << endl;
        return 0;
    }
    K -= f;
    K %= loop;
    nowpos = s_index;
    
    rep(i, K){
        nowpos = a[nowpos];
    }
    cout << nowpos + 1 << endl;
    
}

Measured memory_bytes: 13176
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N, T, A;
    io.read(N, T, A);
    vector<int> H(N);
    for(int i = 0; i < N; i++){
        io.read(H[i]);
    }
    int ans = 1;
    int m = abs(1000 * T - 6 * H[0] - 1000 * A);
    for(int i = 1; i < N; i++){
        int d = abs(1000 * T - 6 * H[i] - 1000 * A);
        if(d < m){
            m = d;
            ans = i + 1;
        }
    }
    cout << ans;
    return 0;
}

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

int main() 
{
    vector<vector<int>> v(3);
    vector<int> a(3);
    vector<int> b(3);
    for (int i=0; i<3; i++)
        for (int j=0; j<3; j++)
        {
            int c;
            cin >> c;
            v[i].push_back(c);
        }
    bool y = true;
    for (int i=0; i<=v[0][0]; i++)
    {
        a[0] = i;
        b[0] = v[0][0] - i;
        for (int j=0; j<=v[1][1]; j++)
        {
            a[1] = j;
            b[1] = v[1][1] - j;
            for (int k=0; k<=v[2][2]; k++)
            {
                y = true;
                a[2] = k;
                b[2] = v[2][2] - k;
                for (int p=0; p<3; p++)
                {
                    for (int q=0; q<3; q++)
                    {
                        if (a[p]+b[q] != v[p][q])
                        {
                            y = false;
                            break; 
                        }
                    }
                    if (y == false)
                        break;
                }
                if (y == true)
                    return cout << "Yes", 0;
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define num(a) a-'0'
#define maxself(a,b) if(b>a)a=b
#define minself(a,b) if(b<a)a=b;
#define debug(x) cout<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"	
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	int n,m;
	cin>>n>>m;
	set<int> se;
	int p;
	string s;
	int wa=0;
	int ac=0;
	vi wac(n+1,0);
	while(m--){
		cin>>p>>s;
		if(s=="WA" && se.find(p)==se.end()){
			wac[p]++;
		}
		else{
			if(se.find(p)==se.end()){
				ac++;
				se.insert(p);
				wa+=wac[p];
			}
		}
	}
	cout<<ac<<" "<<wa<<ln;
}

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

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

string s[100];
int h,w;
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};

void bfs(int x,int y,char a)
{
	queue<pair<int,int>>Q;
	Q.push(make_pair(x,y));
	while(!Q.empty())
	{
		pair<int,int>b=Q.front();Q.pop();
		if(s[b.first][b.second]==a)s[b.first][b.second]='.';
		else continue;
		for(int r=0;r<4;r++)
		{
			int sx=b.first+dx[r];
			int sy=b.second+dy[r];
			if(sx<0||sy<0||sx>=h||sy>=w||s[sx][sy]=='.')continue;
			Q.push(make_pair(sx,sy));
		}
	}
	return;
}

int main()
{
	while(cin>>h>>w,h){
	for(int i=0;i<h;i++)cin>>s[i];
	int c=0;
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			if(s[i][j]!='.')bfs(i,j,s[i][j]),c++;
		}
	}
	cout<<c<<endl;}
	return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin>>N>>S;
  for(int i=0;i<S.size();i++){
    S.at(i)=char((S.at(i)-65+N)%26+65);
  }
  cout<<S<<endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_N = 100;

int N;

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

    cin >> N;

    string s;

    cin >> s;

    int nln = 0;
    int nrn = 0;
    int cln = 0;
    int crn = 0;

    for (int i = 0; i < N; i++) {
        if (s[i] == ')') {
            if (cln > 0) {
                cln--;
            } else {
                nln++;
            }
        } else {
            cln++;
        }
    }

    for (int i = N - 1; i >= 0; i--) {
        if (s[i] == '(') {
            if (crn > 0) {
                crn--;
            } else {
                nrn++;
            }
        } else {
            crn++;
        }
    }

    cout << string(nln, '(') + s + string(nrn, ')') << "\n";

    return 0;
}

Measured memory_bytes: 3568
N,W = map(int,input().split())
VW = [list(map(int,input().split())) for _ in range(N)]

#容量jのとき商品i個目までで入れられる価値の最大値
#i-1個目まで分かっててi個目を詰めるとき
#容量j-wのときの価値+v  or  容量jのときの価値  or  i個目容量j-wのときの価値

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(1,N+1):
  for j in range(W+1):
    v = VW[i-1][0]
    w = VW[i-1][1]
    
    if j >= w:
      dp[i][j] = max(dp[i-1][j-w]+v,dp[i-1][j],dp[i][j-w]+v)
    else:
      dp[i][j] = dp[i-1][j]
      
print(dp[-1][-1])


Measured memory_bytes: 41888
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>

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

using namespace std;

#define MAX 5010
int dp[MAX][4];

void compute(int n,vector<int> &p) {
  rep(i,n+2) rep(j,4) dp[i][j] = INT_MAX;
  dp[0][0] = 0;
  rep(i,n+1) {
    rep(rem,4) {
      if( dp[i][rem] == INT_MAX ) continue;
      REP(use,rem,4) {
	int nrem = max(0,((i<n)?p[i]:0) - use);
	int cost = 0;
	if( 1   <= i ) cost += use;
	if( i+1 <= n ) cost += use;
	dp[i+1][nrem] = min(dp[i+1][nrem],dp[i][rem]+cost);
      }
    }
  }
  int mini = INT_MAX;
  rep(i,4) mini = min(mini,dp[n+1][i]);
  cout << mini << endl;
}

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  compute(n,p);
  return 0;
}

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

#define INF 2e+9

int N;
vector<int> a;

int LIS() {
  vector<long> dp(N,INF);
  for(int i=0; i<N; i++){
    *lower_bound(dp.begin(), dp.end(), a[i]+1) = a[i];
  }
  return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}

int main() {
  cin >> N;
  a.resize(N);
  for(int i=0; i<N; i++){
    cin >> a[N-1-i];
  }
  cout << LIS() << endl;
}

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

vector<int> v;

int main(){
	int n;
	cin >> n;
	v.resize(n);
	for(int i = 0; i < n; i++) cin >> v[i];
	sort(v.begin(), v.end());

	int ans = 0;
	int cnt = 1;
	for(int i = 1; i < n; i++){
		if(v[i] == v[i-1]) cnt++;
		else {
			if(cnt % 2 == 1) ans++;
			cnt = 1;
		}
		if(i == n-1) if(cnt % 2 == 1) ans++;
	}

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


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

int main() {
    int H, W;  cin >> H >> W;
    vector<vector<char>> grid(H + 1, vector<char>(W + 1));
    for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) cin >> grid[i][j];

    int i = 0, j = 0;
    bool ok = true;
    while (true) {
        grid[i][j] = '.';
        if (i == H - 1 && j == W - 1) break;
        if (grid[i + 1][j] == '#') ++i;
        else if (grid[i][j + 1] == '#') ++j;
        else {
            ok = false;
            break;
        }
    }

    for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) {
        if (grid[i][j] == '#') ok = false;
    }

    cout << (ok ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(M)]

from collections import deque

load = [deque([]) for _ in range(N)]
ans_list = [-1]*N
q = deque([])
flag = [False]*N

for a,b in AB:
  a -= 1
  b -= 1
  load[a].append(b)
  load[b].append(a)
  
q.append(0)
flag[0] = True
while len(q)!=0:
  x = q.popleft()
  y = load[x]
  for i in y:
    if flag[i]:
      continue
    else:
      flag[i] = True
      q.append(i)
      ans_list[i] = x
      
if -1 in ans_list[1:]:
  print('No')
else:
  print('Yes')
  for ans in ans_list[1:]:
    print(ans+1)

Measured memory_bytes: 124488
A = [list(map(int, input().split())) for i in range(3)]
N = int(input())
m = [[0]*3 for i in range(3)]
ans,l,r = 0,0,0
for _ in range(N):
  b = int(input())
  for i in range(3):
    for j in range(3):
      if A[i][j]==b:
        m[i][j]=1
                
for i in range(3):
  t = sum(m[i])
  l += m[i][i]
  y = 0
  for j in range(3):
    y += m[j][i]
    if i+j == 2:
      r += m[i][j]
  if t==3 or y==3 or r==3 or l==3:
    ans=1

print('Yes' if ans else 'No')

Measured memory_bytes: 3064
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();				//入力数
		Set<String> Dic = new HashSet<>();
		for (int i = 0; i < N; i++) {
			String Command = scan.next();
			String str = scan.next();
			if (Command.equals("insert")) {
				Dic.add(str);
			} else {
				if (Dic.contains(str)) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
		scan.close();
	}
}




Measured memory_bytes: 253920
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 c = sc.nextInt();
	int d = sc.nextInt();

	for(int i = 0; i < 100; i++) {
		c -= b;
		if(c <= 0)
		break;
		a -= d;
		if(a <= 0)
		break;
	}
	if(c <= 0)
	System.out.println("Yes");
	else
	System.out.println("No");

	sc.close();
	}
}

Measured memory_bytes: 35660
s = input()
a = int(s[:2])
b = int(s[2:])
if a >= 1 and a <= 12:
  if b >= 1 and b <= 12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if b >= 1 and b <= 12:
    print('YYMM')
  else:
    print('NA')

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

def gcd(a, b):
    if a < b: return gcd(b, a)
    elif b > 0: return gcd(b, a % b)
    else:
        return a

l2r = [0] * N
tmp = 0
for i in range(N):
    l2r[i] = tmp
    tmp = gcd(tmp, A[i])

r2l = [0] * N
tmp = 0
for i in range(1, N + 1):
    r2l[-i] = tmp
    tmp = gcd(tmp, A[-i])
    
ans = 1
for i in range(N):
    tmp = gcd(l2r[i], r2l[i])
    if ans < tmp: ans = tmp

print(ans)

Measured memory_bytes: 14456
class RMQ:
    inf = 2147483647
    def __init__(self,n_):
        self.n_ = n_
        self.n = 1
        while self.n < n_: self.n*=2
        self.st = [self.inf]*(2*self.n-1)
    
    def update(self,k,x):
        k+=(self.n-1)
        self.st[k] = x
        while k >0:
            k = (k-1)//2
            self.st[k] = min(self.st[2*k+1],self.st[2*k+2])

    def search(self,a,b,k,l,r):
        if r<=a or b<=l :return self.inf
        if a<=l and r<=b:return self.st[k]
        L = self.search(a,b,k*2+1,l,(l+r)//2)
        R = self.search(a,b,k*2+2,(l+r)//2,r)
        return min(L,R)

    def query(self,a,b):
        return self.search(a,b,0,0,self.n)

def main():
    n,q = map(int,input().split())
    ST = RMQ(n)
    for _ in range(q):
        a,b,c = map(int,input().split())
        if a == 0:ST.update(b,c)
        else     :print (ST.query(b,c+1))

if __name__ == '__main__':
    main()




Measured memory_bytes: 8692
/* ex4-3
   Sagzar1993  */

#include <stdio.h>

int calcSnowDepth(int westHeight, int eastHeight); //プロトタイプ宣言

int main(void) {
    int westHeight, eastHeight; //２つの塔の埋もれていない部分の高さ
    int snowDepth; //求める雪の深さ

    scanf("%d %d", &westHeight, &eastHeight); //入力を受け取る

    snowDepth = calcSnowDepth(westHeight, eastHeight); //積雪の深さを計算

    printf("%d\n", snowDepth); //出力

    return 0;
}

int calcSnowDepth(int westHeight, int eastHeight){
    /*
    ２つの塔が西から数えてn, n+1(=eastTowerNum)番目とすると
    eastHeight - westHeight = (n+1)(n+2)/2 - n(n+1)/2 = n+1
    だから東側の塔の番号は埋もれていない部分の高さの差に等しい
    */
    int eastTowerNum = eastHeight - westHeight;

    //１からeastTowerNumまでの和が東側の塔の高さ
    int eastTowerHeight = eastTowerNum * (eastTowerNum + 1) / 2;

    //塔の高さからその雪に埋もれていない部分の高さを引き、積雪の深さを求める
    int snowDepth = eastTowerHeight - eastHeight;

    return(snowDepth); //積雪の深さを返す
}

Measured memory_bytes: 128
#include <cmath>
#include <iostream>

using namespace std;

int main() {
  long long X;
  cin >> X;
  long long balance = 100;
  for (int n = 1; n <= 3760; n++) {
    balance = (long long)(balance * 1.01);
    if (balance >= X) {
      cout << n << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3216
from collections import deque
h, w = map(int, input().split())
maze = []

for i in range(h):
    maze.append(list(input()))

move = [[-1, 0], [1, 0], [0, -1], [0, 1]]


def bfs(start: list):
    global h, w, maze
    length = [[-1 for _ in range(w)] for _ in range(h)]
    check = [[False for _ in range(w)] for _ in range(h)]
    check[start[0]][start[1]] = True
    queue = deque([start])
    res = -1
    while len(queue) > 0:
        [x, y, bx, by] = queue.popleft()

        length[x][y] = length[bx][by] + 1
        res = max(res, length[x][y])

        for p in move:
            next_x = x + p[0]
            next_y = y + p[1]
            if (next_x < 0)or(next_x == h)or(next_y < 0)or(next_y == w):
                continue
            if not check[next_x][next_y]:
                check[next_x][next_y] = True
                if maze[next_x][next_y] == ".":
                    queue.append([next_x, next_y, x, y])

    return res


ans = -1

for i in range(h):
    for j in range(w):
        if maze[i][j] == ".":
            ans = max(ans, bfs([i, j, i, j]))

print(ans)


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

int n;
string s;
int w[300010];
int e[300010];

int main () {

	cin >> n >> s;
	for (int i = 0; i < n; i ++) {
		if (i == 0) {
			if (s[i] == 'W') {
				w[i] ++;
			}
		}
		else {
			w[i] = w[i-1];
			if (s[i] == 'W') {
				w[i] ++;
			}
		}
	}
	
	for (int i = n-1; i >= 0; i --) {
		e[i] = e[i+1];
		if (s[i] == 'E') e[i] ++;
	}
	
	int mini = n;
	for (int i = 0; i < n; i ++) {
		int tren = 0;
		if (i != 0) tren += w[i-1];
		tren += e[i+1];
		
		mini = min(mini, tren);
	}
	cout << mini;

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll r,g,b; cin>>r>>g>>b;
	printf("%s",(10*g+b)%4==0?"YES":"NO");
}

Measured memory_bytes: 256
# Candies
def main():
    N = int(input())
    A1 = [int(x) for x in input().split()]
    A2 = [int(x) for x in input().split()]
    ans = [0 for i in range(N)]
    for i in range(N):
        if i == 0:
            ans[i] = sum(A1[:]) + A2[-1]
        elif i == N:
            ans[i] = A1[0] + sum(A2[:])
        else:
            ans[i] = sum(A1[:i])+sum(A2[i-1:])
    print(max(ans))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//author:satwik_bhv1
#include<bits/stdc++.h>
//datatypes
#define ll long long 
#define ld long double
//loops
#define fr(i,z,n) for(ll i=z;i<n;i++)
#define br(i,z,n) for(ll i=z;i>n;i--)
//operations
#define mp  make_pair
#define ff  first
#define ss  second
#define pub push_back
#define all(v) v.begin(),v.end()
//map
#define mi map<ll,ll>
//vectors
#define vi vector<ll>
#define vpi vector<pair<ll,ll> >
//constants
#define pi 3.1415926535897932384626
#define mod 1000000007 
#define MAXN 100001
/*notes
    Don't use inbuilt fun for power
    Range of longlong=(-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 )
    INT_MAX = 2147483647(aprox 2*10^10)
    INT_MIN = -2147483648
    LLONG_MAX = 9223372036854775807 
    LLONG_MIN = -9223372036854775808
    __gcd is the function in built for hcf
    priority queue is max heap by default
    topological sort -> khan's algo use bfs and indegree of node  
    sssp(positive weighted edges) -> Dijkstras
    apsp -> Floydwarshall
    MST -> kruskal(DSU)
*/
using namespace std;
//functions
ll power(ll x,ll y){ll res=1;while(y){if(y%2){res*=x;}y/=2;x*=x;} return res;}
ll power(ll x,ll y,ll z){ll res=1;while(y){if(y%2){res=(res*x)%z;}y/=2;x=(x*x)%z;} return res;}
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }
bool sortbysec(const pair<ll, ll>& a, const pair<ll, ll>& b) { return (a.second > b.second); }
ll ceil(ll x,ll y){return (x/y)+(x%y!=0);}
vi ar[100001];
ll vis[100001];
ll dis[100001];
ll dep[100001];
ll deg[100001];
ll ans;
void dfs(ll node)
{
    if(!vis[node])
    {
        vis[node]=1;
        dis[node]=0;
    }
    for(ll child:ar[node])
    {
        if(!vis[child])
        {
            dis[child]=dis[node]+1;
            ans=max(ans,dis[child]);
            vis[child]=1;
            dfs(child);
        }
        if(dis[child]<dis[node]+1)
        {
            dis[child]=dis[node]+1;
            ans=max(ans,dis[child]+dep[child]);
        }
        dep[node]=max(dep[node],dep[child]+1);
    }
}
void solve()
{
    ll n,m;
    cin>>n>>m;
    fr(i,0,m)
    {
        ll a,b;
        cin>>a>>b;
        ar[a].pub(b);
        deg[b]++;
    }
    fr(i,1,n+1)
    {
        if(deg[i]==0)
        {
            dfs(i);
        }
    }
    cout<<ans;
    
}
int main()
{
    fast();
    ll t;
    t=1;
    //cin>>t;
    fr(i,0,t)
    {
        solve();
    }
}
/*





























*/

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

int main(){
	int n;
	scanf(" %d", &n);
	int i, all = 0, s[n];
	for(i = 0; i < n; i++){
		scanf(" %d", &s[i]);
	}
	for(i = 0; i < n; i++){
		all += s[i];
	}
	int min=999;
    for(i = 0; i < n; i++){
		if(s[i] %10 != 0 && s[i] < min){
			min = s[i];
		}
    }
	if(min == 999){
		printf("%d", 0);
	}
	else if(all %10 ==0){
		printf("%d", all-min);
	}
	else{
		printf("%d",all);
	}
	return 0;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> scores(N);
  for(int i=0;i<N;i++) cin >> scores.at(i);
  for(int i=K;i<N;i++){
    if(scores.at(i)>scores.at(i-K)){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

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

int main(){
  int N,count=1;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;N>i;i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int i=0;N>i+1;i++){
    if(vec.at(i) != vec.at(i+1)){
      count++;
    }else{
    }
  }
  cout << count << endl;
}


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

using namespace std;

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

int main()
{
    char A, B;
    cin >> A >> B;
    if (A == B) {
        cout << "=" << endl;
    } else if (A > B) {
        cout << ">" << endl;
    } else {
        cout << "<" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main () {
  int x,a,b;cin>>x>>a>>b;
  if(b<=a)cout << "delicious" << endl;
  else if(b<=a+x)cout << "safe" << endl;
  else cout << "dangerous" << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
 	ll n,k;cin>>n>>k;
 	if(n%k==0){
 		cout<<0<<endl;
 	}else{
 		cout<<1<<endl;
 	}
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  string S;
  cin >> N >> S;
  REP(i,0,S.length()){
    S[i]= 'A'+(S[i]-'A'+N)%26;
  }
  cout<<S<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 16;
const int inf = 16100000;
int dp[(1<<N)];
int a[N];
int cost[N][N];
int solve(int n){
  rep(i,(1<<n))dp[i]=inf;
  rep(i,n)dp[(1<<i)]=a[i];
  rep(i,(1<<n)){
    rep(j,n){
      if (((1<<j)&i) != 0)continue;
      int next=(1<<j)|i;
      rep(k,n){
	if (((1<<k)&i) == 0)continue;
	dp[next]=min(dp[next],dp[i]+cost[j][k]);
      }
      dp[next]=min(dp[next],dp[i]+a[j]);
    }
  }
  return dp[(1<<n)-1];
}

main(){
  int n;
  while(cin>>n && n){
    rep(i,n){
      cin>>a[i];rep(j,n)cin>>cost[i][j];
    }
    cout << solve(n) << endl;
  }
}

Measured memory_bytes: 1124
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

using namespace std;

int main()
{
	int x;
	cin >> x;
	if (x == 5 || x == 7 || x == 3) {
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<typename tn> void read(tn &a){
    tn x=0,f=1;char c=' ';
    for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
    for(;isdigit(c);c=getchar() ) x=x*10+c-'0';
    a=x*f;
}
int a,b;
int main(){
	read(a);
	read(b);
	printf("%d\n",max(0,a-b-b));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld = long double;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N, A, B);
  print((B - A) % 2 ? "Borys" : "Alice");
}


Measured memory_bytes: 256
function Main(input) {
	input = input.split(" ");
	var a = input[0];
	var b = input[1];
	var ret = 0;
	if(a == b || a < b){
		ret = a;
	} else if (a > b) {
		ret = a - 1;
	}
	console.log(ret);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll ans=0;
	for(ll i=1;i<=n;i++){
		for(ll j=1;j<=n;j++){
			for(ll k=1;k<=n;k++){
				ans+= __gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<ans;
 	
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(string, S);

    int ans = 1e9;
    int temp = 0;
    for (int i = 1; i < N; i++) {
        if ( S[i] == 'E' ) {
            temp++;
        }
    }
    ans = min(ans, temp);

    for (int i = 1; i < N; i++) {
        if ( S[i- 1] == 'W' ) {
            temp++;
        }
        if ( S[i] == 'E' ) {
            temp--;
        }
        ans = min(ans, temp);
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans=0;
    cin>>n;
    int a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    int dp[n-1][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    ans=max(dp[0][0],max(dp[0][1],dp[0][2]));
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(j==0)
            dp[i][j]=a[i]+max(dp[i-1][1],dp[i-1][2]);
            if(j==1)
            dp[i][j]=b[i]+max(dp[i-1][0],dp[i-1][2]);
            if(j==2)
            dp[i][j]=c[i]+max(dp[i-1][0],dp[i-1][1]);
            if(i==n-1)
                ans=max(dp[i][j],ans);
        }
    }
    cout<<ans;
   return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
double a[3005];
double dp[3005][3005];

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        scanf("%lf",&a[i]);
    }
    dp[1][1]=a[1];
    dp[1][0]=1-a[1];


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

        }
    }

    double ans=0.0000;
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[n][i];
     }
   //  ans=0;
    printf("%.12f\n",ans);

    return 0;
}


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = 1<<29;

int main() {
  int N; cin >> N;
  set<string> s;
  string prev;
  rep(i, N) {
    string w; cin >> w;
    if (s.count(w)) {
      cout << "No\n";
      return 0;
    }
    if (!prev.empty() && prev.back() != w[0]) {
      cout << "No\n";
      return 0;
    }
    prev = w;
    s.insert(w);
  }
  cout << "Yes\n";
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    private static Scanner scanner;
    public static void main(String args[]){
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	int count = 0;
	for(int i=0;i < a;i++) b[i]=scanner.nextInt();
	for(int i = 0;i < a;i++){
	    for(int j = a - 1;j >= 1;j--){
		if(b[j] < b[j-1]){
		    int tmp = b[j];
		    b[j] = b[j-1];
		    b[j-1] = tmp;
		    count++;
		}
	    }
	}
	for(int i=0;i < a;i++){
	    System.out.print(b[i]);
	    if(i != a-1){
		System.out.print(" ");
	    }else{
		System.out.println("");
	    }
	}
	System.out.println(count);
    }
}



Measured memory_bytes: 26352
n,a,b,c,d=map(int,input().split())
s=input()
flag=0
span=0
buf=-5
if(c<d):
    for i in range(a-1,d):
        if(s[i]=='#' and s[i+1]=='#'):
            flag=1
            break
else:
    for i in range(b-2,d-1):
        if(s[i]=='.' and s[i+1]=='.' and s[i+2]=='.'):
            flag=0
            break
        else:
            flag=1
    
print('No' if flag==1 else 'Yes')

Measured memory_bytes: 3572
n=int(input())

l=[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]

#初期値：n回（n円は1円をn回引き出すことでも得られる）
dp=list(range(n+1))

for item in l:
  for i in range(item,n+1):
    #よりよい引き出し方に変えていく
    dp[i]=min(dp[i-item]+1, dp[i])

print(dp[-1])

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

using namespace std;
#define fordebug int hoge;cin>>hoge;
#define DEKAI 1000000007
#define INF (1<<28)
#define lp(i,n) for(int i=0;i<n;i++)
#define lps(i,j,n) for(int i=j;i<n;i++)

#define int long long
int defplace[8][8],ans[8][8],done;

bool checks(int m[8][8],int x,int y){
	lp(i,8){
		lp(j,8){
			if(m[i][j]==1){
				if(i==x&&j==y)continue;
				if(abs(x-i)==abs(y-j)) return false;
				if(x==i||y==j) return false;
			}
		}
	}
	return true;
}

void try8(int m[8][8],int x){
	/*lp(i,8){
		lp(j,8){
			if(m[i][j]==1) cout<<"Q";
			else cout<<".";
		}
		cout<<endl;
	}
	int hoge;
	cin>>hoge;*/
	if(x==8){
		lp(i,8)lp(j,8){
			ans[i][j]=m[i][j];
		}
		done=1;
		return;
	}
	if(done==1) return;
	lp(i,8){
		if(defplace[x][i]==1){
			if(checks(m,x,i)==false) return;
			else{
				m[x][i]=1;
				try8(m,x+1);
				m[x][i]=0;
				return;
			}
		}
	}
	lp(i,8){
		if(checks(m,x,i)==false) continue;
		m[x][i]=1;
		try8(m,x+1);
		m[x][i]=0;
	}
	return;
}

signed main(){
	int k;
	cin>>k;
	lp(i,k){
		int a,b;
		cin>>a>>b;
		defplace[a][b]=1;
	}
	int m[8][8];
	lp(i,8)lp(j,8)m[i][j]=0;
	try8(m,0);
	lp(i,8){
		lp(j,8){
			if(ans[i][j]==1) cout<<"Q";
			else cout<<".";
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 3056
#include<iostream>
using namespace std;
int main(){
	int l,r,d;
	cin>>l>>r>>d;
	long long int ans = 0;
	for (int i = l; i < r+1; ++i)
	{
		if(i%d == 0) ++ans;
	}
	cout<<ans<<endl;
	return 0;
}

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

struct node{
	void *data;
	struct node *next;
	struct node *prev;
};

struct point{
	int x;
	int y;
};


typedef struct node *NodePointer;

NodePointer nil;

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

void deleteNode(NodePointer t){
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t->data);
	free(t);
}

void backInsert(void *p,int len){
	NodePointer t;
	t = malloc(sizeof(struct node));
	t->data = malloc(len);
	memcpy(t->data,p,len);
	t->next = nil;
	t->prev = nil->prev;
	t->prev->next = t;
	nil->prev = t;
}

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

void deleteAll(){
	NodePointer t = nil->next;
	while(t != nil){
		deleteNode(t);
	}
}

void pop(void *np,int len){
	memcpy(np,nil->next->data,len);
	deleteFirst();
}

int main(int argc, char **argv)
{
	int *square;
	char temp[1000];
	int count = 0;
	int r = 0;
	int c = 0;
	int i = 0;
	int j = 0;
	struct point dif[4] = {{0,-1},{1,0},{0,1},{-1,0}}; 

	scanf("%d%d",&r,&c);
	init();

	square = malloc(sizeof(int) * (r * c));
	
	for(i = 0;i < r;i++){
		scanf("%s",temp);
		for(j = 0;j < c;j++){
			if(temp[j] == '#'){
				square[i * c + j] = 0;
				struct point *blackPoint = malloc(sizeof(struct node));
				blackPoint->x = j;
				blackPoint->y = i;
				backInsert(blackPoint,sizeof(blackPoint));
			}
			else{
				square[i * c + j] = -1;
			}
		}
	}
	
	while(nil->next != nil){
		struct point currentPoint;
		pop(&currentPoint,sizeof(currentPoint));

		for(i = 0;i < 4;i++){
			if((currentPoint.y + dif[i].y) * c + (currentPoint.x + dif[i].x) < 0 || r * c < (currentPoint.y + dif[i].y) * c + (currentPoint.x + dif[i].x) ||
				(currentPoint.x + dif[i].x) == c || (currentPoint.x + dif[i].x) == -1){
			}
			else if(square[(currentPoint.y + dif[i].y) * c + (currentPoint.x + dif[i].x)] == -1){
				struct point pointP;
				pointP.x = currentPoint.x + dif[i].x;
				pointP.y = currentPoint.y + dif[i].y;
				backInsert(&pointP,sizeof(pointP));
				square[(currentPoint.y + dif[i].y) * c + (currentPoint.x + dif[i].x)] = square[(currentPoint.y * c) + currentPoint.x] + 1;
				count = square[(currentPoint.y + dif[i].y) * c + (currentPoint.x + dif[i].x)];
				// printf("%d\n",(((currentPoint.y + dif[i].y) * c)));
				// printf("%d\n",((currentPoint.x + dif[i].x)));
				// printf("\n");
			}
			
		}
		
	}
	printf("%d\n",count);
	
	//deleteAll();
	free(nil);
	return 0;
}



Measured memory_bytes: 97792
package main

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

var sc = bufio.NewScanner(os.Stdin)
func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

const mod = 1000000007

func main() {
	sc.Split(bufio.ScanWords)
	
	var s string
	fmt.Scan(&s)

	n := len(s)
	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, 13)
	}

	dp[0][0] = 1
	for i := 1; i < n+1; i++ {
		if s[i-1] == '?' {
			for j := 0; j < 10; j++ {
				for k := 0; k < 13; k++ {
					dp[i][(k*10%13 + j)%13] = (dp[i][(k*10%13 + j)%13] + dp[i-1][k])%mod
				}
			}
		} else {
			num,_ := strconv.Atoi(string(s[i-1]))
			for k := 0; k < 13; k++ {
				dp[i][(k*10%13 + num)%13] = dp[i-1][k]
			}
		}
	}

	// fmt.Println(dp)
	fmt.Println(dp[n][5])
}


Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
vector<int> G[100010];

int dfs(int v, int p){
    int res = 0;
    int son = 0;
    for(auto u : G[v]){
        if(u != p) res ^= dfs(u, v), son++; 
    }
    return res + 1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 1; i < N; i++){
        int x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);
 
    }
    cout << (dfs(1, 0) - 1 == 0 ? "Bob" : "Alice") << endl;
    return 0;
}

Measured memory_bytes: 10368
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 2000000000;



int main(){
  int a, b;
  cin >> a >> b;
  int ans = a*(a-1)/2;
  if (b > 1) cout << ans + b*(b-1)/2 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

const int MAXN = (int) 1e5;

vector <int> g[MAXN + 1];

int p[MAXN + 1];

int ok1[MAXN + 1], ok2[MAXN + 1];
bool vis[MAXN + 1];

int cur;
int ans = 0;

void dfs(int nod) {
    vis[nod] = 1;
    ok1[nod] = cur;
    ok2[p[nod]] = cur;
    if(ok2[nod] == cur) {
        ans++;
    }
    if(nod != p[nod] && ok1[p[nod]] == cur) {
        ans++;
    }
    for(auto it : g[nod]) {
        if(vis[it] == 0) {
            dfs(it);
        }
    }
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n, m, x, y;
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for(i = 1; i <= n; i++) {
        cin >> p[i];
    }
    for(i = 1; i <= m; i++) {
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    ans = 0;
    for(i = 1; i <= n; i++) {
        if(vis[i] == 0) {
            cur = i;
            dfs(i);
        }
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

int main()
{
  int A, B;
  cin >> A >> B;
  cout << 100 << " " << 100 << endl;
  A--;B--;
  for (int j = 0; j < 100; ++j)
  {
    for (int i = 0; i < 100; ++i)
    {
      if (i < 50)
      {
        if (B > 0 && i % 2 == 0 && j % 2 == 1 && i != 49)
        {
          B--;
          cout << "#";
        }else{
          cout << ".";
        }
      }else{
        if (A > 0 && i % 2 == 0 && j % 2 == 1 && i != 50)
        {
          A--;
          cout << ".";
        }else{
          cout << "#";
        }
      }
    }
    cout << endl;
  }
  return 0;
}

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

int main(void) {
    int n ,m;
    cin >> n >> m;
    vector<int> k(m), p(m);
    vector<vector<int>> s(m, vector<int> (10));
    for (int i = 0; i < m; i++) {
        cin >> k.at(i);
        for (int j = 0; j < k.at(i); j++) {
            cin >> s.at(i).at(j);
            s.at(i).at(j)--; // bit 全探索のために引いておく
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> p.at(i);
    }

    int ans = 0;
    for (int i = 0; i < (1<<n); i++) {
        int flag = 1;
        for (int j = 0; j < m; j++) {
            int count_on = 0;
            for (int l = 0; l < k.at(j); l++) {
                if ((1 << s.at(j).at(l) | i) == i) {
                    count_on++;
                }
            }
            if (count_on % 2 != p.at(j)) {
               flag = 0;
            }
        }
        ans += flag;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

const int N = 10000000;

int main() {
  int n;
  vector<bool> is_prime(N + 1, true);
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i <= N; ++i) {
    for (int j = 2; i * j <= N; ++j) {
      is_prime[i * j] = false;
    }
  }
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int k = n; true; --k) {
      if (k % 6 == 1 and is_prime[k] and is_prime[k - 2]
          and is_prime[k - 6] and is_prime[k - 8]) {
        cout << k << endl;
        break;
      }
    }
  }
}

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

int main(){
        int s; cin >> s;
        int result=0;
        bool done=false;
        while(s--){ 
                int f,s; 
                cin >> f >> s;
                if(f==s){
                        result++;
                }
                else{
                        result=0;
                }
                if(result>=3){
                        done=true;
                }
        }
        if(result>=3 || done){
                cout << "Yes";
        }
        else{
                cout << "No";
        }
}

Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
using namespace std;

main(){
	int n,d,a[20][20];
	int ans;
	ans = 0;
	long long tmp;
	cin>>n>>d;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=d;j++)
			cin>>a[i][j];
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			tmp = 0;
			for(int o=1;o<=d;o++)
				tmp += (a[i][o]-a[j][o])*(a[i][o]-a[j][o]);
			if(sqrt(tmp) == int(sqrt(tmp)))
				ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
using namespace std;

int a, b, c;

int main() {
    scanf("%d %d %d", &a, &b, &c);

    bool c1 = (a == b) && a != c;
    bool c2 = (b == c) && a != b;
    bool c3 = (a == c) && a != b;

    if (c1 || c2 || c3) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}

Measured memory_bytes: 3172
#include <iostream>
#include <string>

using namespace std;

int main(){
  int arr[26]={0};
  string s;
  cin >> s;

  for (auto &c:s) {
    arr[c-'a']++;
  }

  for (int i=0; i<26; i++) {
    if (arr[i]==0) {
      printf("%c\n", 'a'+i);
      return 0;
    }
  }

  printf("None\n");
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

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

  int x[r][c];
  int sum = 0;
  int sum_sum = 0;

  
  int i, j;

 
  
  for(i = 0;i < r;i++){
    for(j = 0;j < c;j++){
      scanf("%d", &x[i][j]);
    }
  }

  for(i = 0;i < r;i++){
    for(j = 0;j < c;j++){
      printf("%d ", x[i][j]);
      sum += x[i][j];
      
      if(c-j == 1){
	printf("%d", sum);
	sum = 0;
      }
    }
    printf("\n");
  }

  for(j = 0;j < c;j++){
    for(i = 0;i < r;i++){
      sum += x[i][j];
    }
    printf("%d ", sum);
    sum_sum += sum;
    sum = 0;
  }

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



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

int main()
{
    int N;
    int K;
    cin >> N;
    cin >> K;
    
    int count = 0;
    
    for (int i=0; i<N; i++){
        int h;
        cin >> h;
        if(h >= K) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
bool comp(int a,int b){
return a>b;
}
mt19937 mrand(random_device{}());
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int main()
{
	fast;
	ll n;
	cin>>n;
	cout<<n+n*n+n*n*n;
	
	
	
	
	
	


}



Measured memory_bytes: 3632