akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int calc(int d) {
  if (d == 0) {
    return 1;
  } else {
    return calc(d % bitset<32>(d).count()) + 1;
  }
}
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> v1(n), v2(n);
  bitset<200000> b(s);
  int a = b.count(), a1 = a - 1, a2 = a + 1, b1 = 0, b2 = 0;
  v1[0] = 1, v2[0] = 1;
  if (b.test(0)) {
    b1 = 1, b2 = 1;
  }
  rep(i,n-1)
  {
    if (a > 1)
      v1[i + 1] = v1[i] * 2 % a1;
    v2[i + 1] = v2[i] * 2 % a2;
    if (b.test(i + 1)) {
      if (a > 1)
        b1 = (b1 + v1[i + 1]) % a1;
      b2 = (b2 + v2[i + 1]) % a2;
    }
  }
  for (int i = n - 1; i >= 0; i--)
    if (b.test(i))
      if (a > 1)
        cout << calc((b1 + a1 - v1[i]) % a1) << endl;
      else
        cout << 0 << endl;
    else
      cout << calc((b2 + a2 + v2[i]) % a2) << endl;
  return 0;
}

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

int main()
{
  string s;
  cin >> s;
  if(s=="Sunny"){
    cout << "Cloudy" << endl;
  }else if(s=="Cloudy"){
    cout << "Rainy" << endl;
  }else if(s=="Rainy"){
    cout << "Sunny" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    h = [int(s) for s in input().split()]
    print(solve(n, h))

def solve(n, h):
    inf = float('inf')
    dp = [inf for _ in range(n)]
    dp[0] = 0
    for i in range(n):
        if i + 1 < n:
            dp[i + 1] = min(dp[i+1], dp[i] + abs(h[i+1] - h[i]))
        if i + 2 < n:
            dp[i + 2] = min(dp[i+2], dp[i] + abs(h[i+2] - h[i]))
    
    return dp[-1]

main()


Measured memory_bytes: 14052
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
vi hoge;
int N;
ll K;
vi tree[114514];
vi ko[114514];
int oya[114514];
void dfs(int now){
	rep(i,tree[now].size()){
		int ch=tree[now][i];
		if(oya[ch]==-1){
			oya[ch]=now;
			dfs(ch);
		}
	}

}

ll ans=1;
bool visited[114514];
ll konum[114514]={0};
void calc(int now){
	ll cnt=0;
	if(now!=0){
		cnt++;
		if(oya[now]!=0)cnt++;
		cnt+=konum[oya[now]];
		cnt--;
	}
	ans*=max(K-cnt,(ll)0);
	ans%=MOD;
	rep(i,tree[now].size()){
		int ch=tree[now][i];
		if(!visited[ch]){
			visited[ch]=true;
			konum[now]++;
			calc(ch);
		}
	}
}
int main(){
	cin>>N>>K;
	rep(i,N-1){
		int a,b;
		cin>>a>>b;a--;b--;
		tree[a].pb(b);
		tree[b].pb(a);
	}
	rep(i,N)oya[i]=-1;
	oya[0]=0;
	dfs(0);
	//cout<<"WW"<<endl;
	rep(i,N){
		if(i!=0)ko[oya[i]].pb(i);
		visited[i]=false;
	}
	visited[0]=true;
	calc(0);
	cout<<ans<<endl;
}


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

int main()
{
  int D,T,S;
  cin>>D>>T>>S;
  float time = float(T);
  float t = (float)D/S;
  if(t<=time) cout<< "Yes";
  else cout<< "No";
    




 return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define N 100010
using namespace std;
int n, m;
int a[N];
int tree[N];
void init(){
    memset(a, 0, sizeof(a));
    memset(tree, 0, sizeof(tree));
}
int lowbit(int x) {return x & (-x); }
void add(int i, int x){
    while(i <= n){
        tree[i] += x;
        i += lowbit(i);
    }
}
int query(int i){
    int res = 0;
    while(i){
        res += tree[i];
        i -= lowbit(i);
    }
    return res;
}
int main() {
    init();
    scanf("%d %d", &n, &m);
    for(int i = 0 ;i  < m; i++){
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        if(a == 0){
            add(b, c);
        }else{
            printf("%d\n", query(c) - query(b-1));
        }
    }
    return 0;
}


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

int main() {

    int N, K;
    cin >> N >> K;

    if (K > (N - 1) * (N - 2) / 2)  {
        cout << "-1" << endl;
        return 0;
    }

    int count = (N * (N - 1) / 2 - K);
    cout << count << endl;
    for (int i = 2; i <= N; i++) {
        cout << 1 << " " << i << endl;
        count--;
    }

    for (int i = 2; i <= N - 1; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (count == 0) {
                return 0;
            }
            cout << i << " " << j << endl;
            count--;
        }
    }

    return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL){
    x=x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if(u==NIL||k==u->key)return u;
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);
  Node y;
  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }

    z->parent=y;

    if(y==NIL)root=z;
    else if(z->key<y->key)y->left=z;
    else y->right=z;
  
}

void inorder(Node u){
  if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);    
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25172
import java.io.*;
import java.util.*;

public class Main{
    
    public static void main(String[] arg){

        Scanner scan =new Scanner(System.in);

        int n=Integer.parseInt(scan.next());
        int m=Integer.parseInt(scan.next());

        ArrayList<Integer> L=new ArrayList<Integer>();
        ArrayList<Integer> R=new ArrayList<Integer>();

        for(int i=0;i<m;i++){
            L.add(scan.nextInt());
            R.add(scan.nextInt());
        }

        Integer i=Collections.max(L);
        Integer j=Collections.min(R);

        System.out.print((i<=j) ? j-i+1 : 0);
     
    }
}

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

using namespace std;

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

    const int NO_OF_ALPHABETS = 26, MOD = 1e9 + 7;;
    vector <long long> frequency(NO_OF_ALPHABETS, 0);
    for(int i = 0; i < length; i++)
        frequency[S[i] - 'a']++;

    long long colourful_sequences = 1;
    for(int alpha = 0; alpha < NO_OF_ALPHABETS; alpha++)
        colourful_sequences = ( (colourful_sequences*(frequency[alpha] + 1))%MOD );

    colourful_sequences = (colourful_sequences + MOD - 1)%MOD;

    cout << colourful_sequences;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;
typedef pair<int, int> pii;

// string でフィールドを作ると入出力がかなり簡単になる
// ☆ 整数を見た目のまま文字列にするには '0' + (int型)

int main(){
	int h, w;
	cin >> h >> w;
	string feld[h];
	for( int i = 0; i < h; ++i ) cin >> feld[i];
	const vector<pii> bw = {pii(-1, 0), pii(1, 0), pii(0, -1), pii(0, 1), pii(1, 1), pii(1, -1), pii(-1, 1), pii(-1, -1)};
	for( int i = 0; i < h; ++i ){
		for( int j = 0; j < w; ++j){
			if( feld[i][j] == '.' ){
				int cnt = 0;
				for( auto d : bw ){
					int x = i + d.first;
					int y = j + d.second;
					if( 0 <= x && x < h && 0 <= y && y < w && feld[x][y] == '#' ) ++cnt;
				}
				feld[i][j] = '0' + cnt;
			}
		}
	}
	for( int i = 0; i < h; ++i ) cout << feld[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 100000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
using namespace std;

bool is_prime[100000000 + 1];// Up to 1e8 + 1
template<typename T>
vector<T> Eratosthenes(const T N) { // return primes up to N
	vector<T> P;
	for (int i = 0; i <= N; i++)
	{
		is_prime[i] = true;
	}
	for (int i = 2; i <= N; i++)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= N; j += i)
			{
				is_prime[j] = false;
			}
			P.emplace_back(i);

			//if (P.size() >= N) break;
		}
	}
	return P;
}

template<typename T>
T gcd(T a, T b) {
	if (a > b) {
		T c = a;
		a = b;
		b = c;
	}
	if (a == 0) {
		return b;
	}

	return gcd(b % a, a);
}

int main() {
	ll A, B; cin >> A >> B;
	vector<ll> Erast = Eratosthenes(static_cast<ll>(1000004));
	//cout << *(Erast.end()-1) << endl;
	ll cnt = 1;
	
	for (int i = 0; i < Erast.size(); i++) {
		if (A % Erast[i] == 0 or B % Erast[i] == 0) {
			if (A % Erast[i] == 0 and B % Erast[i] == 0) cnt++;
			while (A % Erast[i] == 0) {
				A /= Erast[i];
			}

			while (B % Erast[i] == 0) {
				B /= Erast[i];
			}

		}
	}
	if (A == B and A > 1) {
		cnt++;
	}
	cout << cnt << endl;
}


Measured memory_bytes: 2424
/* author   : mpily :-()
title : Competing.cpp
time :Mon Sep  9 21:19:46 2019

*/
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,K;
	cin>>N>>K;
	vector<char>arr(N);
	for(int i = 0; i < N; i++){
		cin>>arr[i];
	}
	int count = 0;
	for(int i = 1; i < N; i++){
		if(arr[i] == arr[i-1])count+=1;
	}
	while(K--){
		count+=2;
		if(count >= N)break;
	}
	if(count >= N)count = N-1;
	cout<<count<<"\n";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {
    int ans = 0, N;
    cin >> N;
    for (int i = 0, a; i < N; i++) {
        cin >> a;
        while (a % 2 == 0) {
            a /= 2;
            ans++;
        }
    }
    cout << ans << endl;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n;
    cin >> n;
    set<ll> s;
    rep(i, n)
    {
        ll b;
        cin >> b;
        s.insert(b);
    }
    if (s.size() == n)
    {
        c("YES");
    }
    else
    {
        c("NO");
    }
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>

using namespace std;

bool contains(int x) {
  while (x) {
    int r = x % 10;
    if (r == 7) return true;
    x /= 10;
  }
  return false;
}

int main() {
  int n;
  cin >> n;
  cout << (contains(n) ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 3e5 + 5, M = 1e9 + 7;

auto solve(const string &s, char c) {
  int sum = 0, n = s.size();
  vector<int> mn(n + 1), mni(n + 1);
  for (int i = 1; i <= s.size(); i++) {
    int t = s[i-1] == c;
    sum += t;
    int k = 2 * sum - i;
    if (i > 1 && k > mn[i - 2]) {
      return make_pair(mni[i - 2] + 1, i);
    }
    mn[i] = mn[i-1], mni[i] = mni[i-1];
    if (mn[i] > k) {
      mn[i] = k, mni[i] = i;
    }
  }
  return make_pair(-1, -1);
}

int main() {
  string s;
  cin >> s;
  for (char c = 'a'; c <= 'z'; c++) {
    auto ans = solve(s, c);
    int l, r;
    tie(l, r) = ans;
    if (l != -1) {
      cout << l << ' ' << r << '\n';
      return 0;
    }
  }
  cout << -1 << ' ' << -1 << '\n';
}


Measured memory_bytes: 4216
package main

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

func main() {
	H := readInt()
	N := readInt()

	dp := make([]int, H+1)
	fill(dp, math.MaxInt64)

	dp[0] = 0
	for i := 0; i < N; i++ {
		A := readInt()
		B := readInt()
		for j := 0; j < H; j++ {
			if dp[j] == math.MaxInt64 {
				continue
			}
			t := min(j+A, H)
			if dp[j]+B < dp[t] {
				dp[t] = dp[j] + B
			}
		}
	}

	fmt.Println(dp[H])
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func fill(a []int, x int) {
	for i := 0; i < len(a); i++ {
		a[i] = x
	}
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}


Measured memory_bytes: 768
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
void solve(){
	int l, r;
	cin >> l >> r;
	if (r - l > 2019){
	   cout << 0 ;
	   exit(0);	
	}
	int mn = INF;
	for(int i = l; i <= r; i++){
	  for(int j = i + 1; j <= r; j++){
		    mn = min(mn, (i*j) % 2019); 
		 } 	
	}
	cout << mn << endl;
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
#include<stdio.h>


int main() {
	int A[100][100];
	int b[100];

	int n, m;
	int i, j;

	scanf("%d %d", &n, &m);

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			fflush(stdin);
			scanf("%d",&A[i][j]);
		}
	}

	for (j = 0; j < m; j++) {
		fflush(stdin);
		scanf("%d", &b[j]);
	}

	int ctmp;
	for (i = 0; i < n; i++) {
		ctmp = 0;
		for (j = 0; j < m; j++) {
			ctmp += (A[i][j] * b[j]);
		}
		printf("%d\n", ctmp);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  while(true){
    int n;
    cin >> n;
    if(n==0)break;
    string s;
    cin >> s;

    // simulate
    int tefuda[n];
    REP(i,n)tefuda[i]=0;
    int ba = 0;
    int turn = 0;
    REP(i,100){
      if(s[i]=='M'){
        tefuda[turn]++;
      }else if(s[i]=='S'){
        ba += 1;
        ba += tefuda[turn];
        tefuda[turn] = 0;
      }else if(s[i]=='L'){
        tefuda[turn] += 1;
        tefuda[turn] += ba;
        ba = 0;
      }
      ++turn;
      turn %= n;
    }
    sort(tefuda,tefuda+n);
    REP(i,n){
      cout << tefuda[i] << " ";
    }
    cout << ba << endl;
  }
  return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;
typedef unsigned long long ull;
const ull base = 131, mod = 19260817;
ull po[610], _hash_row[610][610], _hash_column[610][610];
char board[610][610];
inline void init() {
	po[0] = 1;
	for (int i = 1; i < 610; i++)
		po[i] = po[i - 1] * base;
}
ull hash_row(int begin, int end, int i) {
	return _hash_row[i][end] - po[end - begin] * _hash_row[i][begin];
}
ull hash_column(int begin, int end, int i) {
	return _hash_column[i][end] - po[end - begin] * _hash_column[i][begin];
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	init();
	int N, ans = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
			cin >> board[i][j];
		for (int j = 0, k = N; j < N - 1; j++, k++)
			board[i][k] = board[i][j];
	}
	for (int i = N, k = 0; i < 2 * N - 1; i++, k++)
		for (int j = 0; j < 2 * N - 1; j++)
			board[i][j] = board[k][j];
	for (int i = 0; i < 2 * N - 1; i++)
	{
		_hash_row[i][0] = 0;
		_hash_column[i][0] = 0;
		for (int j = 0; j < 2 * N - 1; j++)
		{
			_hash_row[i][j + 1] = _hash_row[i][j] * base + board[i][j];
			_hash_column[i][j + 1] = _hash_column[i][j] * base + board[j][i];
		}
	}
	bool flag;
	ull row, column;
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			flag = true;
			for (int k = 0; k < N && flag; k++)
			{
				row = hash_row(j, j + N, k + i);
				column = hash_column(i, i + N, k + j);
				if (row != column)
					flag = false;
			}
			if (flag)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6400
package main

import "fmt"

var (
	d   = 1
	ans [][]int
)

func calc(x, i int) {
	for j := range ans[i-1] {
		nx := (x*d + j) % 13
		ans[i][nx] = (ans[i][nx] + ans[i-1][j]) % 1000000007
	}
}

func main() {
	var s string
	fmt.Scan(&s)

	ans = make([][]int, len(s)+1)
	ans[0] = make([]int, 1)
	ans[0][0] = 1
	for i := 1; i <= len(s); i++ {
		if i > 1 {
			d = d * 10 % 13
		}

		ans[i] = make([]int, 13)
		r := s[len(s)-i]
		if r != '?' {
			calc(int(r-'0'), i)
			continue
		}
		for j := 0; j <= 9; j++ {
			calc(j, i)
		}
	}
	fmt.Println(ans[len(s)][5])
}


Measured memory_bytes: 14592
#include <bits/stdc++.h>
    using namespace std;
     
    vector<pair<int, int>> Prepare(const vector<pair<int, int>>& a, int bound) {
      const int n = static_cast<int>(a.size());
      vector<pair<int, int>> result;
      for (int i = 0; i < (1 << n); ++i) {
        int x = 0, y = 0;
        for (int j = 0; j < n; ++j) {
          if (~i & (1 << j)) continue;
          x += a[j].first;
          y += a[j].second;
        }
     
        if (x > bound)
          continue;
        result.emplace_back(x, y);
      }
     
      sort(result.begin(), result.end());
      int size = 1;
      for (int i = 1; i < (int) result.size(); ++i) {
        if (result[i].second <= result[size - 1].second)
          continue;
     
        result[size] = result[i];
        ++size;
      }
     
      result.resize(size);
      return result;
    }
     
    int main() {
      ios::sync_with_stdio(false);
      cin.tie(nullptr);
     
      int n;
      cin >> n;
     
      vector<pair<int, int>> a(n);
      for (auto& e: a)
        cin >> e.second >> e.first;

      int s = min(1024, n + 1);
      vector<vector<pair<int, int>>> memo(s + 5);
      for (int i = 1; i < s; ++i) {
          int v = i;
          vector<pair<int, int>> b;
          while (v > 0) {
            b.push_back(a[v - 1]);
            v /= 2;
          }
    
          memo[i] = Prepare(b, 100000);
      }
 
     
      int q;
      cin >> q;
      for (int i = 0; i < q; ++i) {
        int v, bound;
        cin >> v >> bound;
        vector<pair<int, int>> b, x, y;
        while (v > 0) {
          if (v < s) {
            y = memo[v];
            break;
          }
          b.push_back(a[v - 1]);
          v /= 2;
        }
     
        x = Prepare(b, bound);
        while (y.back().first > bound) y.pop_back();
        const int n = static_cast<int>(x.size());
        const int m = static_cast<int>(y.size());
        int result = max(x.back().second, y.back().second);
        for (int i = 0, j = m - 1; i < n; ++i) {
          while (j >= 0 && x[i].first + y[j].first > bound)
            --j;
          if (j >= 0)
            result = max(result, x[i].second + y[j].second);
        }
     
        cout << result << '\n';
      }
    }

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin; end < i; i--)			// repeat reverse

#endif

int main(void)
{
  ll a, b;
  cin >> a >> b; 
  
  cout << max({a+b, a-b, a*b});
  
  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    ll n, m;
    cin >> n >> m;
    vector<vector<int>> g(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bool f = false;
    vector<int> col(n, -1);
    vector<P> p;
    for (int i = 0; i < n; i++)
    {
        if (col[i] != -1)
            continue;
        queue<int> que;
        que.push(i);
        col[i] = 0;
        int one = 0, zero = 1;
        while (!que.empty())
        {
            int cur = que.front();
            que.pop();
            for (auto v : g[cur])
            {
                if (col[v] == -1)
                {
                    col[v] = 1 - col[cur];
                    que.push(v);
                    if (col[v])
                        one++;
                    else
                        zero++;
                    continue;
                }
                if (col[v] == col[cur])
                    f = true;
            }
        }
        p.emplace_back(min(one, zero), max(one, zero));
    }
    if (f)
    {
        cout << -1 << endl;
        return 0;
    }
    bitset<100000> bs;
    bs.set(0);
    for (auto pp : p)
    {
        int a = pp.first, b = pp.second;
        bs = (bs << a) | (bs << b);
    }
    ll ret = 0;
    for (ll i = 0; i <= n; i++)
        if (bs[i])
            ret = max(ret, i * (n - i) - m);
    cout << ret << endl;
}



Measured memory_bytes: 9432
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

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

    if(m == 0){
        p2(0, 0);
        return  0;
    }

    int p;
    string s;
    vector<bool> flag(n, false);
    int wa = 0;
    int ac = 0;

    vector<int> wa_tmp(n, 0);

    REP(i, 0, m){
        cin >> p >> s;
        if(flag.at(p - 1)){
            continue;
        } else {
            if (s == "WA"){
                wa_tmp.at(p - 1) += 1;
            } else {
                ac++;
                wa += wa_tmp.at(p - 1);
                flag.at(p - 1) = true;
            }
        }
    }

    p2(ac, wa);
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
 
 
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n;
  cin >> n;
  char a;
  bool fla = false;
  rep(i,n){
    cin >> a;
    if(a=='Y')fla=true;
  }
  pri(fla?"Four":"Three");








  return 0;
}


Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

completed = 0
target = 1
i = 1
while i <= N do
  if lines[1][i-1] == target then
    target += 1
    completed += 1
  end
  i += 1
end
  
if completed == 0 then
  print -1
else
  print N - completed
end

Measured memory_bytes: 16772
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;

int main(){
  int N, K; cin >> N >> K;
  set<int> s;
  rep(i,K) {
    int k; cin >> k;
    s.insert(k);
  }

  for (int i=N;i<100000;i++){
    int x = i;
    bool flag = true;
    while (x>0){
      if (s.count(x%10)){
        flag = false;
        break;
      }
      x /= 10;
    }
    if (flag) {
      cout << i << endl;
      break;
    }
  }

  
  // cout << fixed << setprecision(10);
  
  return 0;
}


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

bool cmp(long long & a, long long & b)
{
	return a < b;
}

int main(void)
{
	long long res[3];
	for (int i = 0; i < 3; i++)
		cin >> res[i];
	sort(res, res + 3, cmp);
	cout << res[0] << " " << res[2] << endl;
	return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <math.h>
#include <set>
#include <stack>
#include <bitset>
#include <map>
#include <queue>
#include <random>
#include <unordered_set>
#include <unordered_map>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
#define endl '\n'
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
// typedef tuple<int, int, int> tiii;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector< vector<int> > vvi;
typedef vector<char> vc;

const int INF = 1e9;
const ll INFLL = 1e16;
const int MOD = 1000000007;
const int MAXN = 3e5;
//const ld eps = 1e-6;
const ld eps2 = 1e-9;
const int MOD2 = 998244353;
const int dosz = 5e5;
const int SZ = (1<<18);
const ld PI = atan2l(0, -1);


void fast_io(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
        // freopen("a.in", "r",stdin);
#else
       // freopen("substrcmp.in", "r", stdin);
       // freopen("substrcmp.out", "w", stdout);
#endif
}

void solve(){
    int a, b;
    cin >> a >> b;
    for(int i=1; i<=1e6; i++){
        if((int)(i*0.08) == a && (int)(i*0.1)==b){
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl;
}

signed main() {
    fast_io();
    int q = 1;
    // cout << fixed << setprecision(6);
    // cin >> q;
    // cout << 1 << endl;
    while(q--){
        solve();
    }
    return 0;
}


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

int main(){
    vector<int> num(3);
    for (int i = 0;i < 3;i++){
        cin >> num.at(i);
    }
    sort(num.begin(),num.end());
    
    cout << num.at(0) << " " << num.at(1) << " " << num.at(2) << endl;
}


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

int main() {
  int n;
  int a = 0;    // R->Wの数
  int b = 0;    // W->Rの数
  int n_change; // 交換する回数
  std::string s;
  
  std::cin >> n >> s;


  for (int i = 0; i < n; i++)
    if (s[i] == 'R') a++; // 赤の数でaを初期化(交換回数は赤の数)

  // 境界を一番左においた時の交換回数
  n_change = std::max(a, b);

  // はじめの完成形はすべて白. 境界を左から右に移動させ左から赤色していく
  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') a--; // a(R->W)が一つ減る
    else b++;             // b(W->R)が増える

    // 最小の交換回数を更新
    int now = std::max(a, b);
    n_change = std::min(now, n_change);
  }

  std::cout << n_change << std::endl;
 
  return 0;
}

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    vector<vector<int>> e(n+1);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b;
        e[a].emplace_back(b);
        e[b].emplace_back(a);
    }
    vector<bool> visited(n+1, 0);
    auto dfs = [&](auto f, int curr, vector<int> &v) -> void {
        visited[curr] = 1;
        for (auto &to: e[curr]) {
            if (visited[to]) continue;
            v.emplace_back(to);
            return f(f, to, v);
        }
        return;
    };
    vector<int> v, w;
    dfs(dfs, 1, v);
    dfs(dfs, 1, w);
    reverse(w.begin(), w.end());
    w.emplace_back(1);
    for (auto &x: v) w.emplace_back(x);
    cout << w.size() << "\n";
    for (int i = 0; i < w.size(); i++) {
        if (i) cout << " ";
        cout << w[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 8568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
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;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll N, K;
vector<vector<ll>> dp, sum;

ll beki(ll a, ll b) {
    if(b == 0) return 1;
    ll ret = beki(a, b / 2);
    ret = ret * ret % mod;
    if(b & 1) ret = ret * a % mod;
    return ret;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    dp.resize(N + 1, vector<ll>(N + 2));
    sum.resize(N + 1, vector<ll>(N + 2));
    dp[0][N+1] = 1;
    for(int i = N; i >= 0; i--) {
        sum[0][i] = sum[0][i+1] + dp[0][i+1];
    }
    for(int i = 1; i < K; i++) {
        for(int val = N; val >= 2; val--) {
            dp[i][val] = sum[i-1][val];
            if(val + i <= N + 1) dp[i][val] += dp[i-1][val];
            dp[i][val] %= mod;
        }
        for(int val = N; val >= 0; val--) {
            sum[i][val] = sum[i][val+1] + dp[i][val+1];
            dp[i][val] %= mod;
        }
    }
    ll ans = 0;
    for(int i = 2; i <= N + 1; i++) {
        ans += dp[K-1][i];
        ans %= mod;
    }
    if(N - K > 1) {
        ans *= beki(2, N - K - 1);
    }
    ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 62976
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <math.h>
#define ll long long
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define mod 1000000007
#define inf 11451419198
using namespace std;

ll mpow(ll a, ll b, ll m){
	if (!b) return 1 % m;
	if (b == 1) return a % m;
	if (b % 2) return (a*mpow(a, b - 1, m)) % m;
	else return mpow((a*a)%m, b / 2, m) % m;
}

ll mfact(ll a, ll m){
	ll ret = 1;
	for (ll i = 1; i <= a; ++i) ret = (i*ret) % m;
	return ret;
}

ll fact[200001],factinv[200001];

ll mcomb(ll n, ll k, ll m){
	if (!n && !k) return 1;
	if (n < k || n < 0) return 0;
	return ((((fact[n]%m) * (factinv[k]%m))%m) * (factinv[n - k]%m)) % m;
	//return (((mfact(n, m)*mpow(mfact(k, m), m - 2, m))%m)*mpow(mfact(n - k, m), m - 2, m)) % m;
}

int main(){
	ll n, k; cin >> n >> k;
	ll ans = 0;
	fact[0] = 1;
	for (ll i = 1; i <= 200000; ++i) fact[i] = (fact[i - 1] * i) % mod;
	for (ll i = 0; i <= 200000; ++i) factinv[i] = mpow(fact[i], mod - 2, mod);
	for (int i = 0; i <= min(n-1, k); ++i){
		ans += (mcomb(n, i, mod)*mcomb(n - 1, i, mod))%mod;
		ans %= mod;
	}cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
struct node
{
	 int v;
	 ll w;
	 node(ll sw,int sv)
	 {
	 	 w=sw;
	 	 v=sv;
	 }
};
const int N=2e5+5;
vector<node>v[2*N+1];
int vis[N]={0},vis1[N]={0};
void dfs(int u,ll d)
{
	 
	 for(int i=0;i<v[u].size();i++)
	 {
	 	 int vv=v[u][i].v;
	 	 if(vis1[vv])continue;
	 	 vis1[vv]=1;
	 	 if((d+v[u][i].w)%2)vis[vv]=1;
	 	
	 	 	 dfs(vv,d+v[u][i].w);
		  
	 }
}
int main()
{
  int n=rr;

  memset(vis,0,sizeof(vis));
  rep(i,0,n-1)
  {
  	 int x=rr,y=rr;
	   ll w;
  	 cin>>w;
  	 v[x].push_back(node(w,y));
  	 v[y].push_back(node(w,x));
  	 
  }
  vis1[1]=1;
  dfs(1,0);
  for(int i=1;i<=n;i++)
  printf("%d\n",vis[i]);
}




Measured memory_bytes: 17664
#include<bits/stdc++.h>
using namespace std;
#define infi 100000000000009
#define int long long
int value[101];
int weight[101];
int dp[101][100001];
int  n;

 int rec(int idx,int val)
 {
     if(dp[idx][val] != -1) return dp[idx][val] ; 

     if(idx >= n) return (val > 0) ? infi : 0 ;
     if(val<0) return 0;
     // if(value[idx]>val) return rec(idx+1,val);
     return dp[idx][val] = min(rec(idx+1,val),weight[idx]+rec(idx+1,val-value[idx]));
 }
signed main()
{
    
    cin>>n;
    int w;
    cin>>w; 
    int tot=0;  
    for(int i=0;i<n;i++)
    { 
        cin>>weight[i]>>value[i];
        tot+=value[i];

    }
    memset(dp, -1, sizeof(dp));
    for(int i=tot;i>=1;i--)
    {
        if(rec(0,i)<=w)
        {
            cout << i ; return 0 ; 
        }
    }
    
    cout << 0 ; 

    return 0;


}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

bool is_prime(int n) {
  for (int i = 2; i * i <= n; ++i) {
    if (n % i == 0) return false;
  }
  return n != 1;
}

int main() {
  int a, d, n;
  while (cin >> a >> d >> n) {
    if (a == 0 && d == 0 && n == 0) break;
    int cnt = 0;
    int i = 0;
    while (true) {
      int val = a + i * d;
      if (is_prime(val)) cnt++;
      if (cnt == n) {
        cout << val << endl;
        break;
      }
      i++;
    }
  }
  return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

LL dp[MAXN];

int main(){
  fio();
  int n,w; cin>>n>>w;
  forn(i,n){
  	LL a,b; cin>>a>>b;
  	for(LL i = w; i>=0;i--){
  		if(i+a>w) continue;
  		dp[i+a] = max(dp[i+a], dp[i] + b);
  	}
  }
  LL an = 0;
  for1(i,w){
  	an = max(an, dp[i]);
  }
  cout<<an<<endl;
  return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,k;
  char s[100],w[100],t[100],ans[100]={127};
  scanf("%s %s",s,t);
  for(i=0;s[i];i++){
    for(j=0;t[j];j++){
      if(s[i+j]==0)break;
      if(s[i+j]==t[j]||s[i+j]=='?')continue;
      else break;
    }
    if(t[j]==0){//printf("%d\n",i);
      for(k=0;s[k];k++){
	w[k]=s[k];
	if(w[k]=='?')w[k]='a';
      }
      w[k]=0;
      for(k=0;t[k];k++)w[k+i]=t[k];
      if(strcmp(ans,w)>0)strcpy(ans,w);
    }
  }//printf("%d\n",ans[0]);
  printf("%s\n",ans[0]-127?ans:"UNRESTORABLE");
  return 0;
}
    


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

using namespace std;

#define ll long long
#define F first
#define S second
#define ii pair < int , int >

const int N=15;
vector<ii> v[N];
int a[N];
int ans=0;
bool vis[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0; i<n; i++)
    {
        int sz;
        scanf("%d",&sz);
        for(int j=0; j<sz; j++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            ii z;
            z.F=x-1;
            z.S=y;
            v[i].push_back(z);
        }
    }
    int ans=0;
    for(int msk=0; msk<pow(2,n); msk++)
    {
        bool q=1;
        for(int i=0; i<n; i++)
        {

            if((1<<i) & msk)
                for(auto x:v[i])
                {
                    if(x.S==1 && ((1<<x.F)&msk)==0){
                        q=0;
                        //cout<<msk<<" "<<i<<endl;
                    }
                    if(x.S==0 && (1<<x.F & msk))
                        q=0;
                }
            if(!q)
                break;
        }
        if(!q)
            continue;
        ans=max(ans,__builtin_popcount(msk));
    }
cout<<ans;

}


Measured memory_bytes: 3988
import math
from functools import reduce

def lcm_base(x, y):
	return (x * y) // math.gcd(x, y)

def lcm(*numbers):
	return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
	return reduce(lcm_base, numbers, 1)

n = int(input())
t = [0]*n
for i in range(n):
	t[i] = int(input())
print(lcm_list(t))

Measured memory_bytes: 9576
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>   // popen, pclose, fgets
#include <cstdlib> 
using namespace std;
#define rep0(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>;
using ll = long long; //10e19までいける
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll =vector<vvll>;
const double PI=3.14159265358979323846;
//小数点以下を指定したい時　　→→→→  cout << fixed << setprecision();
//int→string
//string→int   int num = atoi(numStr.c_str());

int main() {
        cout << fixed << setprecision(5);
    int n;cin>>n;
    vector<double> x(n);
    vector<string> u(n);
    rep0(i,n){
        cin>>x[i]>>u[i];
    }
    double sum=0;
    rep0(i,n){
        if(u[i]=="JPY"){
            sum+=x[i];
        }
        else{
            sum+=x[i]*380000;
        }
    }
    cout << fixed << setprecision(5)<<sum<<endl;
}

Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1000000007;

int main(){
  int H,W;cin >> H >> W;
  vector<string> S(H);
  int cnt=0;
  for(int i=0;i<H;i++){
    cin >> S[i];
    for(int j=0;j<W;j++){
      if(S[i][j]=='#'){
        cnt ++;
      }
    }
  }
  vector<vector<bool>> P(H,vector<bool>(W,false));
  queue<int> X;
  queue<int> Y;
  queue<int> D;
  X.push(0);
  Y.push(0);
  D.push(1);
  P[0][0] = true;
  int goalD=0;
  while(!X.empty()){
    int x = X.front(),y=Y.front(),d=D.front();
    X.pop();Y.pop();D.pop();
    if(x==H-1&&y==W-1){
      goalD = d;
      break;
    }
    if(x-1>=0){
      if(S[x-1][y]=='.'&&!P[x-1][y]){
        X.push(x-1);Y.push(y);D.push(d+1);
        P[x-1][y] = true;
      }
    }
    if(x+1<H){
      if(S[x+1][y]=='.'&&!P[x+1][y]){
        X.push(x+1);Y.push(y);D.push(d+1);
        P[x+1][y] = true;
      }
    }
    if(y-1>=0){
      if(S[x][y-1]=='.'&&!P[x][y-1]){
        X.push(x);Y.push(y-1);D.push(d+1);
        P[x][y-1] = true;
      }
    }
    if(y+1<W){
      if(S[x][y+1]=='.'&&!P[x][y+1]){
        X.push(x);Y.push(y+1);D.push(d+1);
        P[x][y+1] = true;
      }
    }
  }
  if(P[H-1][W-1]){
    cout << H*W - cnt - goalD << endl;
  }else{
    cout << -1 << endl;
  }
}

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

int main() {
  int n,l;
  cin >> n >>l;
  int ans=0;
  
  int start = l;
  int last = n+l-1;
  
  if(start<0 && last>0){
    ans=(n+2*l-1)*(n)/2;
  }else if(start<0 && last<=0){
    ans=(n+2*l-2)*(n-1)/2; //lastを食べる
  }else if(start>=0){
    ans=(n+2*l)*(n-1)/2;// startをたべる
  }
  
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  string s;
  cin>>s;
  bool exist[26];
  rep(i,26) exist[i]=false;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<26;j++){
      if(s[i]==alp[j]) exist[j]=true;
    }
  }
  bool judge=false;
  char ans;
  for(int i=0;i<26;i++){
    if(!exist[i]){
      judge=true;
      ans=alp[i];
      break;
    }
  }
  if(!judge) cout<<"None"<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 3688
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

#include <set>
#include <map>

map<int, int> m;
map <int, int> cnt;
int n, t;
vi va;

void init()
{
	cin >> n >> t;
	va.resize(n);
	
	REP(i, n)
	{
		int tmp;
		cin >> tmp;

		m[tmp]++;
		va[i] = tmp;
	}
}

int main()
{
	init();

	int cur;

	REP(i, n - 1)
	{
		cur = va[i];

		m[cur]--;
		if (m[cur] == 0)
			m.erase(cur);

		int best = m.rbegin()->first;

		if (best - cur > 0)
			cnt[best - cur]++;
	}

	cout << cnt.rbegin()->second << endl;

}


Measured memory_bytes: 5376