akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main{
    static Scanner sc=new Scanner(System.in);
    public static void main(String args[]){
        int a,b,c,x;
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        x=sc.nextInt();

        int ans=0;
        for(int i=0;i<=a;i++){
            for(int j=0;j<=b;j++){
                for(int k=0;k<=c;k++){
                    if(500*i+100*j+50*k==x){
                        ans++;
                    }
                }
            }
        }
        System.out.print(ans+"\n");
    }
}

Measured memory_bytes: 21844
a,s,d,f=map(int,input().split())
dp=[[0]*(f+1) for i in range(d+1)]
dp[a][s]=1
mod=998244353

for x in range(a,d+1):
    for y in range(s,f+1):
        if x==a and y==s:continue
        dp[x][y]=(dp[x-1][y]*y+dp[x][y-1]*x-dp[x-1][y-1]*(x-1)*(y-1))%mod
        
print(dp[d][f])


Measured memory_bytes: 134056
def cntLetter(s):
    cnt = 0
    ans = 0
    for i in range(len(s)):
        if (s[i] == 'A') or (s[i] == 'T') or (s[i] == 'C') or (s[i] == 'G'):
            cnt += 1  
            ans = max(ans, cnt)
        else:
            cnt = 0
    return ans

def main():
    s = input()
    print(cntLetter(s))
main()

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <iostream>
#include <iomanip>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

const int INF=1e9;
const ll INFF=1e17;
const double EPS=1e-9;
const ll MOD=1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin >> a >> b;
	cout << ((!(a%3) || !(b%3) || !((a+b)%3))?"Possible":"Impossible") << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int H, W, N, Sy, Sx;
bool in(int l, int r, int p){
  return p <= r && p >= l;
}
int main(){
  cin >> H >> W >> N >> Sy >> Sx;
  Sy--;Sx--;
  string S, T; cin >> S >> T;
  int R = W - 1, L = 0, D = H - 1, U = 0;
  bool f = true;
  for(int i = N - 1; i >= 0 && f; --i){
    switch(T[i]){
    case 'U':
      if(D != H - 1)D++;
      break;
    case 'D':
      if(U != 0)U--;
      break;
    case 'R':
      if(L != 0)L--;
      break;
    case 'L':
      if(R != W - 1)R++;
    }
    switch(S[i]){
    case 'U':U++;break;
    case 'D':D--;break;
    case 'R':R--;break;
    case 'L':L++;break;      
    }
    if(R < L)f = false;    
    if(D < U)f = false;    
  }
  f &= in(L,R,Sx);
  f &= in(U,D,Sy);
  cout << (f?"YES":"NO") << endl;
  return 0;
}


Measured memory_bytes: 776
#include "bits/stdc++.h"
using namespace std;

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(ll i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(ll j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


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

    int H, W, h, w;
    cin >> H >> W >> h >> w;

    cout << ((H - h) * (W - w)) << endl;

    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a,c,d,max,min;
    long g;
    max = -1000000;
    min = 1000000;
    d = 0;
    g = 0;
    scanf("%d",&c);
    while(c > d){
        scanf("%d",&a);
        if(a > max){
            max = a;
        }
        if(a < min){
            min = a;
        }
        g = g + a;
        d ++;
    }
    printf("%d %d %ld\n",min,max,g);
    return 0;
}



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

/*
 * seenとwaitを渡して探索地点がなくなるまで再起関数を回す
 */

//N:頂点の数，M:辺の数
int N, M;
int cnt = 0;

vector<vector<int>> v(10,vector<int>(10));
vector<int> used;


int dfs(int now, int depth){
    // すでに訪れた頂点なら終了する
    if(used[now] == 1) return 0;

    // depthがNなら有効なパスなので1を返す
    if(depth == N) return 1;

    // 使用済みのフラグを立てる
    used[now] = 1;

    int ans = 0;

    // 全部の遷移先をチェックする
    for(int i = 0; i < N; i++){
        // nowから繋がっている頂点であれば，遷移を写す
        if(v[now][i]){
            ans += dfs(i, depth + 1);
        }
    }
    // 使用済みフラグを折る
    used[now] = 0;
    return ans;
}


int main() {
    cin >> N >> M;
    rep(i, M){
        int a, b;
        cin >> a >> b;
        --a; --b;
        v[a][b] = v[b][a] = 1;
    }
    used = vector<int>(N, 0);

    cout << dfs(0, 1) << endl;
    return 0;

}


Measured memory_bytes: 256
import math

def eratosthenes():
    limit = 100001
    B = [True for _ in range(limit + 1)]
    C = [0 for i in range(limit + 1)]
    for i in range(2, limit):
        if i >= math.sqrt(limit):
            break
        for ii in range(i ** 2, limit, i):
            B[ii] = False
    for i in range(3, limit + 1, 2):
        if B[i] and B[(i + 1) // 2]:
            C[i] += 1
    for i in range(3, limit + 1):
        C[i] += C[i - 1]
    return C


def main():
    Q = int(input())
    C = eratosthenes()
    ans = []
    for _ in range(Q):
        l, r = map(int, input().split())
        ans.append(C[r] - C[l - 1])
    for c in ans:
        print(c)


main()


Measured memory_bytes: 10784
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

#ifdef DEBUG
#define dprintf      printf
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)    {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for((i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(1){}else
#define drep(i,n)    if(1){}else
#define dstop()      if(1){}else
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__);
#define array(T,id,n) T id[n]; rep(i,n)cin>>id[i];

//#define int long long;
#ifndef int
#define INF  (0x7fffffff)
#else
#define LINF (0x7fffffffffffffff)
#endif

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}
#define UNION_FIND_MAX_N (112345)
int union_find_par[UNION_FIND_MAX_N];
int union_find_rank[UNION_FIND_MAX_N];

void init(int n)
{
  int i;
  for(i=0;i<n;i++)
    {
      union_find_par[i]=i;
      union_find_rank[i]=0;
    }
}

int find(int x)
{
  if(union_find_par[x]==x)
    return x;
  else
    return union_find_par[x]=find(union_find_par[x]);
}

void unite(int x,int y)
{
  x=find(x);
  y=find(y);
  if(x==y)
    return;
  if(union_find_rank[x]<union_find_rank[y])
    union_find_par[x]=y;
  else
    union_find_par[y]=x;
  if(union_find_rank[x]==union_find_rank[y])
    union_find_rank[x]++;
}

int nsame(int x,int y)
{
  return find(x)!=find(y);
}

typedef struct edge
{
  int u;
  int v;
  int cost;
  bool operator>(const edge&right)const
  {
    return cost>right.cost;
  }
  bool operator<(const edge&right)const
  {
    return cost<right.cost;
  }
}Edge;

signed main(void)
{
  int n;
  Edge edge[112345]={};
  int i,j,k=0;
  int sum=0;
  cin>>n;
  init(n);
  rep(i,n)rep(j,n)
    {
      cin>>edge[k].cost;
      edge[k].u=i;
      edge[k].v=j;
      k++;
    }
  sort(edge,edge+k);
  rep(i,k)
    if(edge[i].cost!=-1)
      if(nsame(edge[i].u,edge[i].v))
	unite(edge[i].u,edge[i].v),sum+=edge[i].cost;
  
  cout<<sum<<endl;    
  return 0;
}

Measured memory_bytes: 4412
#include <stdio.h>
#include <string.h>

#define MAX (123456 * 2 + 1)

char prime[MAX];

int main(void)
{
    int i, j;

    memset(prime, 1, sizeof(prime));
    prime[0] = prime[1] = 0;
    for (i = 4; i < MAX; i += 2)
        prime[i] = 0;
    for (i = 3; i * i < MAX; i += 2)
        if (prime[i])
            for (j = i * 2; j < MAX; j += i)
                prime[j] = 0;

    for (;;) {
        int n, c = 0;

        scanf("%d", &n);
        if (n == 0)
            break;

        for (i = n + 1; i <= n * 2; ++i)
            if (prime[i])
                ++c;

        printf("%d\n", c);
    }


    return 0;
}

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

#define MIN(a, b) (((a)<(b))?(a):(b))

int main(int argc, char **argv)
{
  int p = 0;
  int q = 0;
  int r = 0;
  int min = 0;

  scanf("%d %d %d", &p, &q, &r);

  min = MIN(p+q, p+r);
  min = MIN(min, q+r);

  printf("%d\n", min);

  return 0;
}


Measured memory_bytes: 128
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 5e3 + 10;
void cmp(string& s1, string& s2)
{
	if (s1.length() > s2.length()) puts("GREATER"), exit(0);
	if (s1.length() < s2.length()) puts("LESS"), exit(0);
	for (int i = 0; i < s1.length(); i++)
	{
		if (s1[i] == s2[i]) continue;
		if (s1[i] > s2[i]) puts("GREATER"), exit(0);
		else puts("LESS"), exit(0);
	}
	puts("EQUAL");
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s1, s2;
	cin >> s1 >> s2;
	cmp(s1, s2);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
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 x = a+b; 
      
      if(x>=c){
         System.out.print("Yes");
      }else{
        System.out.print("No");
      }

    }
}

Measured memory_bytes: 23636
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    digits = len(str(n))

    ans = 0
    for i in range(1, digits+1):
        if i % 2 == 0:
            continue

        limit = n+1 if i == digits else 10**i
        for j in range(10**(i-1), limit):
            ans += 1

    print(ans)


Measured memory_bytes: 2940
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long K){
    vll a{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cout<<a[K-1]<<endl;
}

int main(){
    long long K;
    scanf("%lld",&K);
    solve(K);
    return 0;
}


Measured memory_bytes: 256
L = int(input())
v = list(map(int,bin(L)[:2:-1]))
N = len(v)+1
edges = []
unit = 1
for i in range(N-1):
    L -= unit*v[i]
    edges.append((i+1, i+2, 0))
    edges.append((i+1, i+2, unit))
    if v[i]:
        edges.append((i+1, N, L))
    unit *= 2

print(N, len(edges))
for a, b, c in edges:
    print(a, b, c)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
	int W,H,x,y,r;
	
	cin>>W>>H>>x>>y>>r;
	if (x-r>=0 && x+r<=W && y-r>=0 && y+r<=H)
	cout<<"Yes"<<endl;
	
	else
	cout<<"No"<<endl; 
	
	
	return 0;
	
}


Measured memory_bytes: 3096
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

void solve(long long N, long long M) {
  ll ans = (1900 * M + 100 * (N - M)) * pow(2, M);
  print(ans);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  solve(N, M);
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	var n, k, a int
	var dp [2][]int

	fmt.Fscan(fp, &n, &k)

	prev := 0
	current := 1
	dp[prev] = make([]int, k+1)
	dp[current] = make([]int, k+1)
	dp[prev][0] = 1
	for i := 0; i < n; i++ {
		fmt.Fscan(fp, &a)
		sum := 0
		for j := 0; j <= k; j++ {
			sum += dp[prev][j]
			if j-a-1 >= 0 {
				sum -= dp[prev][j-a-1]
			}
			dp[current][j] = sum
			dp[current][j] %= 1000000007
		}

		current, prev = prev, current
	}

	fmt.Println(dp[prev][k])

}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
const int SIZE = 3000;
int dp[SIZE+1][SIZE+1];
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   string s, t; cin >> s >> t;
   rep(i,s.size())rep(j,t.size()){
      dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      if (s[i] == t[j])
         dp[i+1][j+1] = dp[i][j] + 1;
   }
   string lcs;
   int x = s.size(), y = t.size();
   while (dp[x][y] != 0)
   {
      if (dp[x][y] == dp[x-1][y])x--;
      else if (dp[x][y] == dp[x][y-1])y--;
      else if (dp[x][y]-1 == dp[x-1][y-1]){
         x--;y--;
         lcs.push_back(s[x]);
      }
   }
   reverse(lcs.begin(),lcs.end());
   cout << lcs << endl;
}

Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main(){
	int n;
  	cin >> n;
 	vector<int> a(n);
 	rep(i,n) cin >> a[i];
  	
 	sort(a.begin(), a.end());
  
  	int p = a.size() / 2;
  	int l = a[0];
  	int r = a[a.size() - 1];
  	while (true) {
      p = (r + l) / 2;
      int count = 0, countLeft = 0, countRight = 0;
      for (int i = 0; i < n; i++) {
        count += (p - a[i]) * (p - a[i]);
        countLeft += (p - 1 - a[i]) * (p - 1 - a[i]);
        countRight += (p + 1 - a[i]) * (p + 1 - a[i]);
      }
      /*
      cout << "p:" << p << endl;
      cout << count << endl;
      cout << countLeft << endl;
      cout << countRight << endl;
      */

      if (countLeft >= count and countRight >= count) {
        cout << count << endl;
        return 0;
      }
      if (countLeft < count) {
        r = p - 1;
      } else {
        l = p + 1;
      }
    }
  	return 0;
}

Measured memory_bytes: 256
def main():
    A = int(input())
    B = int(input())
    C = int(input())
    X = int(input())

    cnt = 0
    for ia in range(A+1):
        for ib in range(B+1):
            for ic in range(C+1):
                if 500*ia + 100*ib + 50*ic == X: cnt +=1

    print(cnt)    

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<stdio.h>
int main(void){
int N,K,i,n=1;
scanf("%d",&N);
scanf("%d",&K);
for(i=1;i<=N;i++){
if((2*n)>(n+K)) n = n+K;
if((2*n)<=(n+K)) n = 2*n;
}
printf("%d",n);
return 0;
}

Measured memory_bytes: 128
# Aizu Problem 00161: Sport Meet
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")



    
while True:
    n = int(input())
    if n == 0:
        break
    teams = []
    for _ in range(n):
        team, m1, s1, m2, s2, m3, s3, m4, s4 = [int(__) for __ in input().split()]
        time = 60 * m1 + s1 + 60 * m2 + s2 + 60 * m3 + s3 + 60 * m4 + s4
        teams.append([team, time])
    teams = sorted(teams, key=lambda x: (x[1], x[0]))
    print(teams[0][0])
    print(teams[1][0])
    print(teams[-2][0])

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

typedef long long ll;
ll f[200001], finv[200001], dp[200001], ans[200001];
int child[200001];
const ll mod = 1000000007;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

vector<int> v[200001];
int n;

void dfs(int p, int x){
    child[x] = 1;
    for(int j : v[x]){
        if(j == p)  continue;
        dfs(x, j);
        child[x] += child[j];
    }
    dp[x] = f[child[x]-1];
    for(int j : v[x]){
        if(j == p)  continue;
        dp[x] = dp[x]*finv[child[j]]%mod*dp[j]%mod;
    }
}

void dfs2(int p, int x){
    for(int j : v[x]){
        if(j == p)  continue;
        ans[j] = ans[x]*f[n-1-child[j]]%mod*f[child[j]]%mod*modpow(dp[j], mod-2)%mod*finv[n-child[j]]%mod;
        for(int k : v[j]){
            if(k == x)  continue;
            ans[j] = ans[j]*finv[child[k]]%mod*dp[k]%mod;
        }
        dfs2(x, j);
    }
}

int main(){
    f[0] = finv[0] = 1;
    for(int i = 1; i <= 200000; i++){
        f[i] = f[i-1]*i%mod;
    }
    finv[200000] = modpow(f[200000], mod-2);
    for(int i = 199999; i >= 1; i--){
        finv[i] = finv[i+1]*(i+1)%mod;
    }

    cin >> n;
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    dfs(0, 1);
    ans[1] = dp[1];
    dfs2(0, 1);
    for(int i = 1; i <= n; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 21872
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;


double l[20],a[20],b[20];

double dis(int x, int y){
  return (l[x]-l[y])*(l[x]-l[y]) + (a[x]-a[y])*(a[x]-a[y]) + (b[x]-b[y])*(b[x]-b[y]);
}

int main(){
  int n,m;
  double dp[1<<20];
  
  cin >> n >> m;

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

  for(int i=0;i<(1<<n);i++)dp[i] = 0.0;

  for(int i=0;i<(1<<n);i++){
    for(int j=0;j<n;j++){
      if( i & (1<<j) ){
	int tmp = i - (1<<j);

	double sum = 0.0;
	for(int k=0;k<n;k++){
	  if( tmp & (1<<k) )sum += dis(j,k);
	}
	dp[i] = max(dp[i],dp[tmp] + sum);
      }
    }
  }

  double mx = 0.0;
  for(int i=0;i<(1<<n);i++){
    int cnt = 0;
    for(int j=0;j<n;j++){
      if(i & (1<<j) )cnt++;
    }
    if(cnt == m)mx = max(dp[i],mx);
  }
  printf("%.8lf\n",mx);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

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

int main(void) {
	LL a, b, x;
	cin >> a >> b >> x;
	cout << ((b - a + (a % x)) / x) + (a % x == 0) << endl;
}


Measured memory_bytes: 256
N = int(input())


def dfs(s):  # 文字sで始まる七五三数の個数
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s+c)
    return ret


print(dfs('0'))


Measured memory_bytes: 2940
N, K = map(int, input().split())
A = list(map(int, input().split()))

mod = 10**9 + 7
B, C = [0]*N, [0]*N
for i in range(N):
    ai = A[i]
    for j in range(i, N):
        aj = A[j]
        if ai > aj:
            B[i] += 1
    for j in range(i + 1):
        aj = A[j]
        if ai > aj:
            C[i] += 1

ans = (sum(B) * K * (K + 1) // 2) % mod
ans += (sum(C) * (K - 1) * K // 2) % mod
print(ans % mod)


Measured memory_bytes: 42092
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

enum Type{
	Zero,
	One,
	Two,
};

struct Info{
	Info(int arg_node_id,int arg_diff){
		node_id = arg_node_id;
		diff = arg_diff;
	}
	bool operator<(const struct Info & arg) const{
		return diff < arg.diff;
	}
	int node_id,diff;
};

int N;
int point[NUM];
int value[NUM][3];
vector<int> G[NUM];


void dfs(int node_id,int parent){

	int tmp_value = point[node_id];
	int child,tmp;

	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i];
		if(child == parent)continue;

		dfs(child,node_id);

		tmp = value[child][Zero]-2;

		if(tmp >= 0){
			tmp_value += tmp;
		}
	}

	value[node_id][Zero] = tmp_value;

	priority_queue<Info> Q;

	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i];
		if(child == parent)continue;

		Q.push(Info(child,(value[child][One]-1)-max(0,value[child][Zero]-2)));
	}

	value[node_id][One] = value[node_id][Zero];

	if(Q.empty() == false && Q.top().diff > 0){

		value[node_id][One] += Q.top().diff;
		Q.pop();

		if(Q.empty() == false && Q.top().diff > 0){
			value[node_id][Two] = value[node_id][One]+Q.top().diff;
		}
	}

	for(int i = 0; i < G[node_id].size(); i++){

		child = G[node_id][i];
		if(child == parent)continue;

		if(value[node_id][Two] < value[node_id][Zero]+(value[child][Two]-2)-max(0,value[child][Zero]-2)){
			value[node_id][Two] = value[node_id][Zero]+(value[child][Two]-2)-max(0,value[child][Zero]-2);
		}
	}
}

int main(){

	scanf("%d",&N);

	for(int i = 0; i < NUM; i++){
		value[i][Zero] = 0;
		value[i][One] = -BIG_NUM;
		value[i][Two] = -BIG_NUM;
	}

	for(int i = 0; i < N; i++){
		scanf("%d",&point[i]);
	}

	int from,to;

	for(int loop = 0; loop < N-1; loop++){

		scanf("%d %d",&from,&to);
		from--;
		to--;
		G[from].push_back(to);
		G[to].push_back(from);
	}

	queue<int> Q;
	for(int i = 0; i < N; i++){
		if(G[i].size() == 0){
			Q.push(i);
		}
	}

	dfs(0,-1);
	int ans = -BIG_NUM;

	for(int i = 0; i < N; i++){
		ans = max(ans,max(value[i][Zero],max(value[i][One],value[i][Two])));
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 22820
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e9)
using namespace std;
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    ll cnt = 0;
    while(X > 0){
        cnt++;
        X -= cnt;
    }
    print(cnt);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
#define foreach(i,A) for(auto &i:A)
#define all(A) A.begin(),A.end()
#define len(A) (ll)A.size()
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
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(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n, k;
  cin >> n >> k;
  vector<int> A(n), pos_A, neg_A;
  rep(i, n){
    cin >> A[i];
    if(A[i] > 0) pos_A.push_back(A[i]);
    else if(A[i] < 0) neg_A.push_back(-A[i]);
  }
  sort(pos_A.begin(), pos_A.end());
  sort(neg_A.begin(), neg_A.end());
  ll pos = pos_A.size(), neg = neg_A.size(), zero = n - pos - neg;
  ll pair_neg = pos * neg, pair_zero = zero * (pos + neg) + zero * (zero - 1) / 2;

  // result is zero
  if(pair_neg < k && k <= pair_neg + pair_zero){
    cout << 0 << endl;
  }

  // result is negative
  else if(k <= pair_neg){
    k = pair_neg - k + 1;
    ll left = 0, right = 1e18 + 1;
    while(right - left > 1){
      ll mid = (left + right) / 2;
      if([&](ll x){
        ll res = 0;
        foreach(a, pos_A){
          res += upper_bound(neg_A.begin(), neg_A.end(), x / a) - neg_A.begin();
        }
        return res;
      }(mid) < k){
        left = mid;
      } else {
        right = mid;
      }
    }
    cout << -right << endl;
  }

  // result is positive
  else {
    k -= pair_neg + pair_zero;
    ll left = 0, right = 1e18 + 1;
    while(right - left > 1){
      ll mid = (left + right) / 2;
      if([&](ll x){
        ll res = 0;
        for(auto it = pos_A.begin(); it != pos_A.end(); it++){
          res += upper_bound(pos_A.begin(), it, x / *it) - pos_A.begin();
        }
        for(auto it = neg_A.begin(); it != neg_A.end(); it++){
          res += upper_bound(neg_A.begin(), it, x / *it) - neg_A.begin();
        }
        return res;
      }(mid) < k){
        left = mid;
      } else {
        right = mid;
      }
    }
    cout << right << endl;
  }
}

Measured memory_bytes: 2168
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

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

	vector<int> A(N), B(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}

	vector<pair<int, int>> AB(N);
	
	for (int i = 0; i < N; i++) {
		AB[i] = make_pair(A[i], B[i]);
	}
	sort(AB.begin(), AB.end());

	long long ans = 0;

	for (int i = 0; i < N; i++) {
		int buy = min(M, AB[i].second);

		ans += (long long)buy * AB[i].first;

		M -= buy;
	}

	cout << ans << endl;


		 
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
 
using namespace std;
 
bool isPrime[60000];
 
int main(void){
  fill(isPrime, isPrime+60000, true);
  for(int i=2;i<60000;i++){
    if(isPrime[i]){
      for(int j=2; i*j<60000;j++){
	isPrime[i*j] = false;
      }
    }
  }
 
  int n;
  while(cin >> n){
    int tmp=1;
    int mini=0, maxi = 0;
    while(1){
      if(mini == 0 && isPrime[n-tmp] == true) mini = n-tmp;
      if(maxi == 0 && isPrime[n+tmp] == true) maxi = n+tmp;
      if(mini != 0 && maxi != 0) break;
      tmp++;
    }
    cout << mini << " " << maxi << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            //#define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                ios_base::sync_with_stdio(false);
                cin.tie(NULL);
                lli t,n,i,j,b,a,k,q,m;
                cin>>n;
                vector<lli> v(n);
                rep(i,n)cin>>v[i];
                map<lli,lli> mp;
                rep(i,n)mp[v[i]]++;
                lli ans=0;
                for(auto it=mp.begin();it!=mp.end();it++){
                    lli g=it->second;
                    ans+=(g*(g-1))/2ll;
                }
                rep(i,n){
                    lli g=ans;
                    lli f=mp[v[i]];
                    g-=(f*(f-1))/2ll;
                    g+=((f-1)*(f-2))/2ll;
                    cout<<g<<endl;
                }




            }



Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main()
{
	int i,n,x;
	cin >> n;
	for (i=1;i<n+1;i++)
	{
		if (i % 3 == 0) {
			cout << " " << i;
		} else {
			x = i;
			while (x) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}
	cout << endl;
	return 0;
}

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

#define int 		long long
#define vi 			vector <int>
#define si 			set <int>
#define pii 		pair<int,int>
#define fr(n) 		for(__typeof(n) i=0;i<n;i++)
#define rep(i,a,b) 	for(__typeof(b) i=a;i<b;i++)
#define repi(i,b,a) for(__typeof(a) i=b;i>=a;i--)
#define tr(a) 		for(auto it=a.begin();it!=a.end();it++)
#define pb 			push_back
#define mp 			make_pair
#define F 			first
#define S 			second
#define FAST 		ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define time_passed	1.0 * clock() / CLOCKS_PER_SEC

void solve()
{
	int n,m;
	cin>>n>>m;
	int s,c;
	int a[n],flag=0;
	memset(a,-1,sizeof(a));
	fr(m)
	{
		cin>>s>>c;
		s--;
		if(a[s]==-1)
		{
			a[s]=c;
		}
		else if(a[s]!=c)
		{
			flag=1;
		}
	}
	int cnt=0;
	if(a[0]==0 and n>1)
		flag=1;
	if(a[0]==-1 and n>1)
		a[0]=1;
	else if(a[0]==-1 and n==1)
		a[0]=0;
	if(flag)
		cout<<-1;
	else
	{
		for(int i=0;i<n;i++)
		{
			if(a[i]==-1)
				cout<<0;
			else
				cout<<a[i];
		}
	}
}

signed main()
{
	FAST
	int test=1;
	//cin>>test;
	while(test--)
	{
		solve();
	}
	cerr<<endl<<"Time elapsed : "<<time_passed<<endl;
	return 0;
}

Measured memory_bytes: 3772
//https://atcoder.jp/contests/abc166/tasks/abc166_b
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	ll k;
	cin>>k;
	vector<bool> ans;
	ans.resize(n);
	ll cnt=0;
	ll i;
	for(i=1;i<=k;i++)
	{
		ll snack;
		cin>>snack;
		vector<ll> lis;
		lis.resize(snack);
	
		ll j;
		for(j=0;j<snack;j++)
		{
			cin>>lis[j];
			ans[lis[j]-1]=true;
		}
	}
	for(i=0;i<n;i++)
	{
		if(ans[i]==false)
		{
			cnt=cnt+1;
		}
	}
	cout<<cnt<<"\n";
	return 0;
}

Measured memory_bytes: 3656
n = int(input())
s1 = [int(input()) for i in range(n)]
total = sum(s1)
if total%10 != 0:
    print(total)
else:
    s1.sort()
    s2=[s for s in s1 if s%10!=0]
    if s2:
        print(total-s2[0])
    else:
        print(0)


Measured memory_bytes: 2940
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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;
}

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int next_combination(int sub) {
    int x = sub & -sub, y = sub + x;
    return (((sub & ~y) / x) >> 1) | y;
}

int main() {
   int N, K;
   cin >> N >> K;
   int L = (N - 1) * (N - 2) / 2 - K;
   if (L < 0) {
      cout << -1 << endl;
      return 0;
   } else {
      cout << N - 1 + L << endl;
      for (int i = 1; i < N; i++) {
         cout << i << " " << N << endl;
      }
      int cnt = 0;
      for (int i = 1; i <= N - 1; i++) {
         for (int j = i + 1; j <= N - 1; j++) {
            if (cnt == L) return 0;
            cout << i << " " << j << endl;
            cnt++;
         }
      }
   }

}


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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);


void solve(int testCase){

    int n , W;
    scanf("%d %d" , &n , &W);

    vi v(n , 0) , w(n , 0);
    for(int i = 0 ; i < n ; i ++){
            scanf("%d %d" , &w[i] , &v[i]);
    }

    vl dp(W + 1 , 0);

    for(int i = 0 ; i < n ; i ++){
            for(int j = W ; j >= 0 ; j --){
                    if(j - w[i] < 0)continue;
                    dp[j] = max(dp[j] , dp[j - w[i]] + 1ll * v[i]);
            }
    }

    ll ans = *max_element(dp.begin() , dp.end());
    printf("%lld\n" , ans);

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


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

int main(){
  int n;
  const int haiku[5]={5,7,5,7,7};
  while(cin>>n,n){
    vector<string> w(n);
    for(int i=0;i<n;i++) cin>>w[i];
    int res=-1;
    for(int i=0;i<n && res==-1;i++){
      int stage=0;
      int cnt=0;
      for(int j=i;j<n;j++){
	cnt+=w[j].size();
	if(cnt==haiku[stage]){
	  stage++;
	  cnt=0;
	}
	if(stage==5){
	  res=i+1;
	  break;
	}

      }
    }
    cout<<res<<endl;
  }
  return 0;
}

Measured memory_bytes: 3176
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long LL;
LL F[110][10];
LL P[110][10];
LL gg[10];
LL min=-1000000007;
LL my_max(LL a,LL b)
{
	return a>b ? a:b;
}
void dfs(int now,int N)
{
	if(now==10)
	{
		int flag=0;
		for(int p=0;p<10;p++)
			if(gg[p]==1)
				flag=1;
		if(!flag)
			return;
		LL sum=0;
		for(int i=0;i<N;i++)
		{
			int pp=0;
			for(int k=0;k<10;k++)
				if(gg[k]==F[i][k] && gg[k]==1)
					pp++;
			sum+=P[i][pp];
		}
	/*	if(sum>min)
		{
			for(int i=0;i<10;i++)
				printf("%d ",gg[i]);
			printf("%d-%d\n",sum,min);
		//	printf("\n");
		}*/
		min=my_max(sum,min);
		return;
	}
	else
	{
		gg[now]=0;
		dfs(now+1,N);
		gg[now]=1;
		dfs(now+1,N); 
	}
}
int main()
{
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++)
		for(int k=0;k<10;k++)
			scanf("%lld",&F[i][k]);
	for(int i=0;i<N;i++)
		for(int k=0;k<=10;k++)
			scanf("%lld",&P[i][k]);
	dfs(0,N);
	printf("%lld\n",min);
	return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

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

long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}

class agc028_a {
public:
    void solve(istream& in, ostream& out) {
        int N, M;
        in >> N >> M;
        string S, T;
        in >> S >> T;
        for (int a = 1; a <= M; ++a) {
            long long len = 1LL * a * N;
            if (len % M == 0) {
                long long b = len / M;
                long long t = lcm(a, b);
                bool ok = true;
                for (long long i = 0; ok && i < len; i += t) {
                    if (i / a >= N || i / b >= M) {
                        ok = false;
                    } else if (S[i / a] != T[i / b]) {
                        ok = false;
                    }
                }
                if (ok) {
                    out << len << "\n";
                    return;
                }
            }
        }
        out << -1 << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	agc028_a solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int x,y,key,gcd,r,i,j;

    scanf("%d %d",&x, &y);
    if(x < y && 1 <= x && y <= (10^9)){
        key = x;
        x = y;
        y = key;
    }
    r = x % y;
    while(r != 0){
        x = y;
        y = r;
        r = x % y;
    }
    gcd = y;
    printf("%d\n",gcd);

    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
using namespace std;

vector<int> dp(100001,-1),h(100001);
int n;

int rec(int i){
  if(dp[i]>=0) return dp[i];
  int res;
  if(i>=n-1) res=0;
  else if(i==n-2){
    res=abs(h[i]-h[i+1]);
  }
  else {
    res=min(rec(i+1)+abs(h[i]-h[i+1]),rec(i+2)+abs(h[i]-h[i+2]));
  }
  return dp[i]=res;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  cout << rec(0) << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, ll>;

const int limit = 100010;
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d) {
depth[v] = d;
for (auto &e : tree[v]) {
 if (e.to == p) continue;
 dfs(e.to, v, d + e.cost);
 }
 }


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

 for (int i = 0; i < n - 1; ++i) {
 int a, b, c;
 cin >> a >> b >> c;
 a--, b--;
 tree[a].push_back({b, c});
 tree[b].push_back({a, c});
 }

 int q, k;
 cin >> q >> k;
 k--;

 dfs(k, -1, 0);
 for (int i = 0; i < q; ++i) {
 int x, y;
 cin >> x >> y;
 x--, y--;
 cout << depth[x] + depth[y] << endl;
 }

 return 0;
 }

#if 0
void dfs(int v, int p, vector<vector<P>> g, vector<ll> &dist, ll d){
    dist.at(v) = d;
    for(auto &u: g.at(v)){
        if(dist.at(u.first)!=-1) continue;
        dfs(u.first, v, g, dist, d+u.second);
    }
}

int main() {
    int n; cin >> n;
    vector<vector<P>> g(n+1);
    vector<ll> dist(n+1, -1);
    
    rep(i, n-1){
        int a, b, c; cin >> a >> b >> c;
        g.at(a).push_back(make_pair(b, c));
        g.at(b).push_back(make_pair(a, c));
    }

    int q, k; cin >> q >> k;
    dfs(k, -1, g, dist, 0);

    rep(i, q){
        int x, y; cin >> x >> y;
        cout << dist.at(x) + dist.at(y) << endl;
    }
    

    return 0;
}
#endif

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int n,i,j;
    bool flag=true;
     cin>>n;
   for(i=n;i>0;i++)
   {
       flag=true;
    for(j=2;j<=(i/2);j++)
    {
        if(i%j==0)
        {
          flag=false;
          break;
        }
    }
    if(flag==true)
    {
        cout<<i<<endl;
        i=-1;
    }
   }


}




Measured memory_bytes: 3600
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define N 100005
int dis1[N],dis2[N];
int n;
vector<int>g[N];
void dfs(int cur, int pre, int len, int dist[])
{
	int now;
	dist[cur]=len;
	for(int i=0;i<g[cur].size();++i)  
	{
		now=g[cur][i];
		if(now!=pre)
			dfs(now,cur,len+1,dist);
	}
}
int main()
{
	int i,x,y;
	scanf("%d",&n);
	for(i=0;i<n-1;++i)
	{
		scanf("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	dfs(1,-1,0,dis1);
	dfs(n,-1,0,dis2);
	int ans=0;
	for(i=2;i<n;++i)
	{
		if(dis1[i]<=dis2[i])
		ans++;
		else
		ans--;
	}
	if(ans>0)
	cout<<"Fennec";
	else
	cout<<"Snuke";
	return 0;
}

Measured memory_bytes: 14336
using System;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        var size = Console.ReadLine().Split()
            .Select(x => int.Parse(x))
            .ToArray();
        var linesQuery =
            from _ in Enumerable.Range(0, 2)
            select Console.ReadLine().Split()
                .Select(x => long.Parse(x))
                .ToArray();
        var lines = linesQuery.ToArray();
        
        const long mod = (long)(1e9 + 7);

        var total = new long[2];
        for (int a = 0; a < 2; ++a)
        {
            for (int i = 0; i < size[a]; ++i)
            {
                total[a] += (2 * i - size[a] + 1) * lines[a][i];
            }

            total[a] %= mod;
        }

        Console.WriteLine(total[0] * total[1] % mod);
    }
}


Measured memory_bytes: 32304
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadInt();
            int[] A = Input.ReadIntArray();

            int gcd = A[0];
            for (int i = 0; i < A.Length; i++)
            {
                gcd = GCD(gcd, A[i]);
            }
            Console.WriteLine(gcd);
        }

        // validation: AOJ 0005
        public static int GCD(int a, int b)
        {
            return b == 0 ? a : GCD(b, a % b);
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 21728
from itertools import accumulate
n, *A = map(int, open(0).read().split())
if A[0] != 0:
    if A[0] == 1 and n == 0:
        print(1)
    else:
        print(-1)
else:
    B = list(accumulate(A[::-1]))[::-1] + [0]
    C = [0] * (n+1)
    D = [0] * (n+1)
    C[0] = 1
    D[0] = 1

    for i in range(1, n+1):
        C[i] = min(B[i], 2*D[i-1])
        D[i] = C[i] - A[i]
        if D[i] < 0:
            print(-1)
            break
    else:
        print(sum(C))

Measured memory_bytes: 26128
//158 ABC C - Tax Increase
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    int a , b; cin >> a >> b;
    for(int64 i=1;i<=1000;++i){
        if(floor(i*0.08)==a && floor(i*0.10)== b ) { cout << i << endl; return 0; }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
    static Scanner scanner = new Scanner(System.in);
 
    public static void main(String[]$) {
        long n = scanner.nextInt() - 2, a = scanner.nextInt(), b = scanner.nextInt();
        System.out.println(a == b ? 1 : n == -1 || a > b ? 0 : n * (b - a) + 1);
    }
}

Measured memory_bytes: 23508
Module Module1
    Sub main()
        Dim user1 = Console.ReadLine()
        'Dim user1 = 1000000000

        Dim fiveMil As Long = Math.Floor(CLng(user1) / 500)
        user1 = user1 Mod 500
        Dim fiveCoin As Long = Math.Floor(CLng(user1) / 5)

        Console.WriteLine(fiveMil * 1000 + fiveCoin * 5)
    End Sub
end module

Measured memory_bytes: 28324
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

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

vector<int> k(n+1,0);
rep(i,m){
    int u,y;
    cin>>u>>y;
    k[u]++;
    k[y]++;
}
for(int i=1;i<=n;i++){
    if(k[i]%2==1){
        cout<<"NO"<<endl;
        return 0;
    }
}

cout<<"YES"<<endl;


    return 0;
}


Measured memory_bytes: 640