akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
#define forn(i,p,n); for(long long i=p;i<n;++i)
#define rofn(i,p,n); for(long long i=p;i>n;--i)
#define pb push_back
#define vi vector
#define ump unordered_map
void solve(){
	string s,t;
	cin >> s >> t;
	int len1 = s.length();
	int len2 = t.length();
	int curr = 0;
	int ans = INT_MAX;
	int i = 0;
	while(i<len1&&(i+len2)<=len1){
		int j = i;
		int k = 0;
		while(j<len1 && k<len2){
			if(s[j]!=t[k]){
				curr++;
			}
			j++;
			k++;
		}
		ans = min(curr,ans);
		curr = 0;
		i++;
	}
	cout<<ans;
}
 
int main()
{
	fast;
	//int test;
	//cin >> test;
	//while(test--){
		solve();
	//}
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  vector<vector <int> >a(n+1,vector<int>(n+1,0));

  for(int i = 1; i <= n; i++){
    for(int j = i; j <= n; j++){
      if(s[i-1] == s[j-1])a[i][j] = a[i-1][j-1]+1;
      else a[i][j] = 0;
    }
  }
  int ans = 0;
  for(int i = 1; i <= n; i++){
    for(int j = i; j <= n; j++){
      ans = max(ans,min(a[i][j],j-i));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 98176
#!/usr/bin/env python
# coding: utf-8

# In[27]:


n, m = list(map(int, input().split()))


# In[28]:


ans = 10 ** n
num = [-1] * n

for i in range(m):
    s, c = list(map(int, input().split()))
    if num[s - 1] == -1:
        num[s - 1] = c
    elif num[s - 1] != c:
        ans = -1
        break

if ans != -1:
    if n == 1:
        if num[0] == -1:
            ans = 0
        else:
            ans = num[0]
    else:
        if num[0] == 0:
            ans = -1
        else:
            if num[0] == -1:
                num[0] = 1
            for j in range(1, n):
                if num[j] == -1:
                    num[j] = 0
            ans = int(''.join(list(map(str, num))))
print(ans)


# In[ ]:






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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> ans(N, 0);
    for (int64_t _ = 0; _ < N - 1; _++) {
        int64_t A;
        cin >> A;
        ans[A - 1]++;
    }

    for (int64_t i = 0; i < N; i++) {
        cout << ans[i] << endl;
    }
}

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

int main() {
    int N; cin >> N;
    int A[100][3]; rep(i, N) rep(j, 3) cin >> A[i][j];
    rep(i, N) if (A[i][2] != 0) rep(j, 3) swap(A[0][j], A[i][j]);
    rep(cx, 101) rep(cy, 101) {
        bool ok = true;
        int H = A[0][2] + abs(cx - A[0][0]) + abs(cy - A[0][1]);
        if (H < 1) continue;
        rep(i, N)
            if (max(H - abs(cx - A[i][0]) - abs(cy - A[i][1]), 0) != A[i][2])
                ok = false;
        if (ok) cout << cx << " " << cy << " " << H << endl;
    }
    return 0;
}

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


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

struct edge {int to, cost; };

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

ll GCD(ll a, ll b){
  if(b==0) return a;
  else return GCD(b, a%b);
}

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}

int main(){
  int d, t, s;
  cin >> d >> t >> s;
  string ans;
  if(d>t*s) ans = "No";
  else ans = "Yes";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
def main():
  num, K, *line = map(int, open(0).read().split())
  dp = [float("inf")]* num
  dp[0] = 0
  for i in range(1, num):
    min_j = max(0, i - K)
    dp[i] = min([dp[j] + abs(line[i] - line[j]) for j in range(min_j , i)])
  #kの範囲: k = 1,2,3...K 無理なときは k = 1,2..i
  print(dp[-1])
main()


Measured memory_bytes: 13876
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static final int inf = 0x3f3f3f3f;
    public static void main(String[] args) {
        int N = sc.nextInt(), k = sc.nextInt();
        int[] a = new int[N + 1],f = new int[N + 1];
        for(int i = 1; i <= N; i ++) a[i] = sc.nextInt();
        Arrays.fill(f,inf);
        f[1] = 0;
        for(int i = 1; i <= N; i++){
            for(int j = 1; j <= k; j ++){
                if(i + j <= N){
                    f[i + j] = Math.min(Math.abs(a[i] - a[i + j]) + f[i],f[i + j]);
                }else break;
//                if(i > j){
//                    if(f[i] > 0)f[i] = Math.min(Math.abs(a[i] - a[i - j]) + f[i - j],f[i]);
//                    else f[i] = Math.abs(a[i] - a[i - j]) + f[i - j];
//                }else break;
            }
        }
//        for(int i = 1; i <= N; i++) System.out.print(f[i] + " ");
        System.out.println(f[N]);
    }
}

Measured memory_bytes: 50840
#include<vector>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<list>
#include<stack>

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
const ll MOD = 1000000007;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret *= x;
        }
        n >>= 1;
        x *= x;
    }
    return ret;
}

ll eval(ll val,ll idx,const vector<ll> &num){
    ll sb = val/3 + val/5 - val/15 - (mypow(10,idx-1)-1)/3 - (mypow(10,idx-1)-1)/5 + (mypow(10,idx-1)-1)/15;
    ll ad = val/3 + val/5 - (mypow(10,idx-1)-1)/3 - (mypow(10,idx-1)-1)/5;
    return num[idx-1] + (val - (mypow(10,idx-1)-1))*idx - sb*idx + ad*(ll)4;
}

string solve(ll s,const vector<ll> &num){
    ll idx;
    for(int i = 0; i < 18; i++){
        if(num[i] >= s){
            idx = i;
            break;
        }
    }
    ll ok = mypow(10,idx-1);
    ll ng = mypow(10,idx);
    ll used;
    while(abs(ok - ng) > 1){
        ll middle = (ok + ng)/2;
        used = eval(middle,idx,num);
        if(used <= s){
            ok = middle;
        }else{
            ng = middle;
        }
    }

    used = eval(ok-1,idx,num) + 1;
    string pre = "";
    for(ll j = ok; j < ok+20; j++){
        if(j%15 == 0){
            pre += "FizzBuzz";
        }else if(j%3 == 0){
            pre += "Fizz";
        }else if(j%5 == 0){
            pre += "Buzz";
        }else{
            pre += to_string(j);
        }
    }

    string ret = "";

    for(ll j = s - used; j < s - used + 20; j++){
        ret += pre[j];
    }

    return ret;
}

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

    vector<string> ans;

    vector<ll> vec(18,0);

    for(int i = 1; i <= 17; i++){
        ll size = mypow(10,i) - mypow(10,i-1);
        ll sb = (mypow(10,i)-1)/3 + (mypow(10,i)-1)/5 - (mypow(10,i)-1)/15 - (mypow(10,i-1)-1)/3 - (mypow(10,i-1)-1)/5 + (mypow(10,i-1)-1)/15;
        ll ad = (mypow(10,i)-1)/3 + (mypow(10,i)-1)/5 - (mypow(10,i-1)-1)/3 - (mypow(10,i-1)-1)/5;
        vec[i] = vec[i-1] + size*(ll)i - sb*(ll)i + ad*(ll)4;
    }

    ll s;
    cin >> s;

    cout << solve(s,vec) << endl;
    return 0;
}


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

int main(int argc, const char * argv[]) {
    // insert code here...
    
    int m, d;
    int d1, d10;
    int counter = 0;
    
    cin >> m >> d;
    
    
    
    for(int i=1; i<=m; ++i){
        for(int j=1; j<=d; ++j){
            d10 = j / 10;
            d1 = j % 10;
            if(d10 >= 2 && d1 >= 2 && d10 * d1 == i){
                ++counter;
            }
        }
    }
    
    cout << counter << endl;
    
    return 0;
}


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

using namespace std;

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

    double  res =0.0;
    for(int i=1;i<=n;i++){
        int tmp=i;
        double sum=1.0/n;
        while(tmp<k){
            tmp *=2;
            sum/=2;
        }
        res += sum;
    }
    printf("%.12lf\n",res);
}


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

struct node{
  node* ptr;
  int cnt;
  int label;
};

void init(node a[], int n){
  for(int i = 0; i < n; i++){
    a[i].ptr = NULL;
    a[i].cnt = 1;
    a[i].label = i;
  }
}

void merge(node* a, node* b){
  node* x = a;
  node* y = b;
  while(x->ptr != NULL){
    x = x->ptr;
  }
  while(y->ptr != NULL){
    y = y->ptr;
  }
  if(x == y) return;
  if(x->cnt > y->cnt){
    y->ptr = x;
    x->cnt += y->cnt;
  }else{
    x->ptr = y;
    y->cnt += x->cnt;
  }
}


int main(){
  int N,M;
  cin >> N >> M;
  node A[N];
  init(A, N);
  for(int i = 0; i < M; i++){
    int x,y,z;
    cin >> x >> y >> z;
    merge(&A[x-1], &A[y-1]);
  }
  int cnt = 0;
  for(int i = 0; i < N; i++){
    if(A[i].ptr == NULL){
      cnt++;
    }
  }
  cout << cnt << endl;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 2019

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    int cur = 0, d;
    cin >> s;
    int n = sz(s);
    ll res = 0;
    map<int, int> remCounter;
    remCounter[0] = 1;
    vector<int> powTen(n + 1);
    powTen[0] = 1;
    for (int i = 1; i <= n; i++) {
        powTen[i] = (powTen[i - 1] * 10) % MOD;
    }
    for (int i = 0; i < n; i++) {
        d = s[i] - '0';
        cur += (d * powTen[n - i - 1]);
        cur %= MOD;
        res += remCounter[cur];
        remCounter[cur]++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 4276
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
using namespace std;
struct unionfindtree {
    vector<int> par,rank;
    unionfindtree(int n):par(n),rank(n,0) {
        rep(i,n) par[i] = i;
    }
    int root(int n) {
        if(par[n] == n) return n;
        else return par[n] = root(par[n]);
    }
    bool same(int i,int j) {
        return root(i) == root(j);
    }
    void unite(int i,int j) {
        int ri = root(i);
        int rj = root(j);
        if(ri == rj) return;

        if(rank[ri] < rank[rj]) {
            par[ri] = rj;
        } else {
            par[rj] = ri;
            if(rank[ri] == rank[rj]) rank[ri]++;
        }
    }
};

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
        p[i]--;
    }
    unionfindtree u(n);
    rep(i,m) {
        int x,y;
        cin >> x >> y;
        x--; y--;
        u.unite(x,y);
    }
    int ans = 0;
    rep(i,n) {
        if(u.same(i,p[i])) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val As = List.fill(N)(in.nextLong)
  val Limit = BigInt(1e18.toLong)

  def product(ans: BigInt, as: List[Long]): BigInt = as match {
    case Nil => ans
    case x :: xs =>
      ans * x match {
        case a if a > Limit => BigInt(-1)
        case a => product(a, xs)
      }
  }

  println(if (As.contains(0L)) BigInt(0) else product(BigInt(1), As))
}

Measured memory_bytes: 63544
# cook your dish here
x,k,d=map(int,input().split())
l=0
r=k
while (l<r-1):
    m=l+(r-l)//2
    if(x-k*d+2*m*d>0): r=m
    else: l=m
ans1=x-k*d+2*l*d;
ans2=x-k*d+2*r*d;
print(min(abs(ans1),abs(ans2)))   

Measured memory_bytes: 9156
#!/mnt/c/Users/moiki/bash/env/bin/python
H,W      = list(map(int, input().split()))
S        =  [ list(input()) for _ in range(H)]

import sys
sys.setrecursionlimit(2600000)

united_count = [ ]
# [ (黒1個、白2個) ,... k 個] 

directions = [(1,0), (0,1), (-1,0), (0,-1)] # y,x の順番


def dfs(pos, c, now_k):
    # pos : (1,2)
    # 引数は現在の連結成分の番号
    # 座標と、現在の1,0 が渡される
    # 渡されたnow_kで塗りつぶす
    y,x = pos
    for d in directions:
        try:
            if y+d[0] < 0 or x+d[1] < 0:
                continue
            content = S[y+d[0]][x+d[1]] 

            if c != content and (content == "#" or content == ".") :
                S[y+d[0]][x+d[1]] = now_k
                inplace_tuple     = united_count[now_k]
                united_count[now_k]     = ( inplace_tuple[0] + 1, inplace_tuple[1]) if content == "#" else \
                                    ( inplace_tuple[0]    , inplace_tuple[1]+1) # タプルなので新しく作る

                dfs( (y+d[0], x+d[1]),  content,  now_k)  # DFSかける

            else:
                continue
        except:
            continue



now_k = 0
for y in range(H):
    for x in range(W):
        c = S[y][x]  
        if c == "#" or c == "." :
            united_count.append( (1,0) if  c == "#" else (0,1) ) # now_k番目
            S[y][x] = now_k  # cの値は黒だったら、1 を入れてdfsに投げる

            pos = (y,x)
            dfs(pos, c, now_k)
            now_k         += 1

        else:
            continue # もう数字が入っている場合は、パス


answer = 0
for uni in united_count:
    answer = ((uni[0]*uni[1]) + answer) 

print(answer)




Measured memory_bytes: 184820
n,q = map(int,input().split())
s = input()
x = []
y = []
for i in range(q):
    x1,y1=[int(i) for i in input().split()]
    x.append(x1)
    y.append(y1) 

t = [0]*n

for i in range(n-1):
    if s[i+1] == "C" and s[i] == "A":
        t[i+1] = t[i]+1
    else:
        t[i+1] = t[i]
for i in range(q):
    ans = t[y[i]-1] - t[x[i]-1]
    print(ans)

Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N=2e5+3;
string s[55],p[55];
bool go(int x,int y,int n,int m)
{
    for(int i=0,k=x;i<m;i++,k++)
    {
        for(int j=0,l=y;j<m;j++,l++)
        {
            if(p[i][j]!=s[k][l] || (j<m && l>=n))
            {
                return false;
            }
        }
        if(i<m && k>=n)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>s[i];
    }
    for(i=0;i<m;i++)
    {
        cin>>p[i];
    }
    int f=0;
    for(i=0;i<n && f==0;i++)
    {
        for(j=0;j<n;j++)
        {
            if(s[i][j]==p[0][0])
            {
                if(go(i,j,n,m)==true)
                {
                    f=1;
                    break;
                }
            }
        }
    }
    (f==1)? cout<<"Yes\n": cout<<"No\n";
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
m = [0]*n

for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in range(d):
        m[a[j]-1] += 1

ans = 0

for i in range(n):
    if m[i] == 0:
        ans += 1

print(ans)

Measured memory_bytes: 67764
N=int(input())
a=10e6
for i in range(1,N//2+1):
  A=i;B=N-i
  numA=sum([int(i) for i in list(str(A))])
  numB=sum([int(i) for i in list(str(B))])
  a=min(numA+numB,a)
print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

inline int add(int x,int y)
{
    return (x + y)%MOD;
}

inline int sub(int x,int y)
{
    return (x+MOD-y)%MOD;
}

inline int mul(int x,int y)
{
    return (ll)x*y%MOD;
}

int dp[101][8];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w,K;
    cin >> h >> w >> K;
    dp[0][0] = 1;
    rep(i,h){
        rep(l,w){
            rep(j,(1<<(w-1))){
                vi vec;
                rep(k,w-1){
                    if((j>>k)&1){
                        vec.pb(k);
                    }
                }
                bool flag = false;
                int prv = -2;
                set<int> st;
                rep(k,len(vec)){
                    if(vec[k] == prv+1){
                        flag = true;
                        break;
                    }else{
                        st.insert(vec[k]);
                        prv = vec[k];
                    }
                }
                if(flag) continue;
                if(st.count(l-1)){
                    dp[i+1][l-1] = add(dp[i+1][l-1],dp[i][l]);
                }else if(st.count(l)){
                    dp[i+1][l+1] = add(dp[i+1][l+1],dp[i][l]);
                }else{
                    dp[i+1][l] = add(dp[i+1][l],dp[i][l]);
                }
            }
        }
    }
    cout << dp[h][K-1] << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a;
    int b;
    int c;
    int tmp;
    scanf("%d %d %d\n",&a, &b, &c);

    if(a > b) {
      tmp = a;
      a = b;
      b = tmp;
    }

    if(b > c) {
      tmp = b;
      b = c;
      c = tmp;
      if(a > b) {
        tmp = a;
        a = b;
        b = tmp;
      }
    }
    printf("%d %d %d\n",a, b, c);
    return 0;
}


Measured memory_bytes: 2092
#include <stdio.h>

int main(){
    int N, Array[250];
    scanf("%d\n",&N);
    for (int ix = 0 ; ix < N ; ix++){
        if ( ix == N-1) scanf("%d\n",&Array[ix]);
        else scanf("%d ",&Array[ix]);
    }
    for (int ix = 0 ; ix < N ; ix++){
        printf("node %d: key = %d, ",ix+1,Array[ix]);
        if (ix != 0) printf("parent key = %d, ",Array[((ix+1)/2)-1]);
        if (2*(ix+1) <= N) printf("left key = %d, ",Array[2*(ix+1)-1]);
        if (2*(ix+1)+1 <= N) printf("right key = %d, ",Array[2*(ix+1)]);
        printf("\n");
    }
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int num, count = 0;
  int i, j;
  for (i = 1; i <= n; i++) {
    int temp = i;
    num = 0;
    for (j = 0; j < 5; j++) {
      num += temp % 10;
      temp /= 10;
    }
    if (a <= num && num <= b) {
      count += i;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

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


Measured memory_bytes: 3060
#include <stdio.h>

int main(void){
	long long n, p;
	long long i;
	
	scanf("%lld", &n);
	
	p = 1;
	
	for (i = 1; i <= n; i++){
		p = p*i%(int)(1e9+7);
	}
	
	printf("%lld\n", p);
	
	return 0;
}

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

int main()
{
	int n,k,count,i,ans,first_part,second_part,temp_ans;
	string s,new_string;
	vector<int> new_counts;

	cin >> n >> k;
	cin >> s;

	new_string = s[0];
	count = 1;
	for(i=1; i<n; i++)
	{
		if(s[i] == s[i-1])
			count++;
		else
		{
			new_counts.push_back(count);
			new_string += s[i];
			count = 1;
		}
	}
	new_counts.push_back(count);

	int cumarray[new_counts.size()];
	cumarray[0] = new_counts[0];
	for(i=1; i<new_counts.size(); i++)
		cumarray[i] = new_counts[i] + cumarray[i-1];

	if((new_string.size() == 1)&&(new_string[0]=='1'))
	{
		cout << new_counts[0] << endl;
		return 0;
	}
	ans = 0;
	for(i=0; i<new_string.size(); i++)
	{
		if(new_string[i] == '0')
		{
			if((i+2*(k-1)+1)<new_string.size())
				first_part = cumarray[i+2*(k-1)+1];
			else
				first_part = cumarray[new_string.size()-1];

			if(i<2)
				second_part = 0;
			else
				second_part = cumarray[i-2];

			temp_ans = first_part - second_part;
			ans = max(ans, temp_ans);
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define PI 2 * acos(0.0)
#define MAX 1000000
#define INF 1000000 
#define M 1000000007
using namespace std;
/*
bool isPowerOfTwo(ll x){
    return (x && !(x & (x - 1)));
}
// counts no. of 1 in binary representation
ll count_one (ll n){
    ll count = 0;
    while( n ){
        n = n&(n-1);
        count++;
    }
    return count;
}
// checks ith bit is set 
bool is_bit_set(ll n ,ll i){
    if( n & (1<<i) ){
        return true;
    }
    else{
        return false;
    }
}
// generating subset using bit technique ; n -> no. of elements
void subset(char a[], ll n){
   for(ll i = 0;i < (1<<n);i++){
         for(ll j = 0;j<n;j++){
             if(i & (1 << j)){
                 cout<<a[j]<<" ";
             }
         }
         cout<<endl;
   }
}
// Properties  of Modular:
//  1. (a+b)%c = (a%c + b%c)%c
//  2. (a*b)%c = (a%c * b%c)%c
//  3. (a-b)%c = (a%c - b%c)%c
//  4. (a/b)%c = ((a%c) * ( inverse(b)%c ))%c
 
ll binaryExponentiation(ll x,ll n)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}
ll modularExponentiation(ll x,ll n,ll m)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%m;
        x=(x*x)% m;
        n=n/2;
    }
    return result;
}
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else{
        return gcd(b,a%b);
    }
}
ll d, x, y;
void extendedEuclid(ll A, ll B) {
    if(B == 0) {
        d = A;
        x = 1;
        y = 0;
    }
    else {
        extendedEuclid(B, A%B);
        ll temp = x;
        x = y;
        y = temp - (A/B)*y;
    }
}
// when a and m are co prime
ll modInverse(ll A, ll m){
    extendedEuclid(A,m);
    return (x%m+m)%m;   
}
ll countDivisors(ll n) 
{ 
    int cnt = 0; 
    for (int i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
            else 
                cnt = cnt + 2; 
        } 
    }
    return cnt; 
} 
*/
int main(){
    FAST
    ll x,k,d;
    cin>>x>>k>>d;
    if(x == 0){
        if(k%2 == 0){
           cout<<0<<endl;
        }
        else{
           cout<<d<<endl;
        }
    }
    else{
        if(x < 0){
            x = abs(x);
        }
            ll y = x/d;
            ll i = y+1;
            ll ans = 0;
            if(y > k){
               y = k;
            }
            if(i > k){
                i = k;
            }
                ll u = k-y;
                ll r = k-i;
                ll ans1 = 0;
                if(u%2 == 0){
                   ans = x-(y*d);
                }
                else{
                  ans = (x-(y*d)) + d;
                }
                if(r%2 == 0){
                   ans1 = abs(x-(i*d));
                }
                else{
                   ans1 = abs((x-(i*d))+d);
                }
                ans = min(ans1,ans);
            cout<<ans<<endl;
    }
   return 0;
}

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

class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        long n = fs.nextLong();
        int mod ;
        StringBuilder sb = new StringBuilder();
        while(n > 0){
            mod = (int)((n-1)%26);
            sb.append(((char)('a'+mod)));
            n = (n-1)/26;
        }
        System.out.println(sb.reverse().toString());

    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 32460
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)

int main (){
    int n;
    while (cin >> n) {
        int x = 0;
        for (int i = 1; i <= 10000000; ++i) {
            x += i;
            if (x >= n) {
                cout << i << endl;
                break;
            }
        }
    }
}


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

#define LL long long 

map<LL ,int > mp;
LL n,a,ans;
LL sum;

int main() {
cin>>n;
mp[0]++;
for(int i=1;i<=n;i++) {
cin>>a;
sum+=a;
ans+=mp[sum];
mp[sum]++;
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 12800
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def solve(N):
    if N % 2 == 1:
        return 0
    s = 5
    ans = 0
    while N > s:
        ans += N // s // 2
        s = s * 5
    return ans


def main():
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == "__main__":
    main()

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

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

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

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

const int Vmax=30000;

signed main(){
	int n=read();
	vi ans;
	if(n==3){
		ans.PB(2);
		ans.PB(5);
		ans.PB(63);
	}else{
		ans.PB(2);
		ans.PB(3);
		ans.PB(4);
		ans.PB(9);
		n-=4;
		for(int i=6;i<Vmax;i+=6){
			if(n>=2){
				ans.PB(i+2);
				ans.PB(i+4);
				n-=2;
			}
		}
		for(int i=12;i<Vmax;i+=12){
			if(n>=2){
				ans.PB(i+3);
				ans.PB(i+9);
				n-=2;
			}
		}
		for(int i=6;i<=Vmax;i+=6){
			if(n>=1){
				ans.PB(i);
				n--;
			}
		}
	}
	n=ans.size();
	REP(i,n)print(ans[i],i==n-1?1:2);
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		long sum = 100;
		double rate = 1.01;
		long x;
		Scanner scan = new Scanner(System.in);

		x = scan.nextLong();

		int i = 0;
		while(sum < x) {
			i++;
			sum *= rate;
		}

		System.out.println(i);
	}
}


Measured memory_bytes: 27040
INF = int(1e18)

def compute():
    from sys import stdin
    A, B, Q = list(map(int, stdin.readline().split()))
    s = sorted(int(stdin.readline().split()[0]) for _ in range(A))
    t = sorted(int(stdin.readline().split()[0]) for _ in range(B))

    from bisect import bisect_left
    for _ in range(Q):
        x = int(stdin.readline().split()[0])

        i1 = bisect_left(s, x)
        i1 = i1 if i1 < A else i1-1
        i2 = i1-1 if (i1>0) and s[i1]!=x else i1

        res = INF
        for y in set((s[i1], s[i2])):
            j1 = bisect_left(t, y)
            j1 = j1 if (j1 < B) else j1-1
            j2 = j1-1 if (j1 > 0) and t[j1]!=y else j1
            for z in set((t[j1],t[j2])):
                # print(x, y, z)
                res = min(res, abs(x-y) + abs(y-z))
                res = min(res, abs(x-z) + abs(z-y))

        print(res)


if __name__ == "__main__":
    compute()


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

using namespace std;
int main()
{
    int curX = 0;
    int curY = 0;
    int curTime = 0;
    int n;
    cin >> n;
    vector<pair<int,pair<int,int> > > arr(n);
    for(int i = 0;i < n;i++)
        scanf("%d %d %d",&arr[i].first,&arr[i].second.first,&arr[i].second.second);
    sort(arr.begin(),arr.end());
    for(int i = 0;i < n;i++)
    {
        int dist = abs(curX - arr[i].second.first) + abs(curY - arr[i].second.second);
        int timeToReach = arr[i].first - curTime;
        if(dist > timeToReach || (timeToReach-dist) % 2 == 1)
        {
            cout << "No";
            return 0;
        }
        curX = arr[i].second.first;
        curY = arr[i].second.second;
        curTime = arr[i].first;
    }
    cout << "Yes";
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define N 100006
using namespace std;
long long k,s,ans,f[N];
int main()
{
	scanf("%lld%lld",&k,&s);
	for(int i=0;i<=k;i++)
	 for(int j=0;j<=k;j++)f[i+j]++;
	for(int i=0;i<=min(s,k);i++)ans+=f[s-i];
	printf("%lld\n",ans);
}

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

int main()
{
  string s;
  cin >> s;
  
  int n = s.size();
  int ans = 0;
  for(int i = 1; i < n; i++)
  {
    if(s[i] == s[i-1])
    {
      if(s[i-1] == '0') s[i] = '1';
      else              s[i] = '0';
      ans++;
    }
  }
  
  int com = 0;
  if(s[0] == '0') s[0] = '1';
  else            s[0] = '0';
  for(int i = 1; i < n; i++)
  {
    if(s[i] == s[i-1])
    {
      if(s[i-1] == '0') s[i] = '1';
      else              s[i] = '0';
      com++;
    }
  }
    
  cout << min(ans,com) << endl;
}


Measured memory_bytes: 3728
import sys
input = sys.stdin.readline
LOCAL = len(sys.argv) > 1 and sys.argv[1] == 'LOCAL'


def dprint(*args):
  if LOCAL:
    print(*args)


n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]


import math
import itertools


def distanse(x1, y1, x2, y2):
  return math.sqrt((x1 - x2)**2 + (y1 - y2)**2)


def isValid(ox, oy, r):
  # global ox, oy, r
  global xy
  for x, y in xy:
    if distanse(x, y, ox, oy) - r > 1e-6:
      return False
  return True


rs = []
for (x1, y1), (x2, y2) in itertools.combinations(xy, r=2):
  dprint(x1, y1, x2, y2)
  r = distanse(x1, y1, x2, y2) / 2
  ox = (x1 + x2) / 2
  oy = (y1 + y2) / 2
  dprint(ox, oy, r)
  if isValid(ox, oy, r):
    rs.append(r)
# for c1, c2 in itertools.combinations(xy, r=2):
#   dprint(c1, c2)
#   r = distanse(c1, c2)
#   o=(c1+c2)/2

for (x1, y1), (x2, y2), (x3, y3) in itertools.combinations(xy, r=3):
  # http://www.ambrsoft.com/TrigoCalc/Circle3D.htm
  a = x1 * (y2 - y3) - y1 * (x2 - x3) + x2 * y3 - x3 * y2
  b = (x1**2 + y1**2) * (y3 - y2) + (x2**2 + y2**2) * \
      (y1 - y3) + (x3**2 + y3**2) * (y2 - y1)
  c = (x1**2 + y1**2) * (x2 - x3) + (x2**2 + y2**2) * \
      (x3 - x1) + (x3**2 + y3**2) * (x1 - x2)
  d = (x1 ** 2 + y1 ** 2) * (x3 * y2 - x2 * y3) + (x2 ** 2 + y2 ** 2) * \
      (x1 * y3 - x3 * y1) + (x3 ** 2 + y3 ** 2) * (x2 * y1 - x1 * y2)
  if a == 0:
    continue
  ox = -b / (2 * a)
  oy = -c / (2 * a)
  r = math.sqrt((b ** 2 + c ** 2 - 4 * a * d) / (4 * a ** 2))
  if isValid(ox, oy, r):
    rs.append(r)

dprint(rs)
# print('{:.18f}'.format(min(rs)))
print(min(rs))


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

typedef long long ll;
typedef pair<int, int> ii;

const int N = 5e5 + 5;

int n, l[N], r[N], len[N];

template <class T>
struct shift_pq {
  T Q;
  ll total;
  shift_pq() : total(0) {}

  void shift(ll X) {
    total += X;
  }
  void push(ll X) {
    Q.push(X - total);
  }
  void pop() {
    Q.pop();
  }
  ll top() {
    return Q.top() + total;
  }
};

int main() {
#ifdef LOCAL
  freopen("in", "r", stdin);
#endif
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d %d", &l[i], &r[i]);
    len[i] = r[i] - l[i] + 1;
  }

  shift_pq<priority_queue<ll>> L;
  shift_pq<priority_queue<ll, vector<ll>, greater<ll>>> R;

  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    L.shift(-(len[i - 1] - 1));
    R.shift(len[i] - 1);

    L.push(r[i]);
    R.push(r[i]);

    if (r[i] < L.top()) {
      ans += L.top() - r[i];
      L.push(r[i]);
      R.push(L.top());
      L.pop();
      R.pop();
    } else if (r[i] > R.top()) {
      ans += r[i] - R.top();
      R.push(r[i]);
      L.push(R.top());
      L.pop();
      R.pop();
    }
  }

  printf("%lld\n", ans);
}


Measured memory_bytes: 6272
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int,int> PP;

/*
    freopen("input","r",stdin);
    freopen("output","w",stdout);
*/

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll N, K;
    cin >> N >> K;
    ll sol = 0;
    for (ll i = K + 1;i <= N;i++) {
    	ll r = N / i;
    	ll q = N % i;
    	if (q == 0) {
    		sol += r * (i - K);
    	}
    	else {
    		r--;
	    	sol += (i - K) * (r + 1);
	    	if (K == 0) q--;
	    	sol += max(0LL, q - K + 1);
	    }
    }
    cout << sol << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

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

	int n;
	cin >> n;
	ll* a = new ll[n];
	rep(i, n) cin >> a[i];

	ll* sum = new ll[n + 1];
	sum[0] = 0;
	REP(i, 1, n + 1) sum[i] = a[i - 1] + sum[i - 1];

	ll ans = 0;
	map<ll, ll> m;
	rep(i, n + 1) {
		auto p = m.find(sum[i]);
		if (p == m.end()) {
			m[sum[i]] += 1;
		}
		else {
			ans += m[sum[i]];
			m[sum[i]] += 1;
		}
	}

	cout << ans << "\n";

	return 0;
}



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

int main(void){
    char s[101], t [101];

    scanf("%s%s", s, t);
    for(int i = 0; i < strlen(s) - 1; i++){
        for(int j = i + 1; j < strlen(s); j++){
            if(s[i] > s[j]){
                char tmp;
                tmp = s[i];
                s[i] = s[j];
                s[j] = tmp;
            }
        }
    }

    for(int i = 0; i < strlen(t) - 1; i++){
        for(int j = i + 1; j < strlen(t); j++){
            if(t[i] < t[j]){
                char tmp;
                tmp = t[i];
                t[i] = t[j];
                t[j] = tmp;
            }
        }
    }

    if(strcmp(s, t) < 0){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;

} 


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**7)
mod=10**9+7
n=int(input())
edges=[[] for _ in range(n)]
for _ in range(n-1):
    x,y=map(int,input().split())
    edges[x-1].append(y-1)
    edges[y-1].append(x-1)
C=[[] for _ in range(n)]

def fill_C(v,par):
    for c in edges[v]:
        if c==par:
            continue
        C[v].append(c)
        fill_C(c,v)
fill_C(0,-1)

DP=[[-1,-1] for _ in range(n)]

def white(v):
    if DP[v][0]!=-1:
        return DP[v][0]
    res=1
    for c in C[v]:
        res*=white(c)+black(c)
        res%=mod
    DP[v][0]=res
    return res
def black(v):
    if DP[v][1]!=-1:
        return DP[v][1]
    res=1
    for c in C[v]:
        res*=white(c)
        res%=mod
    DP[v][1]=res
    return res

print((black(0)+white(0))%mod)

Measured memory_bytes: 121964
implicit none

integer(8) :: n
integer(8), allocatable :: a(:)
integer(8) :: i
integer(8) :: s, s1, s2, ss

read *, n
allocate(a(0:n+1))
a(0) = 0
a(n+1) = 0
read *, (a(i), i=1,n)

s = 0
do i = 1, n+1
  s = s + abs(a(i)-a(i-1))
enddo

s1 = abs(a(1) - a(0))
do i = 1, n
   s2 = abs(a(i+1) - a(i))
   ss = abs(a(i+1) - a(i-1))
   write(6,'(i0)') s - s1 - s2 + ss
   s1 = s2
enddo
stop
end

Measured memory_bytes: 2944
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cstdio>
using namespace std;
typedef long long ll;
const int N = 2e5+5;
const ll INF = 2e18;

int a[N];

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i = 1;i <= n;++i) scanf("%d",&a[i]);
	sort(a+1,a+n+1,greater<int>());
	
	ll ans = 0;
	for(int i = k+1;i <= n;++i) ans += a[i];
	cout << ans;
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
x = list(map(int, input().split()))
souwa = 0
kazu = len(x)
souwalist=[]
saidai = max(x)

for j in range(saidai):
	j += 1
	for i in range(kazu):
		tem = x[i]
		souwa = (tem - j) ** 2 + souwa
	souwalist.append(souwa)
	souwa = 0

print(min(souwalist))


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

int dx4[] = {1, -1, 0, 0};
int dy4[] = {0, 0, 1, -1};
int dx8[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy8[] = {1, -1, 0, 0, 1, -1, -1, 1};

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main() {
    int N, M;
    cin >> N >> M;
    vector<vector<bool>> d(N+1, vector<bool>(N+1));
    rep(i, M) {
        int n, m;
        cin >> n >> m;
        d[n][m] = d[m][n] = true;
    }
    int a[N];
    rep(i, N) a[i] = i+1;
    ll ans = 0;
    do {
        bool f = true;
        rep(i, N-1) {
            f = f && d[a[i]][a[i+1]];
        }
        if(f) ++ans;
    } while (next_permutation(a + 1, a + N));

    cout << ans << nl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem( f, x ) memset( f, x, sizeof(f) )
#define pii pair<int,int>
#define fi first
#define se second
#define mk(x,y) make_pair(x,y)
#define pk push_back
typedef long long ll;
using namespace std;
const int M = 215;
const int N = 55;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 2505;
ll m, n, s;
int head[N], cnt;
ll dis[N][MAXN];
ll c[N], d[N];

struct eg{
    int to, pre;
    ll a, b;
    eg( ):to(0),pre(0),a(0),b(0){}
    eg( int tt, int pp, ll aa, ll bb ):to(tt),pre(pp),a(aa),b(bb){}
}e[M];

struct node{
    int x;
    ll mon, dis;
    node():x(0),mon(0),dis(0){ }
    node( int xx, ll mm, ll dd ):x(xx),mon(mm),dis(dd){ }
    friend bool operator<( node p1, node p2 ){
        if( p1.dis == p2.dis )
            return p1.mon < p2.mon;
        return p1.dis > p2.dis;
    }
};

void add( int x, int y, ll a, ll b ){
    e[++cnt] = eg( y, head[x], a, b );
    head[x] = cnt;
}

void BFS( ){
    priority_queue<node> pq;
    while( !pq.empty() ) pq.pop();
    node cur, nxt;
    cur = node( 1, s, 0 );
    dis[1][s] = 0;
    pq.push( cur );
    while( !pq.empty() ){
        cur = pq.top();
        pq.pop();
        int x = cur.x;
        int w = cur.mon;
        for( int i = head[x]; i; i = e[i].pre ){
            int to = e[i].to;
            if( cur.mon < e[i].a ) continue;
            nxt = node( to, cur.mon-e[i].a, dis[x][cur.mon]+e[i].b );
            if( dis[to][nxt.mon] > nxt.dis ){
                dis[to][nxt.mon] = nxt.dis;
                pq.push( nxt );
            }
        }
        ll mi = min( cur.mon+c[x], ll(2500) );
        if( dis[x][mi] > dis[x][cur.mon]+d[x] ){
            dis[x][mi] = dis[x][cur.mon]+d[x];
            pq.push( node( x, mi, dis[x][mi] ) );
        }
    }
}

void init( ){
    for( int i = 0; i <= n; i++ ){
        head[i] = 0;
        for( int j = 0; j < MAXN; j++ )
            dis[i][j] = INF;
    }
    cnt = 0;
    s = min( s, ll(2500) );
}

int main( ){
    while( scanf( "%d %d %d", &n, &m, &s ) != EOF ){
        init( );
        ll x, y, a, b;
        for( int i = 0; i < m; i++ ){
            scanf( "%lld %lld %lld %lld", &x, &y, &a, &b );
            add( x, y, a, b );
            add( y, x, a, b );
        }
        for( int i = 1; i <= n; i++ )
            scanf( "%lld %lld", c+i, d+i );
        BFS( );
        for( int i = 2; i <= n; i++ ){
            ll ans = INF;
            for( int j = 0; j < MAXN; j++ )
                ans = min( ans, dis[i][j] );
            printf( "%lld\n", ans );
        }
    }
    return 0;
}


Measured memory_bytes: 7280
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n;
	cin >> n;
	int c[n-1], s[n-1], f[n-1];
	for (int i = 0; i < n-1; i++)
		cin >> c[i] >> s[i] >> f[i];
	for (int i = 0; i < n-1; i++) {
		int t = 0;
		for (int j = i; j < n-1; j++) {
			if (t < s[j])
				t = s[j] + c[j];
			else {
				int tmp = t - s[j];
				int tmp1 = (tmp+f[j]-1)/f[j];
				t = s[j] + tmp1*f[j] + c[j];
			}
		}
		cout << t << endl;
	}
	cout << 0 << endl;
	return 0;
}


Measured memory_bytes: 3648
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  char buff[5555];
  int K;
  scanf("%s %d", buff, &K);
  string s = buff;

  vector<string> v;
  REP(i, (int)s.size()) REP(j, K) {
    if (i + j < (int)s.size()) {
      v.push_back(s.substr(i, j+1));
    }
  }

  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  puts(v[K-1].c_str());

  return 0;
}


Measured memory_bytes: 1660
#include <stdio.h>

int main(void){

  int x,y,z;

  printf("");
  scanf("%d %d %d",&x,&y,&z);

  if (x<y&&y<z){

    printf("Yes\n");
      
      } else {

    printf("No\n");

      }

  return 0;
}


    

Measured memory_bytes: 580