akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cassert>
#include<cstdio>
using namespace std;

struct P
{
  int s,e;
  P(int s,int e):s(s),e(e){}
};

void shuffle(vector<P>& vec,int x,int y,int n)
{
  vector<P> ins;
  for(int i=0;i<vec.size();i++)
    {
      if(vec[i].e <= x)
	{
	  vec[i].s += (n-x),vec[i].e += (n-x);
	}
      else if(vec[i].s <= x && vec[i].e <= y)
	{
	  ins.push_back(P(x+1,vec[i].e));
	  ins[ins.size()-1].s += (n-y)-x,ins[ins.size()-1].e += (n-y)-x;
	  vec[i].e = x;
	  vec[i].s += (n-x),vec[i].e += (n-x);
	}
      else if(vec[i].s <= x && vec[i].e  > y)
	{
	  ins.push_back(P(vec[i].s,x));
	  ins[ins.size()-1].s += (n-x),ins[ins.size()-1].e += (n-x);
	  ins.push_back(P(x+1,y));
	  ins[ins.size()-1].s += (n-y)-x,ins[ins.size()-1].e += (n-y)-x;
	  vec[i].s = y+1;
	  vec[i].s -= y,vec[i].e -= y;
	}
      else if(vec[i].s  > x && vec[i].e <= y)
	{
	  vec[i].s += (n-y)-x,vec[i].e += (n-y)-x;
	}
      else if(vec[i].s  > x && vec[i].s <= y && vec[i].e  > y)
	{
	  ins.push_back(P(vec[i].s,y));
	  ins[ins.size()-1].s += (n-y)-x, ins[ins.size()-1].e += (n-y)-x;
	  vec[i].s = y+1;
	  vec[i].s -= y,vec[i].e -= y;
	}
      else if(vec[i].s  > y)
	{
	  vec[i].s -= y,vec[i].e -= y;
	}
      else 
	assert(false);
    }
for(int i=0;i<ins.size();i++)
  vec.push_back(ins[i]);
}

int main()
{
  int n;
  while(scanf("%d",&n),n)
    {
      int m;
      scanf("%d",&m);
      int p,q,r;
      scanf("%d %d %d",&p,&q,&r);
      vector<P> vec;
      vec.push_back(P(1,r));

      for(int i=0;i<m;i++)
	{
	  int x,y;
	  scanf("%d %d",&x,&y);
	  shuffle(vec,x,y,n);
	}
   
      int cnt = 0;
      for(int i=0;i<vec.size();i++)
	{
	  if(vec[i].s > q || vec[i].e < p)
	    continue;
	  cnt += min(vec[i].e,q) - max(vec[i].s,p)+1;
	}
      cout << cnt << endl;
    }
  return 0;
}

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

int main()
{
	string s,t;
	cin>>s>>t;
	int a = 0;
	for(size_t i = 0; i<s.size(); i++)
	{
		if(s[i]!=t[i])
		{
			a = 1;
		}
	}
	if(a==0)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

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

    // input
    int N;
    cin >> N;

    ll ans = 1;

    vector<ll> A(N);
    FOR(i, 0, N){
        ll t;
        cin >> t;
        ans = lcm(ans, t);
    }

    p(ans);
    
    return 0;
}

Measured memory_bytes: 256
S = input()
c = 0
zo = 0 # zero-one
oz = 0 # one-zero
for i in range(0, len(S)//2 * 2, 2):
    if S[i] == '0':
        oz += 1
    else:
        zo += 1
    if S[i+1] == '0':
        zo += 1
    else:
        oz += 1
if len(S) & 1:
    if S[-1] == '0':
        oz += 1
    else:
        zo += 1
print(min(oz, zo))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> x(N), y(N);

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

    double sum=0;
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            sum += sqrt((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]));
        }
    }
    printf("%.10f\n", sum/N);
    return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) begin(x), end(x)
#define uniq(x) (x).erase(unique(all(x)), end(x))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr long double PI = 3.1415926535897932384626433832795028L;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

string S, T;
signed main() {
    cin >> S >> T;
    if (S == T.substr(0, S.length())) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  x = 0;
  bool flag = 0;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') {
      flag = 1;
    }
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  if (flag) {
    x = -x;
  }
}
const int N = 805;
int n, m, k, sx, sy, ans = 1e9;
char mp[N][N];
bool vis[N][N];
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
struct node {
  int x, y;
};
node que[N * N];
void bfs() {
  int l = 1, r = 0;
  que[++r] = (node) {sx, sy};
  vis[sx][sy] = 1;
  while (l <= r) {
    int x = que[l].x;
    int y = que[l++].y;
    ans = min(ans, (min(min(x - 1, n - x), min(y - 1, m - y)) + k - 1) / k + 1);
    for (int i = 0; i < 4; ++i) {
      int X = x + dx[i], Y = y + dy[i];
      if (X >= 1 && X <= n && Y >= 1 && Y <= m && abs(sx - X) + abs(sy - Y) <= k && !vis[X][Y] && mp[X][Y] != '#') {
        vis[X][Y] = 1;
        que[++r] = (node) {X, Y};
      }
    }
  } 
}
int main() {
  read(n), read(m), read(k);
  for (int i = 1; i <= n; ++i) {
    scanf("%s", mp[i] + 1);
    for (int j = 1; j <= m; ++j) {
      if (mp[i][j] == 'S') {
        sx = i, sy = j;
      }
    }
  } 
  bfs();
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 9888
#include<bits/stdc++.h>
using namespace std;
const long long int mod =1e9+7;
long long int power(long long int x,long long int y)
{
  if (y == 0)
   return 1;


       long long int p = power(x, y/2) % mod;
       p = (p * p) % mod;

    return (y%2 == 0)? p : (x * p) % mod;
}

long long int coff(long long int n,long long int x)
{
    long long int res=1;
     if(x > n-x)
      x=n-x;

       for(int i=1;i<=x;i++)
          res = (res*(n+1-i))%mod;

      for(int i=1;i<=x;i++)
      {
        long long int t=power(i,mod-2);
         res = (res*t)%mod;
       }

      return res;
}
int main()
{
   long long int n,a,b;
     cin>>n>>a>>b;

      long long int calculate = power(2,n);

        long long int ans=coff(n,a);
        long long int temp=coff(n,b);

         long long int final = (calculate-1+mod)%mod;
         final = (final -ans + mod)%mod;
         final = (final - temp + mod)%mod;

        cout<<final;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n,a,b;
  cin>>n>>a>>b;
  ll densya = n*a;
  cout<< (densya>b?b:densya);
  return 0;
}

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

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

	int N = S.size();
	int N1 = T.size();
	int ma = 0;
	for( int i = 0; i + (N1 - 1) < N; i++ ) {
		int n = 0;
		for( int j = 0; j < N1; j++ ) {
			if( S[i + j] == T[j] ) n++;
		}
		ma = max( ma, n );
	}
	int ans = N1 - ma;

	cout << ans << endl;
}


Measured memory_bytes: 3508
#include<stdio.h>
#define N 8
#define NOT_FREE 1
#define FREE 0

int col[N],dpos[15],dneg[15],row[N];
int p[N][N]={};

int printBoard(void){
    int i,j;
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(p[i][j]){
                if(row[i]!=j)return 0;
            }
        }
    }
    for(i=0;i<N;i++){
        for(j=0;j<N;j++){
            if(row[i]!=j)printf(".");
            else printf("Q");
        }
        printf("\n");
    }
    return 0;
}

void putQueen(int i){
    int j;
    if(i==N){
        printBoard();
        return;
    }
    for(j=0;j<N;j++){
        if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)continue;
        row[i]=j;
        col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
        putQueen(i+1);
        row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
    }
}



int main(){
    int n,i,j;
    int x,y;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d%d",&x,&y);
        p[x][y]++;
    }
    putQueen(0);
    return 0;
}



Measured memory_bytes: 2108
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	lli a, b, x;
	cin >> a >> b >> x;
	
	cout << b/x - (a==0?(-1):(a-1)/x) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);

        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=sc.nextInt();

        if(a<b&&b<c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 26372
s=input()
l=[]
for i in range(len(s)):
    if s[i]=='0':
        l.append('0')
    elif s[i]=='1':
        l.append('1')
    else:
        if len(l)>0:
            l.pop(len(l)-1)
x=''.join(l)
print(x)

Measured memory_bytes: 3060
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: ident) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    let mut it = s.split_whitespace();
    let mut a = vec![];
    for _ in 0..3 {
        let l = parse!(it, 3);
        a.push(vec![l.0, l.1, l.2]);
    }
    let n = parse!(it);
    let mut check = vec![vec![false; 3]; 3];
    for _ in 0..n {
        let b: usize = parse!(it);
        for i in 0..3 {
            for j in 0..3 {
                if b == a[i][j] {
                    check[i][j] = true;
                }
            }
        }
    }
    let mut ret = "No";
    for i in 0..3 {
        if check[i][0] && check[i][1] && check[i][2] {
            ret = "Yes";
            break;
        }
    }
    for i in 0..3 {
        if check[0][i] && check[1][i] && check[2][i] {
            ret = "Yes";
            break;
        }
    }
    if check[0][0] && check[1][1] && check[2][2] {
        ret = "Yes"
    }
    if check[0][2] && check[1][1] && check[2][0] {
        ret = "Yes"
    }
    println!("{}", ret);
}


Measured memory_bytes: 4352
n = str(input())
a = int(n[0])
b = int(n[1])
c = int(n[2])
d = int(n[3])
ans = a
for bit in range(8):
    if bit & (1<<2):
    	ans += b
    	op1 = '+'
    else:
        ans -= b
        op1 = '-'
    if bit & (1<<1):
        ans += c
        op2 = '+'
    else:
        ans -= c
        op2 = '-'
    if bit & 1:
        ans += d
        op3 = '+'
    else:
        ans -= d
        op3 = '-'
    if ans == 7:
        print(str(a) + op1 + str(b) + op2 + str(c) + op3 + str(d) + "=7")
        break
    ans = a

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

int main() {
  int n;
  cin >> n;
  vector<pair<string, int>> a(n);
  for(int i=0;i<n;i++) cin >> a[i].first >> a[i].second;
  string x;
  cin >> x;
  int from = 0;
  for(int i=0;i<n;i++) {
    if(a[i].first == x) {
      from = i + 1;
      break;
    }
  }
  int ans = 0;
  for(int i=from;i<n;i++) {
    ans += a[i].second;
  }

  cout << ans << endl;
}

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

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        int[] dp = new int[n];
        dp[1] = Math.abs(a[1] - a[0]);

        for (int i = 2; i < n; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = 1; j <= Math.min(i, k); j++) {
                min = Math.min(min, dp[i - j] + Math.abs(a[i - j] - a[i]));
            }
            dp[i] = min;
        }

        out.println(dp[n - 1]);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


Measured memory_bytes: 36140
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll MOD = 1000000007;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y;
    return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define sz(a) int((a).size())
#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 what_is(x) cout << #x << " is: " << x << endl;
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define ll long long int

#define vi vector<int>
#define pii pair<int,int>
#define vl vector<ll>
#define pll pair<ll, ll>

template<typename T>
T extgcd(T a, T b, T &x, T &y) { if (b == 0) {x = 1;y = 0;return b;}T x1, y1;T g = extgcd(b, a % b,x1, y1);x = y1; y = x1 - (a/b)*y1;return g;}
template<typename T>
T fast_power(T a, T b){T res = (T)1;while( b ){if( b & 1 ) res = res * a;b >>= 1;a *= a; } return res;}
template<typename T>
T fast_powerModulo( T a, T b, T M){T res = (T)1;a %= M;while( b ){if( b & 1 ) res = (res * a) % M;b >>= 1;a *= a;a %= M; }return res;}
template<typename T>
T LCM(T a, T b){ T gd = __gcd(a, b); T ml = a * b; return ml/ gd;}

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

const int INF = 1<<30;
const ll LINF = 1ll<<60;

int main(){
    FAST
    int h, w;
    cin >> h >> w;
    int n; cin >> n;
    int mx = max(h , w);
    int mn = min(h , w);
    int val = (n + mx - 1)/mx;
    cout << val << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

int32_t main(){
	IOS;
	int x, a;
	cin >> x >> a;

	if(x < a){
		cout << 0 << endl;
	}	
	else{
		cout << 10 << endl;
	}




	return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mkmap;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<vi> vv;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
const ll mod=1000000007;
const int sz=1000001;
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(i=a;i<b;++i)
#define rrep(i,a,b) for(i=a;i>=b;--i)
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define db(x) cout << (#x) << " = " << x << endl;

inline ll mult(ll a, ll b) {return (((a % mod) * (b % mod)) % mod);}

int mn;
int dp[2][100001];

bool fun(vi &a,bool turn,int k){
    if(k<mn) return !turn;
    if(dp[turn][k]!=-1) return dp[turn][k];
    for(auto p:a){
        if(p>k) continue;
        if(fun(a,!turn,k-p)==turn) return dp[turn][k]=turn;
    }
    return dp[turn][k]=!turn;
}

int main(){
    fast;
    int t,tt,tti,n,m,x,y,z,i,j,k,temp,count,o,e,f,ans,sum,l,r,mx;
    ll lx,ly,lz,ltemp;
    double fx,fy,fz;
    string s;

    memset(dp,-1,sizeof(dp));

    cin>>n>>m;
    vi a(n);
    mn=100000;
    rep(i,0,n) cin>>a[i];
    rep(i,0,n) mn=min(mn,a[i]);
    cout<<(fun(a,true,m)?"First":"Second");
}

/*
    
*/

Measured memory_bytes: 13796
l,r = map(int,input().split())
if r-l>=2018:
  print(0)
else:
  ans = float('inf')
  for i in range(r-l):
    for j in range(i+1,r-l+1):
      ans = min((((l+i)%2019)*((l+j)%2019))%2019,ans)
  print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;

vector<vector<ll>> dp(410, vector<ll>(410,longinf));
vector<ll> asum(410,0);                       //ruisekiwa

ll dfs(int l,int r){
  if(dp[l][r]!=longinf){ return dp[l][r]; }
  if(l==r){ return 0; }
  ll cur=longinf;
  for(int i=l; i<r; i++){
    cur = min(cur, dfs(l,i)+dfs(i+1,r));     //dokode wakeruka zentansaku
  }
  return dp[l][r] = cur+(asum[r]-asum[l-1]);  //l~r no goukei
}


int main(){
  int n;
  cin >> n;
  vector<ll> a(410);
  rep(i,n){ cin >> a[i]; }
  asum[0]=0;
  rep(i,n){ asum[i+1]=asum[i]+a[i]; }
  
  ll ans = dfs(1,n);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    vector<char> s(N);
    for(int i = 0; i < N; i++){
        cin >> s[i];
    }

    if(K >= 1 && K <= N){
        //cout << "bbb";
        s[K-1] += (char)32;
    }

    for(int i = 0; i < N; i++){
        cout << s[i];
    }

    cout << endl;
}

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

/*
 * ref. https://ja.wikipedia.org/wiki/%E3%83%80%E3%82%A4%E3%82%AF%E3%82%B9%E3%83%88%E3%83%A9%E6%B3%95
 */

using namespace std;

#define MAX_V 100000
#define INF 1000000001

typedef long long ll;
typedef int PrevList[MAX_V];
typedef ll DistanceList[MAX_V];

class Elem {
    public:
        int vertex;
        ll distance;

        bool operator < (const Elem &other) const {
            return distance < other.distance;
        }

        bool operator > (const Elem &other) const {
            return distance > other.distance;
        }
};

// auto compare = [](Elem a, Elem b) {
//     return a.distance < b.distance;
// };

typedef vector<vector<Elem> > Edges;

// typedef priority_queue<Elem, vector<Elem>, decltype(compare)> PriorityQueue;
typedef priority_queue<Elem, vector<Elem>, greater<Elem> > PriorityQueue;

/*
 * n: size of vertices (assume that names of vertices are 0, 1, ..., n-1)
 * start: start vertex
 */
void dijkstra(const int n, const int start, const Edges &edges,
        PrevList &prev_list, DistanceList &d_list, PriorityQueue &queue) {
    // Initialization
    for (int i = 0; i < n; i++) {
        if (i == start) {
            d_list[i] = 0;
        } else {
            d_list[i] = INF;
        }

        prev_list[i] = -1;

        Elem elem;
        elem.vertex = i;
        elem.distance = d_list[i];
        queue.push(elem);
    }

    while (queue.size() > 0) {
        Elem elem = queue.top();
        queue.pop();

        for (int i = 0; i < edges[elem.vertex].size(); i++) {
            Elem next = edges[elem.vertex][i];
            ll alt = d_list[elem.vertex] + next.distance;
            if (d_list[next.vertex] > alt) {
                d_list[next.vertex] = alt;
                prev_list[next.vertex] = elem.vertex;

                Elem e;
                e.vertex = next.vertex;
                e.distance = d_list[next.vertex];
                queue.push(e);
            }
        }
    }
}

Edges edges;
PrevList prev_list;
DistanceList d_list;

// ref. http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A&lang=jp
int main(void) {
    PriorityQueue q;

    int v, e, r;

    cin >> v >> e >> r;

    for (int i = 0; i < v; i++) {
        edges.push_back(vector<Elem>());
    }

    for (int i = 0; i < e; i++) {
        int s, t, d;
        Elem e;
        cin >> s >> t >> d;

        e.vertex = t;
        e.distance = d;
        edges[s].push_back(e);
    }

    dijkstra(v, r, edges, prev_list, d_list, q);

    for (int i = 0; i < v; i++) {
        if (d_list[i] != INF) {
            cout << d_list[i] << endl;
        } else {
            cout << "INF" << endl;
        }
    }

    return 0;
}



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

int main() {
	int n,k;
	cin>>n>>k;
	int a[n+5];
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	int sum=0;
	for(int i=0;i<k;i++)
	 sum+=a[i];
	cout<<sum;
	return 0;
}

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

#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define si set<int>
#define ii pair<int,int>
#define f first
#define s second
#define pb push_back
#define endl '\n'
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define sz(c) (int) (c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define db(x) cout << #x << ": " << x << endl
#define _db(c) for (auto x : c) cout << x << " "; cout << endl
#define forc(i,c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define tc int t; cin >> t; while (t--)

ll MOD = 1000000007;
ll ans = 0;
ll a, b, i, j, m, n, x, y;

int main() { 
	io;
	
	int count = 1;
	while (cin >> x) {
		if (x == 0) {cout << count; return 0;}
		count++;
	}
	
}

Measured memory_bytes: 3612
#include<stdio.h>
int main()
{
	int A,B,cnt;
	scanf("%d%d",&A,&B);
	//if(B==1) printf("0\n");
	if(A==B){
		printf("1\n");	
	}else{
		for(int i=0;i<=30;i++){
			cnt=A*i-i+1;
			if(cnt>=B){		
				printf("%d\n",i);
				break;
			}
		}
	}
}


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

int main(){
    int a,b;
    int c1,c2,c3;
    cin >> c1 >> c2 >> c3;
    a = c2-c1;
    b = c3-c2;
    bool possible = true;
    for(int i=0; i<2; i++){
        int p,q,r;
        cin >> p >> q >> r;
        if(q-p != a || r-q != b){
            possible = false;
        }
    }
    if(possible){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main(){
	long long n, ans = 0;
	cin >> n;
	vector<long long> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	if(a[n - 1] != 2){
		cout << -1 << endl;
		return 0;
	}
	long long l = 2, r = 3;
	bool f = true;
	for(int i = n - 2; i >= 0; i--){
		long long l2 = l / a[i], r2 = r / a[i];
		if(l % a[i] != 0 && r % a[i] != 0 && l2 == r2){
			f = false;
			break;
		}
		l = a[i] * (long long)((l + a[i] - 1) / a[i]);
		r = a[i] * (long long)(r / a[i] + 1) - 1;
		
	}
	if(f){
		cout << l << " " << r << endl;
	}else{
		cout << -1 << endl;
	}
	return 0;
}

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

long long n,d,x,y,ans;

int main()
{
	ios::sync_with_stdio(false);

	cin>>n>>d;
	d*=d;

	for(int i=0;i<n;i++)
	{
		cin>>x>>y;
		if(x*x+y*y<=d) ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ===================

// Template End =========================

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













Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {
	
	int N,M; cin >> N >> M;

	for (int i = 0; i < M; i++) {
		int a; cin >> a;
		N -= a;
	}
	if (N < 0) {
		cout << -1 << endl;	
	}else {
		cout << N << endl;
	}

	return 0;
}


Measured memory_bytes: 3620
import java.util.*;

public class Main {

    static List<List<Integer>> edges = new ArrayList<>();
    static int[] dp = null;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();

        char[][] grid = new char[H][W];
        for (int i = 0; i < H; i++) {
            String s = sc.next();
            for (int j = 0; j < s.length(); j++) {
                grid[i][j]=s.charAt(j);
            }
        }


        long[][] dp = new long[H+1][W+1];

        int ans = 0;
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if(i==1 && j==1){
                    dp[i][j]=1;
                    continue;
                }
                if(grid[i-1][j-1]=='.'){
                    dp[i][j] = dp[i-1][j] + dp[i][j-1];
                    dp[i][j] %= 1_000_000_007;
                }
            }
        }

        System.out.println(dp[H][W]);
    }

}


Measured memory_bytes: 41100
#include<iostream>
using namespace std;
int main(){
	int a;
	cin>>a;
	int b[a],c[a],d=0;
	for(int i=0;i<a;i++){
		cin>>b[i];
	}
	for(int i=0;i<a;i++){
		cin>>c[i];
	}
	for(int i=0;i<a;i++){
		if(b[i]-c[i]>0)
			d+=b[i]-c[i];
	}
	cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
int ans;
int n, k, q, a[2010], ls[2010];
priority_queue <int, vector <int>, greater <int> > q1, q2;
int main () {
	scanf ("%d%d%d", &n, &k, &q);
	for (int i = 1; i <= n; i++) scanf ("%d", &a[i]), ls[i] = a[i];
	sort (ls + 1, ls + n + 1);
	ans = ls[n] - ls[1];
	for (int p = 1; p <= n; p++) {
		for (int i = 1; i <= n; i++) if (a[i] >= ls[p]) {
			int j = i; while (j < n && a[j + 1] >= ls[p]) j++;
			if (j - i + 1 < k) { i = j; continue; }
			for (int x = i; x <= j; x++) q1.push (a[x]);
			for (int x = j - i + 1; x >= k; x--) q2.push (q1.top ()), q1.pop ();
			while (!q1.empty ()) q1.pop ();
			i = j;
		}
		int mx = 0; bool ok = true;
		for (int i = 1; i <= q; i++) {
			if (q2.empty ()) { ok = false; break; }
			mx = q2.top (), q2.pop ();
		}
		while (!q2.empty ()) q2.pop ();
		if (ok) ans = min (ans, mx - ls[p]);
	}
	printf ("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

    public static void main(String[] args) {
     
        Scanner entrada=new Scanner(System.in);
        int k=entrada.nextInt();
        int x[]=new int[k];
        int x2[]=new int[3];
        int count=0;
        int count2=0;
        for (int i = 0; i < k; i++) {
            x[i]=entrada.nextInt();
        }
      
        for (int i = 0; i < k-2; i++) {
            for (int j = 0; j < 3; j++) {
            
           x2[j]=x[j+count];
          
        }
        count++;  
     Arrays.sort(x2);
         
       if(x[count]==x2[1]){
           count2++;
       
       }
       
       }
  System.out.println(count2);
    }
    
}


Measured memory_bytes: 23892
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_E main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


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

    int N, M; cin >> N >> M;
    vi U(M), V(M);
    REP(i,M) {
        cin >> U[i] >> V[i];
        U[i]--; V[i]--;
    }
    int S, T; cin >> S >> T;
    S--; T--;

    vvi es(N);
    REP(i,M) {
        es[U[i]].push_back(V[i]);
    }

    vvi dist(N, vi(3, INF));

    queue<pii> que;
    que.push(pii(S, 0));
    dist[S][0] = 0;

    while(!que.empty()) {
        pii v = que.front(); que.pop();
        int x = v.first;
        int l = v.second;
        for(int nx : es[x]) {
            int nl = (l + 1) % 3;
            if (dist[nx][nl] != INF) continue;
            dist[nx][nl] = dist[x][l] + 1;
            que.push(pii(nx, nl));
        }
    }

    int ans = dist[T][0] == INF ? -1 : dist[T][0] / 3;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12032
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n, q;
    cin >> n >> q;
    VI a(q), b(q);
    REP(i, q) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    vector<bool> ans(n, false);
    ans[0] = true;
    ans[1] = true;
    int pos = 0;
    REP(i, q) {
        if (a[i] == pos) { pos = b[i]; }
        else if (b[i] == pos) { pos = a[i]; }
        swap(ans[a[i]], ans[b[i]]);
        if (pos > 0) { ans[pos - 1] = true; }
        if (pos < n-1) { ans[pos + 1] = true; }
    }

    int ansc=0;
    REP(i,n){
        if(ans[i]){
            ansc++;
        }
    }
    cout << ansc << endl;

    return 0;
}

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

ll calc(ll i, ll j, const vector<vector<ll>>& a){
    ll ret = 0;
    REP(u, a.size()){
        REP(v, a.at(i).size()){
            ll n = a.at(u).at(v);
            ret += n * min(abs(i - u), abs(j - v));
        }
    }
    return ret;
}

int main(){
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> a(h, vector<ll>(w));
    REP(i, h){
        REP(j, w){
            cin >> a.at(i).at(j);
        }
    }

    ll ans = numeric_limits<ll>::max();
    REP(i, h){
        REP(j, w){
            ans = min(ans, calc(i, j, a));
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3176
import java.util.*;

public class Main {
    public static void main(String[] args) {
        HashMap<String, Integer> si = new HashMap<String, Integer>();

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        sc.nextLine();

        for (int i = 0; i < N; i++) {
            String s;
            s = sc.next();
            si.put(s,si.getOrDefault(s,0)+1);
        }


        Iterator it = si.entrySet().iterator();
        ArrayList arr = new ArrayList();
        int currentMax = 0;

        while(it.hasNext()) {
            Map.Entry<String,Integer> set = (Map.Entry<String, Integer>) it.next();

            if (set.getValue()>currentMax) {
                arr.clear();
                arr.add(set.getKey());
                currentMax = set.getValue();
            }

            else if (set.getValue()==currentMax) {
                arr.add(set.getKey());
            }

            else {
            }
        }
        Collections.sort(arr);
        for (int i = 0; i < arr.size(); i++) {
            System.out.println(arr.get(i));
        }
    }
}


Measured memory_bytes: 82268
from collections import deque


def main():
    H, W = map(int, input().split())
    A = [input() for _ in range(H)]
    q = deque()
    visited = [[False] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if A[i][j] == "#":
                q.append((i, j, 0))
                visited[i][j] = True
    ans = 0
    directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    while len(q):
        i, j, cost = q.popleft()
        ans = max(ans, cost)
        for d in directions:
            ni = i + d[0]
            nj = j + d[1]
            if 0 <= ni < H and 0 <= nj < W and not visited[ni][nj]:
                q.append((ni, nj, cost+1))
                visited[ni][nj] = True
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 135900
#include <stdio.h>

int main(){
    int a, b, c;
    int i;
    int count = 0;
    scanf("%d%d%d", &a, &b, &c);
    
    for(i=a;i<=b;i++){
        if(c % i == 0)
            count++;
    }
    
    printf("%d\n", count);
    
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

vvl G = VV(5001, 0, 0, ll);
// 頂点iを見ている時点でペアが決まっていない点がj個ある場合の数
#define P 1000000007
#define N_MAX 10000000
typedef long long int ll;
ll fac[N_MAX+1];
ll inv[N_MAX+1];
ll finv[N_MAX+1];

ll comb(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (((fac[n]*finv[n-k])%P)*finv[k])%P;
}
ll perm(ll n, ll k){
  if(n<0||k<0||n<k) return 0;
  return (fac[n]*finv[n-k])%P;
}

void init(){
  fac[0] = finv[0] = fac[1] = finv[1] = inv[1] = 1;
  for(int i = 2; i <= N_MAX; i++){
    fac[i] = (fac[i-1]*i)%P;
    inv[i] = ((-(P/i)*inv[P%i])%P+P)%P;
    finv[i] = (finv[i-1]*inv[i])%P;
  }
}
ll pp(ll a, ll b){
  return (a * b)%P;
}

ll root = -1;
vvl dp = VV(5001, 0, 0, ll);
vll pat(100000, 0);

ll dfs(ll now, ll from){
  if(G[now].size()==1){
    dp[now] = vll{0, 1, 0, 0};
    return 1;//ノード数
  }
  ll s = 1, idx = 0;
  vvl tmp_dp;
  tmp_dp.push_back(vll{0, 1, 0, 0});
  for(auto to:G[now]){
    if(to==from) continue;
    ll num = dfs(to, now);
    tmp_dp.push_back(vll((s+num+1)*2+1,0));

    ll th = s+num+1;
    for(int l=0;l<=s;l++){
      for(int r=0;r<=num;r++){
        //rを追加する時に切る場合
        tmp_dp[idx+1][l+th] =
        (tmp_dp[idx+1][l+th] +
        pp(pp(tmp_dp[idx][l], dp[to][r]), pat[r])+
        pp(pp(tmp_dp[idx][l+s+1], dp[to][r+num+1]), pat[r]))%P;

        tmp_dp[idx+1][l] =
        (tmp_dp[idx+1][l] +
        pp(pp(tmp_dp[idx][l+s+1], dp[to][r]), pat[r])+
        pp(pp(tmp_dp[idx][l], dp[to][r+num+1]), pat[r]))%P;

        //切らない場合
        tmp_dp[idx+1][l+r] =
        (tmp_dp[idx+1][l+r] +
        pp(tmp_dp[idx][l], dp[to][r]) +
        pp(tmp_dp[idx][l+s+1], dp[to][r+num+1]) )%P;

        tmp_dp[idx+1][l+r+th] =
        (tmp_dp[idx+1][l+r+th] +
        pp(tmp_dp[idx][l], dp[to][r+num+1]) +
        pp(tmp_dp[idx][l+s+1], dp[to][r]) )%P;
      }
    }
    idx++;
    s += num;
  }
  dp[now] = tmp_dp[idx];
  return s;
}


int main(int argc, char const *argv[]) {
  init();
  ll n;std::cin >> n;
  for(int i=0;i<n-1;i++){
    ll a, b;std::cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  if(n==2){
    std::cout << 1 << '\n';
    return 0;
  }
  for(int i=1;i<=n;i++){
    if(G[i].size()>1){
      root = i;
      break;
    }
  }
  pat[2] = 1;
  for(ll i=3;i<100000;i++) pat[i] = (pat[i-2]*(i-1))%P;//k個での組
  dfs(root, -1);
  ll ans = 0;
  //std::cout << dp[root].size() << '\n';
  for(int i=0;i<=n;i++){
    dp[root][i] = pp(dp[root][i], pat[i])%P;
    dp[root][i+n+1] = pp(dp[root][i+n+1], pat[i])%P;
  }
  for(int i=0;i<=n;i++){
    ans = (ans + dp[root][i])%P;
    ans = (ans - dp[root][i+n+1] + P)%P;
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 434280
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}


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

	ll  d, n, m, k, ans = 0, ret = M;
	bool flag = false, flag2 = false;
	string s, t;
	cin >> s;
	rep(i, s.size()-1) {
		if (s[i] == s[i + 1]) {
			cout << i+1 << " " << i+2 << endl;
			return 0;
		}
	}
	rep(i, s.size() - 2) {
		if (s[i] == s[i + 2]) {
			cout << i+1 << " " << i+3 << endl;
			return 0;
		}
	}
	cout << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
typedef long long int ll;

template<typename T>
struct BellmanFord{
	struct Edge{
		int  from,to; ll cost;
		Edge(){}
		Edge(int from,int to,ll cost):from(from),to(to),cost(cost){}
	};

	int n;
	vector<vector<int> >G;
	vector<int> used,reach;
	BellmanFord(int n):n(n),G(n),used(n,0),reach(n,0){}

	vector<Edge> es;
	void add_edge(int from,int to,ll cost){
		es.push_back(Edge(from,to,cost));
		G[from].push_back(to);
	}

	void dfs(int v){
		if(used[v])return ;
		used[v]=1;
		for(int u:G[v]){
			dfs(u);
		}
	}
	ll build(int from,int to,int &neg_loop){
		for(int i=0;i<n;i++){
			fill(used.begin(),used.end(),0);
			dfs(i);
			reach[i]=used[to];
		}
		vector<ll> ds(n,1e18);
		ds[from]=0;
		for(int i=0;i<n;i++){
			bool update=0;
			for(auto e:es){
				if(!reach[e.from]||!reach[e.to]||ds[e.from]==1e18) continue;
				if(ds[e.to]>ds[e.from]+e.cost){
					ds[e.to]=ds[e.from]+e.cost;
					update=1;
				}
			}
			if(!update)break;
			if(i==n-1){
				neg_loop=1;
				return 1e18;
			}
		}
		neg_loop=0;
		return ds[to];
	}
};

int main(){
	int n,m,p; cin >> n >> m >> p;
	BellmanFord<int> G(n);
	for(int i=0;i<m;i++){
		int a,b,c; cin >> a >> b >> c;
		a--; b--;
		G.add_edge(a,b,p-c);
	}
	int neg_loop;
	int res=G.build(0,n-1,neg_loop);
	if(neg_loop){
		cout << -1 << endl;
		return 0;
	}
	else{
		cout << max((ll)0,(ll)-res) << endl;
		return 0;
	}
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N, 0);

  for(int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  
  sort(vec.begin(), vec.end());
  
  int count = 0, prev = 0;
  
  for(int j = 0; j < N; j++) {
    if(prev != vec[j]) {
      count ++;
    } 
    prev = vec[j];
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;

int N, M;
vector<bool> issafe; // issafe[v] := v が壊れていないかどうか

int main(){
  int n, m; cin >> n >> m;
  issafe.assign(n+1, true);
  int a;
  for(int i=0; i<m; i++){
    cin >> a;
    issafe[a] = false;
  }
  
  vector<int> dp(n+1, 0);
  dp[0] = 1;
  if(issafe[1]) dp[1] = 1;
  for(int i=2; i<=n; i++){
    if(issafe[i-1]) dp[i] += dp[i-1];
    if(issafe[i-2]) dp[i] += dp[i-2]; 
    dp[i] %= MOD;
    //cout << dp[i] << endl;
   
  }
  
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
 
int main(void) {
  char S[1024];int q,Q;
  scanf("%s\n",S);
  scanf("%d\n",&Q);
  for (q=0;q<Q;q++) {
    char C[1024]; int c,B,E;
    scanf("%s",C);
    scanf("%d %d",&B,&E);
    if (!strcmp(C,"replace")) {
      scanf("%s",C);
      memcpy(S+B,C,E-B+1);
    }
    else if (!strcmp(C,"reverse")) {
      strncpy(C,S+B,E-B+1);
      for(c=E;c>=B;c--)
        S[c]=C[E-c];
    }
    else if (!strcmp(C,"print")) {
      strncpy(C,S+B,E-B+1);
      C[E-B+1]=0;
      printf("%s\n",C);
    }
  }
  return 0;
}

Measured memory_bytes: 620
n, a, b = map(int, input().split())
mod = 10**9+7

def cmb2(n, r, mod):
    res = 1
    temp = 1
    for k in range(1, r+1):
        res *= (n-k+1)
        temp *= k
        res %= mod
        temp %= mod
    res *= pow(temp,(mod-2),mod)
    res %= mod
    return res

def power(a, n, mod):
    bi=str(format(n,"b")) #2進数
    res=1
    for i in range(len(bi)):
        res=(res*res) %mod
        if bi[i]=="1":
            res=(res*a) %mod
    return res

ans = power(2, n, mod) - cmb2(n, a, mod) - cmb2(n, b, mod) -1
ans %= mod
print(ans)


Measured memory_bytes: 9240
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

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


Measured memory_bytes: 3116