akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys


def solve(N: int, T: int, t: "List[int]"):
    answer =0 
    for i in range(N-1):
        answer += min(t[i+1]-t[i],T)
    
    answer += T
    print(answer)


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    t = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, T, t)

if __name__ == '__main__':
    main()


Measured memory_bytes: 27196
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
//cout << std::fixed << std::setprecision(15) << y << endl;


int main(){
    string S, T;
    cin >> S >> T;

    ll minChange = 1000;
    ll count;
    rep(i, S.length() - T.length() + 1){
        count = 0;
        rep(j, T.length()){
            if(S[i + j] != T[j]){
                count++;
            }
        }
        minChange = min(minChange, count);
    }

    cout << minChange << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <vector>

#include <cstdint>

constexpr bool parity32(std::uint_fast32_t c) noexcept {
  c ^= c >> 1;
  c ^= c >> 2;
  return ((c & 0x11111111) * 0x11111111 >> 28 & 0x1) != 0;
}

int scan() {
  int r = 0;
  int c;
  while ((c = getchar_unlocked() - '0') >= 0)
    r = r * 10 + c;
  return r;
}

int main() {
  const int n = scan();
  std::vector<std::vector<int>> t(n);
  for (int i = 0; i != n - 1; i += 1) {
    const int a = scan() - 1;
    const int b = scan() - 1;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  const int m = scan();
  const int s = 1 << m;
  std::vector<int> z(s, 0);
  {
    std::vector<int> x(n, 0);
    for (int i = 0; i != m; i += 1) {
      const int u = scan() - 1;
      const int v = scan() - 1;
      x[u] ^= 1 << i;
      x[v] ^= 1 << i;
    }
    const auto dfs = [&](const auto &dfs, int v, int p) -> void {
      for (int e : t[v]) {
        if (e != p) {
          dfs(dfs, e, v);
          z[x[e]] += 1;
          x[v] ^= x[e];
        }
      }
    };
    dfs(dfs, 0, n);
  }
  for (int w = 1; w != s; w <<= 1) {
    for (int i = 0; i != s; i += w << 1) {
      const int end = i + w;
      for (int j = i; j != end; j += 1) {
        z[j + w] += z[j];
      }
    }
  }

  long long ans = 0;
  for (int i = 0; i != 1 << m; i += 1) {
    auto res = 1LL << z[s - 1 ^ i];
    if (parity32(i))
      res = -res;
    ans += res;
  }
  printf("%lld", ans);
}

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

int main(){
   int w,h,n;
   cin >> w >> h >> n;
   int xa=0,xb=w;
   int ya=0,yb=h;
   vector<vector<int>> u(n,vector<int>(3));
   for (int i=0;i<n;i++){
      for (int j=0;j<3;j++){
         cin >> u.at(i).at(j);
         if (j==2){
            if (u.at(i).at(2)==1){
               if (xa<u.at(i).at(0))xa=u.at(i).at(0);
            }
            if (u.at(i).at(2)==2){
               if (xb>u.at(i).at(0))xb=u.at(i).at(0);
            }
            if (u.at(i).at(2)==3){
               if (ya<u.at(i).at(1))ya=u.at(i).at(1);
            }
            if (u.at(i).at(2)==4){
               if (yb>u.at(i).at(1))yb=u.at(i).at(1);
            }
         }
      }
   }
   if (xa>xb||ya>yb)cout << 0 << endl;
   else cout << (xb-xa)*(yb-ya) << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader input =new BufferedReader (new InputStreamReader (System.in));
		String str = input.readLine( );
		String[] nl = str.split(" ");
		int n = Integer.parseInt(nl[0]);
		String[] list = new String[n];

		for(int i=0; i<n; i++){
			list[i] = input.readLine( );
		}
		Arrays.sort(list);
		String answer = "";
		for(int i=0; i<n; i++){
			answer = answer + list[i];
		}
		System.out.println(answer);
	}

}


Measured memory_bytes: 25300
from collections import deque

mod = 10 ** 9 + 7

N, K, *AB = map(int, open(0).read().split())

E = [set() for _ in range(N + 1)]
for a, b in zip(*[iter(AB)] * 2):
    E[a].add(b)
    E[b].add(a)

ans = K

Q = deque([1])
while Q:
    v = Q.popleft()
    for i, u in enumerate(E[v], 1):
        ans *= (K - i - (v > 1))
        ans %= mod
        E[u].remove(v)
        Q.append(u)

print(ans)

Measured memory_bytes: 43220
import sys
from math import sqrt


def calc_height(f):
    """ f???????????°????????§????????¢(m) """
    return 5.0 * f - 5.0


if __name__ == '__main__':
    # ??????????????\?????¨???????????????
    for line in sys.stdin:
        req_v = float(line)  # ??¬???????????????????????????????????????

        # ???????????????
        floor = 1  # ??¬??????????????????????????????????????°
        # found = False  # ??????????????°??????????????£???????????????
        while True:
            y = calc_height(floor)
            t = sqrt(y / 4.9)
            v = 9.8 * t  # floor????????????????????????????????§??????????¨????
            if v >= req_v:
                break
            floor += 1  # ???????????????????????????????????£????????§???1????????¢?????????????????????

        # ???????????¨???
        print(floor)

Measured memory_bytes: 7496
#include<iostream>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N, D; std::cin >> N >> D;
  int k = D*2+1;
  fin((N+k-1)/k);
  return 0;
}


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

typedef long long int ll;
typedef vector<int> vi;			typedef vector<ll> vl;
typedef vector<vi> vvi; 		typedef vector<vl> vvl;
typedef pair<int, int> 	pii;	typedef pair<ll, ll> pll;
typedef vector<pii> vii; 		typedef vector<pll> vll;
typedef map<int,int> mii;
typedef vector<char> vc;
typedef vector<bool> vb;
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define rforne(i,n) for(int i=n;i>=1;i--)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define in insert
#define mp(a, b) make_pair(a, b)
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define min3(a, b, c) min(min(a, b), c)
#define min4(a, b, c, d) min(min(a, b), min(c, d))
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max(max(a, b), max(c, d))
#define INF LLONG_MAX
#ifdef KARAN
	#include "../../trace.h"
#else
    #define trace(args...)
#endif

ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; 
	while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
void graph(vvi &adj, int m) {int x, y; forn(i, m){cin>>x>>y; adj[--x].pb(--y); adj[y].pb(x);}}

void dfs(ll v, ll p, ll l, vvl &adj, vl &a, vl &dp, vl &ans){

	ll lo = lower_bound(dp.begin(), dp.end() + l, a[v]) - dp.begin();
	
	ll prev_val = dp[lo];
	dp[lo] = a[v];
	ans[v] = lower_bound(dp.begin(), dp.end() + l, INF) - dp.begin();
	
	for(auto u: adj[v]){
		if(u!=p)
			dfs(u, v, max(lo, l), adj, a, dp, ans);
	}
	dp[lo] = prev_val;
}

void solve(){
	ll n;
	cin>>n;
	vl a(n);
	forn(i, n) cin>>a[i];
	vvl adj(n);
	forn(i, n-1){ ll u, v; cin>>u>>v; u--; v--; adj[u].pb(v); adj[v].pb(u); }
	vl ans(n);
	vl dp(n);
	forn(i, n) dp[i] = INF;
	dfs(0, 0, 0, adj, a, dp, ans);
	for(auto elem: ans)
		cout<<elem<<endl;	
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifdef KARAN
		freopen("inp.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    	freopen("err.txt", "w", stderr);
	#endif
	int t=1;
	// cin>>t;
	while(t--)
		solve();
}


Measured memory_bytes: 41548
// ALDS1_1_A:   Insertion Sort
// 2018.3.14

#include <stdio.h>

int
main (void)
{
  int N;
  int A[100] = {};
  int i, j, v, k;

  scanf ("%d\n", &N);
  scanf ("%d", &A[0]);

  for(i = 1; i < N; i++)
    {
        scanf (" %d", &A[i]);
    }
  // 1st line
  
  printf ("%d", A[0]);
  
  for (k = 1; k < N; k++)
    {
      printf (" %d", A[k]);
    }
  printf ("\n");
      
  //insertionSort(A, N) // N個の要素を含む0-オリジンの配列A

  for(i = 1; i < N; i++)
    {
      v = A[i];
      j = i - 1;
      while (j >= 0 && A[j] > v)
	{
	  A[j+1] = A[j];
	  j--;
	}
      A[j+1] = v;

  // lest lines
      
      printf ("%d", A[0]);
      
      for (k = 1; k < N; k++)
	{
	  printf (" %d", A[k]);
	}
      printf ("\n");
    }
  return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>

int main(){
  int x,y,a,r;

  scanf("%d%d",&x,&y);
  if(x<y){
    a = x;
    x = y;
    y = a;
}

  r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }

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

  return 0;
}



Measured memory_bytes: 2128
n=int(input())
a=list(map(int,input().split()))

add=[]
sub=[]
for i in range(n):
    add.append(i+a[i])
    sub.append(i-a[i])

add_dic={}
sub_dic={}

for l in add:
    if l in add_dic:
        add_dic[l]+=1
    else:
        add_dic[l]=1

for l in sub:
    if l in sub_dic:
        sub_dic[l]+=1
    else:
        sub_dic[l]=1

ans=0

for i,k in add_dic.items():
    if i in sub_dic:
        ans+=k*sub_dic[i]

print(ans)

Measured memory_bytes: 166180
#include<bits/stdc++.h>
//pbds
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>   using orderedSet =tree<T, null_type, less<T>,rb_tree_tag, tree_order_statistics_node_update>;
///use less_equal in pbds template to work as multiset...................................................
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
//BFS+DFS
#define boundary(i,j) (i>=0 && i<n && j>=0 && j<m)
int X[]={-1,1,0,0};
int Y[]={0,0,1,-1};
ll mod=1e9+7;
ll dp[2006];
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     dp[0]=1LL;
     int s;
     cin>>s;
     for(int i=3; i<=s; i++)
     {
         for(int j=i; j>=3; j--)
            dp[i]=(dp[i]+dp[i-j])%mod;
     }
     cout<<dp[s]<<endl;
}




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

#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define reset(a, v) memset ((a), v, sizeof (a))

using namespace std;

typedef long long ll;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ii> vii;

string dat;
vi V;

bool check () {
	int cur1 = sz(V) / 2 - 1;
	int cur2 = (sz(V) & 1 ? cur1 + 2 : cur1 + 1);

	while (cur1 != -1) {
		if (dat[V[cur1]] != dat[V[cur2]]) return 0;
		--cur1;
		++cur2;
	}
	return 1;
}

int get_ans () {
	int ret = 0;
	int cur1 = sz(V) / 2 - 1;
	int cur2 = (sz(V) & 1 ? cur1 + 2 : cur1 + 1);
	while (cur1 != -1) {
		int len1 = V[cur1 + 1] - V[cur1];
		int len2 = V[cur2] - V[cur2 - 1];
		ret += abs (len1 - len2);
		--cur1;
		++cur2;
	}
	ret += abs (V[cur1 + 1] - ((int)dat.length() - 1 - V[cur2 - 1]));
	return ret;
}

int main () {
	cin >> dat;
	for (int i = 0; i < (int)dat.length(); ++i) {
		if (dat[i] != 'x') {
			V.push_back (i);
		}
	}

	if (V.empty()) {
		printf ("0\n");
		return 0;
	}
	
	if (!check ()) {
		printf ("-1\n");
		return 0;
	}

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

Measured memory_bytes: 1020
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.max
import kotlin.time.seconds

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (d, n) = readIntegerList()
    var i = 0
    var count = 0
    while (count != n) {
        i++
        var tmp = 0
        var j = i
        while (tmp != 3 && j % 100 == 0) {
            j /= 100
            tmp++
        }

        if (tmp == d) count++

    }
    out.println(i)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 36444
import math
while True:
    n = int(input())
    if n==0:
        break
    s = [int(x) for x in input().split()]
    mean = sum(s)/len(s)
    tmp = []
    for xi in s:
        tmp.append((xi-mean)**2)
    print(math.sqrt(sum(tmp)/len(tmp)))


Measured memory_bytes: 5716
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;

int main(){
  int n; cin>>n;
  double ans;
  if(n%2==0)ans=0.5000000000;
  else {
    ans=n+1;
    ans/=n;
    ans*=0.5;
  }
std::cout << std::fixed;
std::cout << std::setprecision(6) <<ans<<endl;;
 
}

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

int main(void){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if(x >= r && x+r <= w && y >= r && y + r <= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
int N, X;
long long BG[60][2];
long long dp(int n, long long x) {
    if(BG[n][0] <= x) {
        return BG[n][1];
    }
    if(x == 1) {
        return 0;
    } else if(x <= 1 + BG[n - 1][0]) {
        return dp(n - 1, x - 1);
    } else if(x == 2 + BG[n - 1][0]) {
        return BG[n - 1][1] + 1;
    } else if(x <= 2 + BG[n - 1][0] * 2) {
        return BG[n - 1][1] + 1 + dp(n - 1, x - 2 - BG[n - 1][0]);
    } else {
        return BG[n][1];
    }
}
int main() {
    int N;
    long long X;
    cin >> N >> X;

    BG[0][0] = 1;
    BG[0][1] = 1;
    rep(i, 1, N + 1) {
        BG[i][0] = BG[i - 1][0] * 2 + 3;
        BG[i][1] = BG[i - 1][1] * 2 + 1;
    }
    // cout << BG[N][0] << endl;
    // cout << BG[N][1] << endl;

    cout << dp(N, X) << endl;
}


Measured memory_bytes: 384
from itertools import product, accumulate

N, W = map(int, input().split())
v0, v1, v2, v3 = [None], [], [], []
w0, v0[0] = map(int, input().split())
for i in range(1, N):
    w, v = map(int, input().split())
    if w - w0 == 0:
        v0.append(v)
    elif w - w0 == 1:
        v1.append(v)
    elif w - w0 == 2:
        v2.append(v)
    else:
        v3.append(v)

v0 = sorted(v0, reverse=True)
v1 = sorted(v1, reverse=True)
v2 = sorted(v2, reverse=True)
v3 = sorted(v3, reverse=True)

av0 = [0] + list(accumulate(v0))
av1 = [0] + list(accumulate(v1))
av2 = [0] + list(accumulate(v2))
av3 = [0] + list(accumulate(v3))

ans = 0
for i, j, k, l in product(range(len(v0) + 1), range(len(v1) + 1),
                          range(len(v2) + 1), range(len(v3) + 1)):
    v = av0[i] + av1[j] + av2[k] + av3[l]
    w = w0 * i + (w0 + 1) * j + (w0 + 2) * k + (w0 + 3) * l
    if w <= W:
        ans = max(v, ans)
print(ans)


Measured memory_bytes: 3064
n,k = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in range(len(p)):
    p[i] = (1+p[i])*p[i]/p[i]/2
#print(p)
l = [0]
for i in range(len(p)):
    l.append(l[i]+p[i])
#print(l)
s = []
for i in range(len(p)-k+1):
    s.append(l[i+k]-l[i])
#print(s)
print(max(s))


Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
//constexpr int mod=1000000007;
int mod;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,p,a[200010],r[200010],ans,d=10;
string s;
map<int,int>mp;
signed main(){
    cin>>n>>p>>s;
    mod=p;
    rep(i,n)a[i]=s[i]-'0';
    if(p==2||p==5){
        rep(i,n){
            if(a[i]%p==0){
                ans+=i+1;
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    for(int i=n-1;i>=0;i--){
        r[i]=r[i+1]+a[i]*d;
        r[i]%=mod;
        d=(d*10)%mod;
    }
    r[n]=0;
    int ans=0;
    rep(i,n){
        mp[r[i]]++;
        ans+=mp[r[i+1]];
    }
    cout<<ans<<endl;
    return 0;
}

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

int main() {
  int r,D,x_2000; cin >> r >> D >> x_2000;
  vector<int> x(10);
  rep(i,10) {
    if(i==0) x[i] = r*x_2000-D;
    else x[i] = r*x[i-1]-D;
  }
  rep(i,10) cout << x[i] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k-a-b>0)cout<<a-(k-a-b)<<endl;
	  else if(k<a)cout<<k<<endl;
	  else cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 3164
import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;

    public class Main {

        public static void main(String[] args) throws IOException {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String [] line = br.readLine().split( " ");
            int n = Integer.parseInt(line[0]);
            int m = Integer.parseInt(line[1]);
            int sum = 0;
            String [] nums = br.readLine().split(" ");

            for(int i = 0 ; i< m; i++){
                sum += Integer.parseInt(nums[i]);
            }

            if(n-sum < 0){
                System.out.println("-1");
            }
            else {
                System.out.println(n-sum);
            }

        }
    }

Measured memory_bytes: 34224
r,c=map(int,input().split())
grid=[input() for _ in [0]*r]
ans=sum([grid[i].count(".") for i in range(r)])
visit=[[grid[i][j]=="#" for j in range(c)] for i in range(r)]
d=[(1,0),(-1,0),(0,1),(0,-1)]
cnt=0
q=[[0,0]]
flag=False
while q:
    qq=[]
    while q:
        i,j=q.pop()
        for dx,dy in d:
            if 0<=i+dx<r and 0<=j+dy<c:
                if i+dx==r-1 and j+dy==c-1:
                    flag=True
                if visit[i+dx][j+dy]==False:
                    visit[i+dx][j+dy]=True
                    qq.append([i+dx,j+dy])
    q=qq
    cnt+=1
    if flag==True:
        break
if flag==False:
    print(-1)
else:
    print(ans-cnt-1)

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

#define SWAP(type,a,b) { type work = a; a = b; b = work; }

/*
    基準値を選ぶ
*/
int select_pivot(const int* array, int begin, int end)
{
    return array[(begin + end) / 2];  // 中央の要素を基準値とする
}


/*
    クイックソート (再帰部分、昇順)
*/
void quick_sort_rec(int* array, int begin, int end)
{
    int pivot = select_pivot( array, begin, end );
    int i = begin;
    int j = end;

    while( 1 ){
        while( array[i] < pivot ){ ++i; }  // 基準値以上の値が見つかるまで右方向へ進めていく
        while( array[j] > pivot ){ --j; }  // 基準値以下の値が見つかるまで左方向へ進めていく

        if( i >= j ){ break; }  // 左右から進めてきたiとjがぶつかったらループを終える

        // 基準値の位置よりも左側にあり、基準値よりも大きい値 (array[i]) と、
        // 基準値の位置よりも右側にあり、基準値よりも小さい値 (array[j]) の
        // 位置関係を交換する。
        SWAP( int, array[i], array[j] );

        // 次回に備えて、注目点をずらす
        i++;
        j--;
    }


    // 基準値の位置より左側に要素が２つ以上あれば、
    // その部分についてクイックソートを再帰させる
    if( i - begin >= 2 ){
        quick_sort_rec( array, begin, i - 1 );
    }

    // 基準値の位置より右側に要素が２つ以上あれば、
    // その部分についてクイックソートを再帰させる
    if( end - j >= 2 ){
        quick_sort_rec( array, j + 1, end );
    }
}


void sort(int* array, int size){
    // 配列全体を対象にする
    quick_sort_rec( array, 0, (int)(size - 1) );
}

void print_array(int data[], int n){
    for(int i = 0; i < n; i++){
        printf("%d ", data[i]);
    }
    printf("\n");
}

int main(void){
    int n, x1, x2;
    scanf("%d", &n);
    int data1[n], data2[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &data1[i]);
        data2[i] = data1[i];
    }
    sort(data2, n);
    x1 = data2[n / 2];
    x2 = data2[n / 2 - 1];
    for(int i = 0; i < n; i++){
        if(data1[i] < x1){
            printf("%d\n", x1);
        }else{
            printf("%d\n", x2);
        }
    }
    return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>

#define rr register
#define INF 1e18
#define LINF -1e18

using namespace std;

const int MAXN = 1e5 + 1;

inline int read() {
	int s = 0, m = 0;
	char ch = getchar();
	while (!isdigit(ch)) {m |= ch == '-', ch = getchar();}
	while (isdigit(ch)) {s = s * 10 + (ch ^ 48), ch = getchar();}
	return m ? -s : s;
}

int n, d, l, r,minn = 0x7fffffff;
double a[50][50];

signed main(int argc, char const *argv[]) {
	l = read();
	r = read();
	for (rr int i = l; i < r; i++) {
		for(rr int j = i + 1; j <= r; j++) {
			int a = ((i % 2019) * (j % 2019)) % 2019;
			minn = minn < a ? minn :a;
			if (minn == 0){
				cout<<minn;
				return 0;
			}
		}
	}
	cout<<minn;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using intl = int64_t;
using graph = vector<vector<int> >;
int main(){
    int n;
    cin >> n;
    int x[n];
    for(int i=0;i<n;i++) cin >> x[i];

    int sum = 1000000;
    for(int i=1;i<=100;i++){
        int subsum=0;
        for(int j=0;j<n;j++){
            subsum += (i-x[j])*(i-x[j]);
        }

        sum = min(sum,subsum);
    }

    cout << sum << endl;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(long long i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const double EPS = 1e-9;
const ll powll = 1LL<<1;

/*
while(!frag && cin >> a >>b, a|b)
*/

int main(void){
    int n; 
    cin >> n;
    map<string, int> mp;
    string s;
    rep(i,0,n){
        cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << "\n";
    cout << "WA x " << mp["WA"] << "\n";
    cout << "TLE x " << mp["TLE"] << "\n";
    cout << "RE x " << mp["RE"] << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
typedef vector<double> vec3;

int main() {

  string s;
  ll k;
  cin >> s >> k;
  for(int i = 0; i < k; i++) {
    if(s.at(i) != '1') {
      cout << s.at(i) << endl;
      return 0;
    }
  }
  cout << '1' << endl;
}

Measured memory_bytes: 256
import math
def prime(n):
    set1 = set()
    while n % 2 == 0: 
        set1.add(2) 
        n = n / 2
    for i in range(3,int(math.sqrt(n))+1,2): 
        while n % i== 0: 
            set1.add(i)
            n = n / i 
    if n > 2: 
        set1.add(n)
    return set1

a,b = map(int, input().split())
ans1 = prime(a)
ans2 = prime(b)
ans3 = ans1.intersection(ans2)
print(len(ans3)+1)


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i,n) for(unsigned int i=0;i<(n);i++)
#define INF 1<<16
int main()
{
	while (true)
	{
		int A[10][10];
		REP(i, 10)REP(j, 10)
		{
			if (i == j)A[i][j] = 0;
			else A[i][j] = INF;
		}
		int N,M=-1;
		cin >> N;
		if (N == 0)break;
		REP(i, N)
		{
			int a, b, c;
			cin >> a >> b >> c;
			M = max(M, min(a, b));
			A[a][b] = c;
			A[b][a] = c;
		}
		REP(k, 10)REP(i, 10)REP(j, 10)
		{
			A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
		}
		int min_value = INF;
		int min_index = -1;
		REP(i, M+1)
		{
			int sum = 0;
			REP(j, M+2)
			{
				sum += A[i][j];
			}
			if (min_value > sum)
			{
				min_index = i;
				min_value = sum;
			}
			else if (min_value == sum)
			{
				min_index = min(min_index, int(i));
			}
		}
		cout << min_index << " " << min_value << endl;
	}
	return 0;
}

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

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
ll pre1[maxn];
ll pre2[maxn];
ll sum;

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

	pre1[1] = 0;
	for(ll i = 2; i <= n; i++){
		pre1[i] = pre1[i - 1] + i - 1;
		//cout << pre1[i] << endl;
	}

	pre2[1] = n - 1;
	for(ll i = 2; i <= n; i++){
		pre2[i] = pre2[i - 1] + n - i;
		//cout << pre2[i] << endl;
	}

	for(ll i = k; i <= n; i++){
		sum += (pre2[i] - pre1[i] +1);
	}
	cout << sum % mod<< endl;
}



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

#define INF 100000000

int main(){
    ll x;
    cin>>x;

    ll a = 100;
    double r = 1.01;
    int ans = 0;

    while(a < x){
        a = floor(a*r);
        ++ans;
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
int main(void){
  
  int i,n,k,xi,s;
  
  cin>>n>>k;
  for(i=0;i<n;i++){
    cin>>xi;
    if(xi < k-xi)s+=2*(xi);
    else s+=2*(k-xi);
  }
  cout<<s;
}

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

int main() {
  int k;
  cin >> k;
  rep(i,k){
    cout << "ACL";
  }
  cout << endl;

  return(0);
}

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

typedef long long ll;

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    rep(i, N) cin >> L[i];
    int s = 0;
    rep(i, N) {
        s += L[i];
        if (s > X) {
            cout << i + 1 << endl;
            return 0;
        }
    }
    cout << N + 1 << endl;
}

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

int main(){
  int n;
  cin>>n;
  if(n>=100000){
    cout<<90000+900+9<<endl;
  }else if(n>=10000){
    cout<<n-9999+909<<endl;
  }else if(n>=1000){
    cout<<909<<endl;
  }else if(n>=100){
    cout<<n-99+9<<endl;
  }else if(n>=10){
    cout<<9<<endl;
  }else{
    cout<<n<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int r = sc.nextInt();
		int D = sc.nextInt();
		int x = sc.nextInt();
		
		for(int i=0;i<10;i++) {
			x=r*x-D;
			System.out.println(x);
		}
	}
}

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 static 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: 23124
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static final int MAX_NUM_OF_PRIME_NUMBERS = 10000;
	static long[] primeTable = new long[MAX_NUM_OF_PRIME_NUMBERS];
	
	public static void main(String[] args) throws IOException{
		primeTable = getPrimeNumbers();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true){
			int n = Integer.parseInt(br.readLine());
			if(n == 0)	break;
			int[] prime = getMaxTwinPrime(n);
			System.out.println(prime[0] + " " + prime[1]);
		}
	}
	public static int[] getMaxTwinPrime(int max){
		int[] prime = new int[2];
		int maxIndex = 0;
		for(int i = 0; i < primeTable.length; i++){
			if(primeTable[i] > max){
				maxIndex = i - 1;
				break;
			}
		}
		for(int i = maxIndex; i > 0; i--){
			if(primeTable[i] - primeTable[i - 1] == 2){
				prime[0] = (int)primeTable[i - 1];
				prime[1] = (int)primeTable[i];
				break;
			}
		}
		return prime;
	}
	private static long[] getPrimeNumbers(){
		long[] primeNumber = new long[MAX_NUM_OF_PRIME_NUMBERS];
		int numPrimeNumbers = 0;
		long n = 1;
		while(numPrimeNumbers < MAX_NUM_OF_PRIME_NUMBERS){
			if( isPrimeNumber(++n) ){
				primeNumber[numPrimeNumbers] = n;
				numPrimeNumbers++;
			}
		}
		return primeNumber;
	}
	private static boolean isPrimeNumber(long target){
		if( target == 2 )	return true;
		if( target % 2 == 0 )	return false;
		for(int i = 3; i * i < target + 1; i = i + 2){
			if( target % i == 0){
				return false;
			}
		}
		return true;
	}
}

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

using namespace std;
int main(){
    int n;
    string s;
    cin >> n >> s;
    int count = 0;
    int max=0;
    for(int i=0;i<n;i++){
        if(s[i] == 'I'){
            count++;
        }
        else if(s[i] == 'D'){
            count--;
        }
        if(count > max)max=count;
    }
    cout << max << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define swap(x,y) (x^=y^=x^=y)
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 5005
#define mod 1000000007
ll dp[MN][MN],g[MN],t[MN],siz[MN];
int hr[MN],en;
struct edge{int to,nex;}e[MN<<1];
inline void ins(int f,int t)
{
	e[++en]=(edge){t,hr[f]};hr[f]=en;
	e[++en]=(edge){f,hr[t]};hr[t]=en;
}
void dfs(int x,int fa){
    siz[x]=1;dp[x][1]=1;register int i,j,k;
    for(i=hr[x];i;i=e[i].nex)if(e[i].to^fa)
	{
    	dfs(e[i].to,x);
    	for(j=0;j<=siz[x];++j)
    		t[j]=dp[x][j],dp[x][j]=0;
    	for(j=0;j<=siz[x];++j)
    		for(k=0;k<=siz[e[i].to];++k)
    			(dp[x][j+k]+=t[j]*dp[e[i].to][k]%mod)%=mod; 
    	siz[x]+=siz[e[i].to];
	}
	for(i=0;i<=siz[x];i+=2)
		dp[x][0]=(dp[x][0]-dp[x][i]*g[i]%mod+mod)%mod;

}
int main(){
    register int i,n,x;
    n=read();
    for(i=1;i<n;++i) x=read(),ins(x,read());
    g[0]=1;for(i=2;i<=n;g[i]=g[i-2]*(i-1)%mod,i+=2);
    dfs(1,0);
    printf("%lld\n",mod-dp[1][0]);
    return 0;
}

Measured memory_bytes: 194944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  
  vector<int> moti(N);
  for(int i=0;i<N;i++){
     cin>>moti.at(i);
  }
  sort(moti.begin(),moti.end());
  int count=0;
  int now=0;
  for(int i=0;i<moti.size();i++){
     if(now<moti.at(i)){now=moti.at(i);count++;}
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split())) + [10 ** 10]
piv = 0
res = 0
tmp = 0
while piv < n:
    if a[piv] >= a[piv + 1]:
        tmp += 1
    else:
        res = max(res, tmp)
        tmp = 0
    piv += 1
else:
    res = max(res, tmp)
print(res)

Measured memory_bytes: 14252
def CountTriangles(arr, n): 

    count = 0

    for i in range(n): 
        for j in range(i + 1, n): 

            for k in range(j + 1, n): 
                  
                if (arr[i] + arr[j] > arr[k] and 
                    arr[i] + arr[k] > arr[j] and 
                    arr[k] + arr[j] > arr[i] and len(set([arr[i],arr[j],arr[k]]))==3): 
                    count += 1
    return count 


n=int(input())
l=list(map(int,input().split()))
print(CountTriangles(l,n))

##d=dict()
##for i in range(n):
##    for j in range(n):
##        for k in range(n):
##            if i==j or j==k or i==k:
##                continue
##            if checktri(l[i],l[j],l[k]):
##                
##                trip=[l[i],l[j],l[k]]
##                trip.sort()
##                if trip in 


Measured memory_bytes: 9192
N = int(input())
a = list(map(int, input().split()))
ans = 0
t = "T"
while t == "T":
    for i in range(N):
        if a[i] % 2 == 0:
            a[i] = a[i] / 2
        else:
            t = "F"
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int x=10000000;
    int cnt=1;
    int m;
    for(int i=0; i<n; i++)
    {
        cin>>m;

        if(i>0)
        {
            if(x>m) ++cnt;
        }
        x=min(x,m);
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int n;
int rez;
int main(){
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
        int p = i, l = 0;
        while(p>0){
            p /= 10;
            l++;
        }
        if(l%2==1)rez++;
    }
    cout <<rez;
    return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

tuple<vector<FiniteField>, vector<FiniteField>> MakeFactorialTables(int n) {
  vector<FiniteField> factorials(n + 1);
  vector<FiniteField> inverse_factorials(n + 1);
  factorials[0] = 1;
  for (int i = 1; i <= n; i++) {
    factorials[i] = factorials[i - 1] * i;
  }
  inverse_factorials[n] = FiniteField(1) / factorials[n];
  for (int i = n; i >= 1; i--) {
    inverse_factorials[i - 1] = inverse_factorials[i] * i;
  }
  return make_tuple(factorials, inverse_factorials);
}

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

  int n, m;
  cin >> n >> m;
  if (abs(n - m) >= 2) {
    cout << 0 << endl;
    return 0;
  }

  vector<FiniteField> fs;
  tie(fs, ignore) = MakeFactorialTables(max(n, m) + 1);
  auto ans = fs[n] * fs[m];
  if (n == m) ans *= 2;
  cout << ans << endl;
}


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

using namespace std;

int main() {

	int n;
	cin >> n;
	vector<int> a(n, 0);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	deque<int> b;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			b.push_back(a[i]);
		}
		else {
			b.push_front(a[i]);
		}
	}

	if (n % 2 != 0) { 
		reverse(b.begin(),b.end());
	}
	for (int i = 0; i < n; i++) {
		cout << b[i] << " " ;
	}
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;

bool same_keta(ll a, ll b, ll k) {
	ll range = 1LL<<k;
	ll bit = (a/range)%2LL;
	if(bit == 0LL) return false;
	else {
		ll len = b-a;
		return (len%2)!=0LL;
	}
}

bool keta(ll a, ll b, ll k) {
	ll range = 1LL<<k;
	ll br = b/range;
	ll ar = a/range;
	ll rs = br-ar;
	if(br>0LL) {
		ll start = (ar+1LL)*range;
		ll end = (br)*range;
		return same_keta(a,start,k)^same_keta(end,b+1LL,k);
	}else {
		if(b<k) return false;
		return same_keta(a,b+1LL,k);
	}
}

bool one(ll a, ll b) {
	b -= ((b-a)/4LL)*4LL-4LL;
	ll ans = 0;
	for(ll i = a; i <= b; i++) {
		ans ^= i;
	}
	return (ans&1LL)==1LL;
}

ll calc(ll a, ll b) {
	ll ans = 0;
	for(ll i = 50; i >= 1; i--) {
		ans |= (keta(a,b,i)?1LL:0LL);
		ans <<= 1LL;
	}
	ans |= (one(a,b)?1LL:0LL);
	return ans;
}

int main() {
	ll a,b;
	cin >> a >> b;
	ll ans = calc(a,b);
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;
const ll so = 1e9+7;

int main(){
    int N;
    cin >> N;
    
    ll ans=1;
    for(int i=1; i<=N; i++){
        ans *= i;
        ans = ans%so;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;


public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		while(sc.hasNext()){
			String[] s = sc.nextLine().split(" ");
			String[] _s = sc.nextLine().split(" ");

			int[] a = new int[4];
			int[] b = new int[4];
			int count = 0,count_2 = 0;

			for(int i = 0; i<4 ; i++){
				a[i] = Integer.parseInt(s[i]);
				b[i] = Integer.parseInt(_s[i]);
			}

			for(int i= 0;i<4;i++){
				for(int j= 0;j<4; j++){
					if(a[i] == b[j]){
						if(i == j) count++;
						else count_2++;
					}
				}
			}
			System.out.println(count + " " +count_2);

		}
	}
}

Measured memory_bytes: 17176
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
    for(int a, b, n; cin >> a >> b >> n; )
	{
		vector<vint> board(a, vint(b, true)), dp(a, vint(b, 0));
		
		rep(i, n)
		{
			int x, y;
			cin >> x >> y;
			
			board[x-1][y-1] = false;
		}
		
		dp[0][0] = 1;
		
		rep(x, a) rep(y, b)
		{
			if(0 < x && board[x-1][y]) dp[x][y] += dp[x-1][y];
			if(0 < y && board[x][y-1]) dp[x][y] += dp[x][y-1];
		}
		
		cout << dp[a-1][b-1] << endl;
	}
}

Measured memory_bytes: 1220
#include <iostream>
#include <list>
#include <vector>

using namespace std;

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

    if (m == 1) {
        cout << "1" << endl;
    } else {
        list<pair<int, int>> prime;
        int d = 0;

        for (int i = 2, mm = m; mm > 1; i++) {
            if (mm % i == 0) {
                pair<int, int> p = make_pair(i, 0);

                while (mm % i == 0) {
                    p.second++;
                    mm /= i;
                }

                prime.push_back(p);

                if (d < p.second) {
                    d = p.second;
                }
            }
        }

        vector<vector<long long>> dp(d, vector<long long>(n, 0));
        dp[0][0] = 1;

        for (int i = 0; i < d; i++) {
            for (int j = 0; j < n; j++) {
                if (i < d - 1) {
                    dp[i + 1][j] += dp[i][j];
                    dp[i + 1][j] %= 1000000007;
                }

                if (j < n - 1) {
                    dp[i][j + 1] += dp[i][j];
                    dp[i][j + 1] %= 1000000007;
                }
            }
        }

        vector<long long> cmb(d, 0);

        for (int i = 0; i < d; i++) {
            for (int j = 0; j < n; j++) {
                cmb[i] += dp[i][j];
                cmb[i] %= 1000000007;
            }
        }

        long long res = 1;

        for (list<pair<int, int>>::iterator i = prime.begin(); i != prime.end(); i++) {
            res *= cmb[i->second - 1];
            res %= 1000000007;
        }

        cout << res << endl;
    }
}


Measured memory_bytes: 23808
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;


ll n;
ll index, a, b;
ll sum[5000];
V vi;

int main(){
	while (cin >> n&&n){
		vi.clear();
		fill(sum, sum + 5000, 0);
		REP(i, n){
			cin >> index >> a >> b;
			if (find(ALL(vi), index) == vi.end()){
				vi.push_back(index);
			}
			if (sum[index] >= 1000000)continue;
			sum[index] += a*b;
		}
		bool f = 1;
		REP(i, vi.size()){
			if (sum[vi[i]] >= 1000000){
				cout << vi[i] << endl;
				f = 0;
			}
		}
		if (f)cout << "NA" << endl;
	}
}

Measured memory_bytes: 1268
/**
 * Problem:	D. 
 * Author:	hkxadpall. 
 * Date:	2018-08-25. 
 * Upload:	AtCoder. 
 */
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue> 
#include <map>
#include <set>
using namespace std;

namespace AuthorName { 
    template <typename _TpInt> inline _TpInt read();
    template <typename _TpRealnumber> inline double readr();
    template <typename _TpInt> inline void write(_TpInt x);
//	template <typename _TpSwap> inline void swap(_TpSwap &x, _TpSwap &y);
	
#	define Max_N 1007
	
	int n, m;
	
	int main() 
	{
		n = read<int>();
		m = read<int>();
		char str[101][101];
		bool look1[101] = {0}, look2[101] = {0};
		for (int i = 0; i < n; i++)
			scanf("%s", str[i]);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (str[i][j] == '#') look1[i] = look2[j] = 1;
			}
		}
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (look1[i] && look2[j]) putchar(str[i][j]);
			}
			if (look1[i]) putchar(10);
		}
	    return 0;
	}

#	define Getchar() getchar()

    template <typename _TpInt>
    inline _TpInt read()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpInt init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = (init << 3) + (init << 1) + (c & 15);
        return init * flag;
    }

    template <typename _TpRealnumber>
    inline double readr()       
    {
        register int flag = 1;
        register char c = Getchar();
        while ((c > '9' || c < '0') && c != '-') 
            c = Getchar();
        if (c == '-') flag = -1, c = Getchar();
        register _TpRealnumber init = (c & 15);
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init * 10 + (c & 15);
        if (c != '.') return init * flag;
        register _TpRealnumber l = 0.1;
        while ((c = Getchar()) <= '9' && c >= '0') 
            init = init + (c & 15) * l, l *= 0.1;
        return init * flag;
    }

    template <typename _TpInt>
    inline void write(_TpInt x)
    {
        if (x < 0) {
            putchar('-');
            write<_TpInt>(~x + 1);
        }
        else {
            if (x > 9) write<_TpInt>(x / 10);   
            putchar(x % 10 + '0');
        }
    }

//	template <typename _TpSwap>
//	inline void swap(_TpSwap &x, _TpSwap &y)
//	{
//	    _TpSwap t = x;
//	    x = y;
//	    y = t;
//	}
}

int main()
{
    AuthorName::main();
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define all(v) (v).begin(),(v).end()
int GCD(int a,int b){
	/*最大公約数*/
	int r,tmp;
	if(a<b){
		tmp = a;
		a = b;
		b = tmp;
    }
    r = a % b;
	while(r!=0){
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}
int main(){
	int n,ans;
	cin>>n;
	vector<int> an(n,0);
	rep(i,n){
		cin>>an.at(i);
	}
	ans=GCD(an.at(0),an.at(1));
	for(int k=1;k<n;k++){
		ans=GCD(ans,an.at(k));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int n, tmp, count;
	while(cin >> n){
		count = 0;
		for(int i = 0; i <= 9; i++){
			if(i > n){
				break;
			}
			for(int j = 0; j <= 9; j++){
				if((i + j) > n){
					break;
				}
				for(int k = 0; k <= 9; k++){
					tmp = i + j + k;
					if(tmp > n){
						break;
					}
					for(int l = 0; l <= 9; l++){
						if(n == (tmp+l)){
							count++;
							break;
						}
					}
				}
			}
		}
		
		cout << count << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0