akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

template<class T>
void outvo(vector<T> v) {
  if (v.size() == 0) return;
  cout << v[0];
  for (int i = 1; i < v.size(); i++)
    cout << " " << v[i];
  cout << endl;
}

void dfs(ll n, vector<ll> ans) {
  // debug2(n, ans.size());

  if (n == 0) {
    outvo(ans);
    return;
  }

  for (int i = n; i >= 1; i--) {
    // debug3(n, i, ans.size());
    ll len = ans.size();
    if (len == 0 || (len > 0 && i <= ans[len-1])) {
      ans.push_back(i);
      dfs(n-i, ans);
      ans.pop_back();
    }
  }
}

void solve() {
  while (true) {
    ll n; cin >> n;
    if (n == 0) break;
    dfs(n, vector<ll>{});
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(){
    int n; cin>>n;
    for(int k=1; ; k++){
        if(k*(k-1)/2>n){
            cout<<"No"<<endl;
            return 0;
        }
        if(k*(k-1)/2==n){
            cout<<"Yes"<<endl<<k<<endl;
            int ans[k][k-1];
            int cnt=1;
            for(int i=0; i<k; i++){
                for(int j=i; j<k-1; j++){
                    ans[i][j]=ans[j+1][i]=cnt;
                    cnt++;
                }
            }
            rep(i,k){
                cout<<k-1;
                rep(j,k-1){
                    cout<<' '<<ans[i][j];
                }
                cout<<endl;
            }
            return 0;
        }
    }
}

Measured memory_bytes: 2944
n = int(input())
p = list(map(int, input().split()))
ans = 0
for i in range(1, n-1):
    min_p = min(p[i-1], p[i+1])
    max_p = max(p[i-1], p[i+1])
    if min_p < p[i] < max_p:
        ans += 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;

    if(s == u) a--;
    if(t == u) b--;
    cout << a << " " << b;
    return 0;
}

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

using namespace std;

const int maxn = 200010;

int n,p[maxn],res=0;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++) {
        int x;
        cin>>x;
        p[x] = i;
    }
    //for (int i=1;i<=n;i++) cout<<p[i]<<endl;
    int now=1;res = 1;
    for (int i=1;i<n;i++) {
        if (p[i] < p[i+1]) now++;
        else now=1;
        res = max(res,now);
    }
    cout<<n-res<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int A[N];
    rep(i,N){
        cin>>A[i];
    }
    int l[N];
    int r[N];
    l[0]=A[0];
    r[N-1]=A[N-1];
    for(int i=1;i<N;i++){
        l[i]=__gcd(A[i],l[i-1]);
    }
    for(int i=N-2;i>=0;i--){
        r[i]=__gcd(r[i+1],A[i]);
    }

    int ans=0;
    rep(i,N-2){
        ans=max(ans,__gcd(l[i],r[i+2]));
    }
    ans=max(ans,r[1]);
    ans=max(ans,l[N-2]);
    cout << ans << endl;


    



}


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

const int MAX_N = 15, MAX_A = 14;

int N;                // 人数
int A[MAX_N];         // A[i] = (人iの証言の数)
int x[MAX_N][MAX_A];  // x[i][j] = (人iのj個目の証言の相手)
int y[MAX_N][MAX_A];  // y[i][j] = (人x[i][j]は, 1->honest, 0->unkind)
int V[MAX_N];         // V[i] = (人iがhonestかunkindか)
int ans;

void input() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        for (int j = 0; j < A[i]; ++j) {
            cin >> x[i][j] >> y[i][j];
            --x[i][j];
        }
    }
}

void check(){
    int n_honest = 0;
    for (int i = 0; i < N; ++i) {
        if (V[i] == 1) {
            ++n_honest;
            for (int j = 0; j < A[i]; ++j) {
                if (V[x[i][j]] != y[i][j]) return;
            }
        }
    }
    ans = max(ans, n_honest);
}


void dfs(int dep) {
    if (dep == N) check();
    else {
        dfs(dep + 1);
        V[dep] = 1;
        dfs(dep + 1);
        V[dep] = 0;
    }
}

int main() {
    input();
    dfs(0);
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}
ll prime(ll x) {
	ll i;
	if (x < 2)return 0;
	else if (x == 2) return 1;
	if (x % 2 == 0) return 0;
	for (i = 3; i*i <= x; i += 2) {
		if (x%i == 0) return 0;
	}
	return 1;
}

int main() {
  	ll N,K;
  	cin>>N>>K;
	if (N%K == 0)
		cout << 0 << endl;
	else
		cout << 1 << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int m, f, r;
        while(true){
            m = scan.nextInt();
            f = scan.nextInt();
            r = scan.nextInt();
            if(m < 0 && f < 0 && r < 0) break;
            System.out.println(calcGrade(m, f, r));
        }
    }
    public static char calcGrade(int m, int f, int r){
        if(m < 0 || f < 0) return 'F';
        if(m + f >= 80){ return 'A'; }
        else if(m + f >= 65){ return 'B'; }
        else if(m + f >= 50){ return 'C'; }
        else if(m + f >= 30){
            if(r >= 50){ return 'C'; }else{ return 'D'; }
        }
        return 'F';
    }
}


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

using namespace std;





int main(){


	int n; cin >> n;

	int cnt = 0;

	for(int i = 1; i <= n; i++){
		if(i % 2) cnt++;
	}
	

	cout << fixed << setprecision(10) << 1.0 * cnt / n << endl;




	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cassert>
#define F first
#define MAX 1000
#define S second
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef pair<int,int> P;
struct Pox
{
  int x,y,dir;
  Pox(int x=-1,int y=-1,int dir=-1):x(x),y(y),dir(dir){}
};
int dx[] = {+0,+1,+0,-1};//N,E,S,W
int dy[] = {-1,+0,+1,+0};
char G[MAX][MAX];
int visited[MAX][MAX][4];
P src;

int getDir(char c)
{
  switch(c)
    {
    case 'N':
      return 0;
    case 'E':
      return 1;
    case 'S':
      return 2;
    case 'W':
      return 3;
    }
}

char toChar(int c)
{
  switch(c)
    {
    case 0:
      return 'N';
    case 1:
      return 'E';
    case 2:
      return 'S';
    case 3:
      return 'W';
    }
}

int main()
{
  int H,W;
  long long L;
  while(cin >> H >> W >> L,H|W|L)
    {
      int dir;
      rep(i,H)
	{
	  string line;
	  cin >> line;
	  rep(j,line.size())
	    {
	      assert(j < W);
	      G[i][j] = line[j];
	      if(!(G[i][j] == '.' || G[i][j] == '#'))src = P(j,i),dir = getDir(G[i][j]),G[i][j] = '.';
	      
	      rep(k,4)visited[i][j][k] = -1;
	    }
	}     

      long long phase = 0;
      vector<Pox> path;
      path.push_back(Pox(src.F,src.S,dir));

      while(true)
	{
	  if(phase >= L)
	    {
	      cout << src.S+1 << " " << src.F+1 << " " << toChar(dir) << endl;  
	      break;
	    }
	  if(visited[src.S][src.F][dir] != -1)
	    { 
	      L -= phase;
	      L %= (phase-visited[src.S][src.F][dir]);
	      L += (phase-visited[src.S][src.F][dir]);
	      for(int i=0;i<L;i++)
		{
		  src.F += dx[dir];
		  src.S += dy[dir];
		  
		  if(!(0 <= src.F && src.F < W && 0 <= src.S && src.S < H))
		    {
		      src.F -= dx[dir];
		      src.S -= dy[dir];
		      dir = (dir+1)%4;
		      i--;
		      continue;
		    }
		  else if(G[src.S][src.F] == '#')
		    {
		      src.F -= dx[dir];
		      src.S -= dy[dir];
		      dir = (dir+1)%4;
		      i--;
		      continue;
		    }	
		}
	   
	      cout << src.S+1 << " " << src.F+1 << " " << toChar(dir) << endl;
	      
	      break;
	    }     
 
	  visited[src.S][src.F][dir] = phase;
	  src.F += dx[dir];
	  src.S += dy[dir];
	  if(!(0 <= src.F && src.F < W && 0 <= src.S && src.S < H))
	    {
	      src.F -= dx[dir];
	      src.S -= dy[dir];
	      dir = (dir+1)%4;
	      continue;
	    }
	  else if(G[src.S][src.F] == '#')
	    {
	      src.F -= dx[dir];
	      src.S -= dy[dir];
	      dir = (dir+1)%4;
	      continue;
	    }
 
	  path.push_back(Pox(src.F,src.S,dir));
	  phase++;
	}
      

    }
  return 0;
}

Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
    int p[100010],q[100010],s[300010];
    int x,y,a,b,c;
    long long ans;
void qs(int f[],int l,int r)
{
    int i=l,j=r;
    int t;
    int x=f[(l+r)/2];
    do
    {
        while (f[i]>x) i++;
        while (f[j]<x) j--;
        if (i<=j)
        {
            t=f[i];
            f[i]=f[j];
            f[j]=t;
            i++;
            j--;
        }
    }while (i<=j);
    if (l<j) qs(f,l,j);
    if (i<r) qs(f,i,r);
}
int main()
{
    scanf("%d%d%d%d%d",&x,&y,&a,&b,&c);
    for (int i=1;i<=a;i++) scanf("%d",&p[i]);
    qs(p,1,a);
    for (int i=1;i<=x;i++) s[i]=p[i];
    for (int i=1;i<=b;i++) scanf("%d",&q[i]);
    qs(q,1,b);
    for (int i=1;i<=y;i++) s[x+i]=q[i];
    for (int i=1;i<=c;i++) scanf("%d",&s[x+y+i]);
    qs(s,1,x+y+c);
    ans=0;
    for (int i=1;i<=x+y;i++)
        ans+=s[i];
    cout << ans << endl;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
using namespace std;
 
const int MOD=1e9+7;
const double PI=3.14159265359;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    vector<int> v(n);
    for(int&i:v)cin>>i;
    int cur=v[0], ct=1, ans=0;
    
    for(int i=1; i<n; i++){
        if(v[i]==cur){
            ct++;
        }
        else{
            ans+=ct/2;
            cur=v[i];
            ct=1;
        }
    }
    cout<<ans+ct/2;
    
    
    return 0;
}


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

int main(){
	int n,m ;
	cin >> n >> m ;
	vector<bool> ok(n,false) ;
	for(int i=0;i<m;i++){
		int a,b ;
		cin >> a >> b ;
		a-- ; b-- ;
		ok.at(a) = !ok.at(a) ;
		ok.at(b) = !ok.at(b) ;
	}
	bool ans = false ;
	for(int i=0;i<n;i++) if(ok.at(i)) ans = true ;
	cout << (ans?"NO":"YES") << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MAXN = 100;
const int MAXK = 100000;
using namespace std;

int n, k, a[MAXN + 5];
bool dp[MAXK + 5];

void init() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
}

int main() {
#ifdef forever23
  freopen("test.in", "r", stdin);
#endif
  init();

  dp[0] = false;
  for (int j = 1; j <= k; ++j) {
    dp[j] = false;
    for (int i = 1; i <= n; ++i) {
      dp[j] |= a[i] <= j && !dp[j - a[i]];
    }
  }

  if (dp[k]) {
    puts("First");
  } else {
    puts("Second");
  }
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int n, * list, * list1;
	list = new int[200000];
	list1 = new  int[200000];
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		cin >> list[i];
	}
	for ( int i = 1; i < n; i++)
	{
		list1[i] = 0;
	}
	for (int  i = 1; i < n; i++)
	{
		list1[list[i]]++;
	}

	for (int i = 1; i < n; i++)
	{
		cout << list1[i] << endl;
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 4756
#include <string>
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>

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

int main(int argc, char const *argv[])
{
    //ポイントはdoubleは15桁までしか表現できないので，15桁×3桁は無理
    //なので，小数を整数にするためにかけて，その後割ればよい
    ull A;
    double B;
    cin >> A >> B;
    ull B100 = (ull)(B*100+0.01);
    cout << A*B100/100;

    return 0;
}


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

typedef long long ll;

#define pb push_back
#define ft first
#define sd second
#define all(x) begin((x)), end((x))
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define isz(x) (int)(x).size()
/* <-------------------> */

const int MAX = 2e5 + 7;
ll a[MAX];
int n;

ll f(ll b) {
    ll ans = 0;
    for (int i = 1; i <= n; ++i) {
        ans += abs(a[i] - b - i);
    }
    return ans;
}

void solve() {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    ll l =  -(ll)2e9, r = (ll)2e9;
    while (r - l > 200) {
        ll m1 = l + (r - l) / 3, m2 = l + 2 * (r - l) / 3;
        if (f(m1) > f(m2)) {
            l = m1;
        } else {
            r = m2;
        }
    }
    ll ans = (ll)1e16;
    for (ll i = l; i <= r; ++i) {
        ans = min(ans, f(i));
    }
    cout << ans;
}

/* <-------------------> */
// #define LOCAL
int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

ll pal(ll s){
	return s*(s-1)/2;
}
int main(){
	IOS;
	
	ll n,m;cin>>n>>m;
	ll ans = pal(n)+pal(m);
	cout<<ans;
	return 0;
}



Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.OptionalInt;
import java.util.regex.Pattern;
import java.util.stream.Stream;

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

    new Main().run();
  }

  public void run() {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      String line = br.readLine();
      final Pattern delim = Pattern.compile("\\s");
      int[] arrayS = delim
        .splitAsStream(line)
        .mapToInt(Integer::parseInt)
        .toArray();

      OptionalInt max =
        Arrays.stream(arrayS).max();

      dispIntArray( countingSort(arrayS, max.getAsInt()) );
    }
    catch ( IOException e ) {
      System.out.println("IOException!");
    }

  }

  public int[] countingSort(int[] a, int k) {

    int   aLength = a.length;
    int[] result  = new int[aLength];
    int[] counter = new int[k+1];

    for (int var : a) {
      counter[var]++;
    }

    for (int i=1, max=k+1; i < max; i++) {
      counter[i] += counter[i-1];
    }

    for (int i=aLength-1, val=0; i>=0; i--) {
      val = a[i];
      result[counter[val]-1] = val;
      counter[val]--;
    }

    return result;
  }

  public void dispIntArray(int[] target) {
    StringBuilder s = new StringBuilder();

    for (int i : target) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}


Measured memory_bytes: 179892
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin >> n;
  for(int i=0;i<=n;i+=4){
    for(int j=0;j<=n;j+=7){
      if(i+j==n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n, k, c = gets.chomp.split.map(&:to_i)
s = gets.chomp

ldp = []
rdp = []

i = 0
while i < n
  if s[i] == "o"
    ldp << i + 1
    i += c + 1
  else
    i += 1
  end
end

i = n - 1
while i >= 0
  if s[i] == "o"
    rdp << i + 1
    i -= c + 1
  else
    i -= 1
  end
end

ldp[0..(k - 1)].zip(rdp[0..(k - 1)].reverse).each do |i, j|
  puts i if i == j
end

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

vector <int> G[100005];
int distA[100005], distT[100005];
bool odw[100005];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	int T, A;
	cin >> T >> A;
	for (int i = 1; i <= n-1; ++i){
		int a, b;
		cin >> a >> b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	queue <pair<int,int>> Q;
	Q.push({T, 0});

	while (! Q.empty()){
		int v = Q.front().first;
		int d = Q.front().second;
		Q.pop();
		if (odw[v])
			continue;
		odw[v] = true;
		distT[v] = d;
		for (auto u: G[v]){
			if (! odw[u])
				Q.push({u, d+1});
		}
	}

	for (int i = 1; i <= n; ++i)
		odw[i] = false;

	Q.push({A, 0});

	while (! Q.empty()){
		int v = Q.front().first;
		int d = Q.front().second;
		Q.pop();
		if (odw[v])
			continue;
		odw[v] = true;
		distA[v] = d;
		for (auto u: G[v]){
			if (! odw[u])
				Q.push({u, d+1});
		}
	}
	int wynik = -1;

	for (int i = 1; i <= n; ++i){
		if (distT[i] < distA[i]){
			wynik = max(wynik, distA[i]-1);
		}
	}
	cout << wynik << "\n";
}

Measured memory_bytes: 6784
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		Random r = new Random();
		
		long startMilli = System.currentTimeMillis();
		
		final int N = 26;

		int D = sc.nextInt();
		int[] c = new int[N];
		for(int i=0; i<N; i++)
			c[i] = sc.nextInt();
		
		int[][] s = new int[D][N];
		for(int i=0; i<D; i++)
			for(int j=0; j<N; j++)
				s[i][j] = sc.nextInt();
		
		int[] t = new int[D];
//		for(int i=0; i<D; i++)
//			t[i] = r.nextInt(N);

		int[] last = new int[N];
		for(int i=0; i<D; i++) {
			int bestIndex = -1;
			int bestScore = 0;
			for(int j=0; j<N; j++) {
				int score = s[i][j] + c[j]*(i+1-last[j]);
				if(bestIndex < 0 || score > bestScore) {
					bestIndex = j;
					bestScore = score;
				}
			}
			t[i] = bestIndex;
			last[bestIndex]=i+1;
		}
		
//		int score = 0;
//		int[] last = new int[N];
//		for(int i=0; i<D; i++) {
//			score += s[i][t[i]];
//			last[t[i]]=i+1;
//			for(int j=0; j<N; j++)
//				score -= c[j]*(i+1-last[j]);
//		}
		
		long currentMilli = System.currentTimeMillis();

		while(currentMilli - startMilli < 1850) {
			double p = Math.exp(-(currentMilli - startMilli)/1850*5);
			for(int i=0; i<1000; i++) {
				int d = r.nextInt(D)+1;
				int to = r.nextInt(N);
				int from = t[d-1];
				if(from==to)
					continue;
	
				int scoreDiff = s[d-1][to] + c[to]*(d-getIndex(t, to, d, false))*(getIndex(t, to, d, true)-d);
				scoreDiff -= s[d-1][from] + c[from]*(d-getIndex(t, from, d, false))*(getIndex(t, from, d, true)-d);
				if(scoreDiff>0 || p > r.nextDouble())
					t[d-1] = to;
			}
			currentMilli = System.currentTimeMillis();
		}
		for(int i=0; i<D; i++)
			pw.println(t[i]+1);

		sc.close();
		pw.close();
	}
	
	static int getIndex(int[] t, int type, int base, boolean isForward) {
		int ans = base;
		int diff = isForward ? 1 : -1;
		ans += diff;
		while(1 <= ans && ans <= t.length) {
			if(t[ans-1]==type)
				return ans;
			ans += diff;
		}
		return ans;
	}
}


Measured memory_bytes: 38060
#include <stdio.h>
#define n_max 100001
int Depth(int);
int Height(int);

int n, parent[n_max], sibling[n_max], degree[n_max];
 
int main() {
  int i, j, id, left, right, dep;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }
  
  for(i=0;i<n;i++) {
    
    scanf("%d %d %d",&id,&left,&right);
    
    if(left != -1) {
      parent[left] = id;
      sibling[left] = right;
      degree[id]++;
    }
    
    if(right != -1) {
      parent[right] = id;
      sibling[right] = left;
      degree[id]++;
    }
  }
 
  for(i = 0; i < n; ++i) {
    dep = Depth(i);
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, parent[i], sibling[i], degree[i], dep, Height(i));
    
    if(dep==0) printf("root\n");

    else if(degree[i]==0) printf("leaf\n");

    else printf("internal node\n");
  }
  return 0;
}



int Depth(int i){
  if(parent[i]==-1) return 0;
  return Depth(parent[i])+1;
}


int Height(int i){
  int j, h, alo;
  
  h = 0;
  for(j=0;j<n;j++) {
    if(parent[j] == i) {
      alo = Height(j) + 1;
      if(alo>h) h=alo;
    }
  }
  return h;
}



Measured memory_bytes: 2108
N = int(input())
a = [min(int(i) // 400, 8) for i in input().split()]

n, c = 0, 0
ranks = set()
for a_i in a:
    if a_i == 8:
        n += 1
    else:
        ranks.add(a_i)

min_v = len(ranks)
max_v = len(ranks)
if n > 0:
    min_v = max(1, len(ranks))
    max_v = max_v + n

print(min_v, max_v)


Measured memory_bytes: 38256
n, m = map(int, input().split())
k = []
g = []
INF = float("inf")
for i in range(m):
    k.append(list(map(int, input().split()))[0])
    # g: indexの鍵で開けられる箱をbit列として表現
    g.append(sum(map(lambda x: 2**(int(x)-1), input().split())))

dp = [INF] * (2**n)
dp[0] = 0

for i in range(m):
    for j in range(2**n):
        dp[g[i]|j] = min(dp[g[i]|j], dp[j] + k[i])
#print(dp)
print(-1 if dp[-1] == INF else dp[-1])


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int R;
    cin >> R;

    if(R<1200){
        p("ABC");
    }else if(R<2800){
        p("ARC");
    }else{
        p("AGC");
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 10000000007;

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

int main() {
  int N;
  cin >> N;
  int A;
  cin >> A;
  cout << (N*N - A) << endl;
}


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

int main(){
  int n; cin >> n;
  string s; cin >> s;
  rep(i,s.size()){
    int x=s.at(i)-'A';
    x=(x+n)%26;
    s.at(i)=x+'A';
  }
  cout<<s<<endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

macro_rules! read {
    ([$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ([$t:ident]) =>
        (rl().split_whitespace().map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    (_, [$t:ident] ; $n:expr) =>
        ((0..$n).map(|_| read!(_, [$t])).collect::<Vec<_>>());
    (_, [$t:ident]) =>
        (rl().split_whitespace().skip(1).map(|w| read_type!(w, $t)).collect::<Vec<_>>());
    ($($t:ident),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ($t:ident) => (read_type!(rl(), $t));
    ($($t:ident),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(read_type!(w.next().unwrap(), $t)),*)
    }};
}

macro_rules! read_type {
    ($s:expr, chars) => {
        $s.chars().collect::<Vec<char>>()
    };
    ($s:expr, usize1) => {
        read_type!($s, usize) - 1
    };
    ($s:expr, $t:ty) => {
        $s.parse::<$t>().unwrap()
    };
}

fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

////////////////////////////////////////////////////////////////////////////////

fn main() {
    let (a, b, c) = read!(i32, i32, i32);

    let ans = min(min((a + b), (b + c)), (c + a));

    println!("{}", ans);
}


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

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

ll solve(const string S, const ll K) {
    vector<ll> succs;

    char prev = S[0];
    ll count = 1;
    for (int i = 1; i < (int) S.size(); i++) {
        if (S[i] == prev) {
            count++;
        } else {
            succs.push_back(count);
            count = 1;
            prev = S[i];
        }
    }
    succs.push_back(count);

    ll ans = 0;
    if ((int) succs.size() == 1) {
        ans = (succs[0] * K) / 2;
    } else {
        for (int i = 0; i < (int) succs.size(); i++) {
            ans += (succs[i] / 2) * K;
        }
        if (S[0] == S[(int) S.size() - 1]) {
            ans -= (succs[0] / 2) * (K - 1);
            ans -= (succs[(int) succs.size() - 1] / 2) * (K - 1);
            ans += ((succs[0] + succs[(int) succs.size() - 1]) / 2) * (K - 1);
        }
    }

    return ans;
}

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

    ll K;
    cin >> K;

    cout << solve(S, K) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include<iomanip>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int* array;
    array = new int[N];
    int* answer;
    answer = new int[N];
    for (int i = 0; i < N; i++)
    {
        cin >> array[i];
    }
    int num = 0;
    for (int i = 1; i < N; i++)
    {
        num = num+pow(-1,i+1)*array[i];
    }
    answer[0] = (array[0]-num);
    for (int i = 0; i < N; i++)
    {
        answer[i+1] = 2*array[i]-answer[i];
    }
    for (int i = 0; i < N-1; i++)
    {
        cout << answer[i] << " ";
    }   
    cout << answer[N-1] << endl;
    
}

Measured memory_bytes: 2048
import scala.io.StdIn._

object Main extends App {
  val n         = readInt()
  val Seq(t, a) = readLine().split(" ").map(_.toInt).toSeq
  val h         = readLine().split(" ").map(_.toInt).toSeq

  println(h.zipWithIndex.map { case (i, j) => ((t - i * 0.006 - a).abs, j) }.minBy(_._1)._2 + 1)
}


Measured memory_bytes: 58528
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define pb(a) push_back(a)

typedef long long ll;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//const int dy[] = { 0, 0, 1, -1 };
//const int dx[] = { 1, -1, 0, 0 };
const int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
ll gcd(ll a, ll b);
ll lcm(ll x, ll y);

vector<ll> a;

int main()
{
	ll n;
	ll m;
	cin >> n;
	
	m = n % 10;
	if (m == 2 || m == 4 || m == 5 || m == 7 || m == 9) {
		cout << "hon" << endl;
	}
	else if (m == 0 || m == 1 || m == 6 || m == 8) {
		cout << "pon" << endl;
	}
	else if (m == 3) {
		cout << "bon" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

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

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];

    bool ok = true;
    rep(i,N) {
        if (A[i]%2==0) {
            if (A[i]%3!=0 && A[i]%5!=0) ok = false;
        }
    }

    cout << (ok ? "APPROVED" : "DENIED") << ln;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

ll N,K;
vector<int> A;

bool f(int x) {
    if (x < 0) return false;
    if (x >= N) return true;
    if (A[x] >= K) return true;
    bitset<5001> dp;
    dp[0] = 1;
    rep(i,N) {
        if (i == x) continue;
        if (A[i] >= K) continue;
        dp |= (dp<<A[i]);
    }
    for (int i = K - A[x]; i < K; i++) {
        if (dp.test(i)) return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N >> K;
    A.resize(N);
    rep(i,N) cin >> A[i];

    sort(all(A));
    int left = -1, right = N;
    while (right - left > 1) {
        int mid = (left+right)/2;
        if (f(mid)) right = mid;
        else left = mid;
    }

    cout << right << endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut a = a;
    let mut ok = true;
    for i in (0..n - 1).rev() {
        if a[i] > a[i + 1] {
            a[i] -= 1;
        }
        if a[i] > a[i + 1] {
            ok = false;
        }
    }
    puts!("{}\n", if ok { "Yes" } else { "No" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
// 最小公倍数＜ LCM, lcm ＞
//二つの整数 a, b, について、
// gcd(a, b) = g, lcm(a, b) = l とした時
// a * b = g * l

//  l = a * b / g

long long GCD(long long a, long long b){
    while(b != 0){
        long long r = a % b;
        a = b;
        b = r;
    }
    return a;
}

long long LCM(long long a, long long b){
    return a / GCD(a,b) * b;
}

int main(){

    int n, i;
    cin >> n;

    vector<int> a(n);
    for(i=0; i<n; i++){
        cin >> a.at(i);
    }
    
    int ans = 1;

    for(i = 0; i < n; i++){
        ans = LCM(a.at(i), ans);
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <set>

int main()
{
    int A, B;
    std::cin >> A >> B;

    std::set<int> ans{1,2,3};
    ans.erase(A);
    ans.erase(B);
    std::cout << *(ans.begin()) << std::endl;
    return 0;
}

Measured memory_bytes: 256
//mangesh2102000

#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long int 
#define ld long double
#define pb push_back
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define F first
#define S second
#define mod 1000000007

int h,w;
char grid[1005][1005];
int ans[1005][1005];

int paths(int i,int j)
{
    if(ans[i][j]!=-1)
        return ans[i][j];

    if(i==1 && j==1)
        return ans[i][j]=1;

    if(i==1 && j==2)
    {
        if(grid[i][j]=='#')
        {
            return ans[i][j]=0;
        }
        else
        {
            return ans[i][j]=1;
        }
    }

    if(i==2 && j==1)
    {
        if(grid[i][j]=='#')
        {
            return ans[i][j]=0;
        }
        else
        {
            return ans[i][j]=1;
        }
    }

    if(grid[i-1][j]=='.' && grid[i][j-1]=='.')
    {
        return ans[i][j] = (paths(i-1,j) + paths(i,j-1)) % mod;
    }
    else if(grid[i-1][j]=='.')
    {
        return ans[i][j] = (paths(i-1,j)) % mod;
    }
    else if(grid[i][j-1]=='.')
    {
        return ans[i][j] = (paths(i,j-1)) % mod;
    }
    else
    {
        return ans[i][j] = 0;
    }
}

void solve(int t)
{
    cin >> h >> w;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin >> grid[i][j];
            ans[i][j] = -1;
        }
    }

    int ans = paths(h,w);
    ans %= mod;

    cout << ans;
}   


int32_t main()
{
    IOS;
    int t;
    t=1;
    for(int i=1;i<=t;i++)
    {
        solve(i);
    }

    return 0;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200 + 10, M = 100000 + 10;
const int mod = 1e9 + 7;
void add(ll &x,ll y){
    x += y;
    if(x>=mod) x -= mod;
}
ll qpow(ll n,ll k){
    ll res = 1;
    while(k){
        if(k&1) res = res * n % mod;
        n = n * n % mod;
        k >>= 1;
    }
    return res;
}
ll fac[N],inv[N];
ll push(int x,int y){
    return fac[x+y] * inv[x] % mod;
}
int a[N],n;
ll f[N][M];
ll calc(int i,int j){
    if(j<a[n]){
//        cout<<i<<' '<<j<<' '<<fac[n-i]*j<<endl;
        return fac[n-i] * j % mod;
    }
    ll &ans = f[i][j];
    if(ans!=-1) return f[i][j];
    ans = 0;
    int x = 0, y = 0;
    for(int k=i+1;k<=n;k++){
        if(a[k]<=j){
//            cout<<i<<','<<j<<','<<k<<','<<calc(k,j%a[k])*push(n-k,y)%mod*push(n-i-x,x)%mod<<endl;
            add(ans,calc(k,j%a[k])*push(n-k,y)%mod*push(n-i-x,x)%mod);
        }
        if(a[k]<=j) y++;
        else x++;
    }
//    cout<<i<<' '<<j<<' '<<ans<<endl;
    return ans;
}
int main(){
    fac[0] = 1; for(int i=1;i<N;i++) fac[i] = fac[i-1] * i % mod;
    inv[N-1] = qpow(fac[N-1],mod-2);
    for(int i=N-2;i>=0;i--) inv[i] = inv[i+1] * (i + 1) % mod;
    ios::sync_with_stdio(0);
    int x; cin>>n>>x;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n,greater<int>());
    memset(f,-1,sizeof(f));
    cout<<calc(0,x)<<endl;
}


Measured memory_bytes: 164352
#include<bits/stdc++.h>
using namespace std;
int a[200];
int main()
{
	int n,s=0;
	cin>>n;
	for(int i=1;i<=2*n;i++)
		cin>>a[i];
	sort(a+1,a+1+2*n);
	for(int i=1;i<=2*n;i+=2)
	{
		s+=a[i];
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<vector>

#define PI 3.141592654
#define RADIUS 1.0
#define DIAMETER 2*RADIUS
#define EPS 1e-10

struct POINT{
	double x;
	double y;

	POINT& operator += ( const POINT& p )
	{
		x += p.x;
		y += p.y;
		return *this;
	}
	POINT& operator -= ( const POINT& p )
	{
		x -= p.x;
		y -= p.y;
		return *this;
	}
	POINT& operator *= ( double factor )
	{
		x *= factor;
		y *= factor;
		return *this;
	}
	POINT& operator /= ( double factor )
	{
		x /= factor;
		y /= factor;
		return *this;
	}

	double Norm() const{ return sqrt( pow( x , 2 ) + pow( y , 2 ) ); }
};

POINT operator + ( const POINT& a , const POINT& b )
{
	POINT p(a);
	p += b;
	return p;
}

POINT operator - ( const POINT& a , const POINT& b )
{
	POINT p(a);
	p -= b;
	return p;
}

POINT operator * ( const POINT& a , double factor )
{
	POINT p(a);
	p *= factor;
	return p;
}

POINT operator / ( const POINT& a , double factor )
{
	POINT p(a);
	p /= factor;
	return p;
}

typedef POINT VECTOR;

std::istream& operator >> ( std::istream& s , POINT& p )
{
	char c;
	return s >> p.x >> c >> p.y;
}

double getDistance( const POINT& a , const POINT& b )
{
	return sqrt( pow( a.x - b.x , 2 ) + pow( a.y - b.y , 2 ) );
}

void getCrossPoint( const POINT& a , const POINT& b , POINT *p1 , POINT *p2 )
{
	POINT mid = ( a + b ) / 2;
	if( fabs(getDistance( a , b ) - DIAMETER) < EPS ){
		*p1 = mid;
		*p2 = mid;
		return;
	}
	else{
		VECTOR ab = b - a;
		double theta = atan( ab.y / ab.x );
		double h = sqrt( pow( RADIUS , 2 ) - pow( ab.Norm()/2 , 2) );
		p1->x = mid.x + h * cos( theta + PI/2 );
		p1->y = mid.y + h * sin( theta + PI/2 );
		p2->x = mid.x + h * cos( theta - PI/2 );
		p2->y = mid.y + h * sin( theta - PI/2 );
		return;
	}
}

int getMax( int a , int b )
{
	return a > b ? a : b;
}

int getOverlapMax( std::vector<POINT> o , int n )
{
	int overlap = 1;
	for( int i = 0 ; i < n-1 ; i++ ){
		for( int j = i+1 ; j < n ; j++ ){
			int cnt1 , cnt2;
			if( getDistance( o[i] , o[j] ) <= DIAMETER + EPS ){
				POINT p1, p2;
				getCrossPoint( o[i] , o[j] , &p1 , &p2 );
				cnt1 = 2;
				cnt2 = 2;
				for( int k = 0 ; k < n ; k++ ){
					if( k == i || k == j ){
						continue;
					}
					if( getDistance( o[k] , p1 ) <= RADIUS + EPS ){
						cnt1++;
					}
					if( getDistance( o[k] , p2 ) <= RADIUS + EPS ){
						cnt2++;
					}
				}
			}
			else{
				cnt1 = 0;
				cnt2 = 0;
			}
			if( overlap < getMax( cnt1 , cnt2 ) ){
				overlap = getMax( cnt1 , cnt2 );
			}
		}
	}

	return overlap;
}

int main(void)
{
	while(1){
		int n;
		std::cin >> n;
		if( n == 0 ){
			break;
		}
		std::vector<POINT> o;
		for( int i = 0 ; i < n ; i++ ){
			POINT p;
			std::cin >> p;
			o.push_back(p);
		}

		std::cout << getOverlapMax( o , n ) << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1340
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long n,arr[200007],k;
vector<pair<long long,int>>z;
long long bigmod(long long x,long long y){
    if(x==0) return 1ll;
    if(x==1) return y;
    long long xxx=bigmod(x/2,y);
    xxx=(xxx*xxx)%mod;
    if(x%2) xxx=(xxx*y)%mod;
    return xxx;
}
int main()
{
    cin>>n>>k;
    bool x=false;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
        if(!arr[i]) x=true;
        if(arr[i]>=0)
            z.push_back({arr[i],1});
        else z.push_back({-arr[i],0});

    }
    sort(z.begin(),z.end(),greater<pair<long long ,int> >());

    int cnt=0;
    long long ans=1,last=0,last1=0;
    for(int i=0;i<k;i++){
        ans*=(z[i].first);
        ans%=mod;
        cnt+=(z[i].second==0);
        if(z[i].second) last =z[i].first;
        else last1=z[i].first;
    }
    if(cnt%2){
        long long l=0,r=0;
        for(int i=k;i<n;i++){
            if(z[i].second) l=max(l,z[i].first);
            else r=max(r,z[i].first);
        }
        if(l*last>=r*last1&&l*last!=0){
            ans=(ans*bigmod(mod-2,last1))%mod;
            ans=(ans*l)%mod;
        }
        else if(l*last<r*last1&&(last)){
            ans=(ans*bigmod(mod-2,last))%mod;
            ans=(ans*r)%mod;
        }
        else if(l){
            ans=(ans*bigmod(mod-2,last1))%mod;
            ans=(ans*l)%mod;
        }
        else ans=-ans;
    }

    if(ans<0){
        sort(arr,arr+n);
        for(int i=0;i<n;i++) {
            if(arr[i]<0) arr[i]=-arr[i];
        }
        sort(arr,arr+n);
        ans=1;
        for(int i=0;i<k;i++){
            ans=(ans*arr[i])%mod;
        }
        ans=-ans;
        ans+=mod;
    }

    cout<<(ans)%mod<<endl;

    return 0;
}



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

int main() {
    int n;
    int res = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        res += b - a + 1;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
list = list(map(int, input().split()))
count = 0
for i_1 in range(n-2):
    for i_2 in range(i_1+1,n-1):
        for i_3 in range(i_2+1,n):
            if list[i_1] != list[i_2] and list[i_1] != list[i_3] and list[i_2] != list[i_3]:
                if abs(list[i_2]-list[i_3]) < list[i_1] < list[i_2]+list[i_3]:
                    count += 1
print(count)


Measured memory_bytes: 9188
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int n;
  cin >> n;
  vi cnt(n+1,0);
  REP(x,1,101){
    REP(y,1,101){
      REP(z,1,101){
        int p = x*x + y*y + z*z + x*y + y*z + z*x;
        if(p > n) continue;
        cnt.at(p)++;
      }
    }
  }
  REP(i,1,n+1){
    cout << cnt.at(i) << endl;
  }
}

Measured memory_bytes: 3668
#include <stdio.h>
     
int main(){
    long sum = 0;
    int s;
    scanf("%d", &s);
    
	for(int i = 0; i <= s; i++){
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
    }
    printf("%lld",sum);
    return 0;
}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

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

        System.out.println(solve(a, b) ? "Odd" : "Even");
    }

    private static boolean solve(int a, int b) {
        return a*b%2 != 0;
    }
}

Measured memory_bytes: 21588