akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

static void get_ans(long long *ans, int h[], int n) {
    int i;
    int min_h=INT_MAX;
    int *head, head_idx;

    if ( n == 0 )
        return;

    for ( i=0; i<n; i++ )
        min_h = (h[i]<min_h) ? h[i] : min_h;

    *ans += min_h;

    head = h;
    head_idx = 0;
    for ( i=0; i<n; i++ ) {
        h[i] -= min_h;
        if ( h[i] == 0 ) {
            get_ans(ans, head, i-head_idx);
            head = &h[i+1];
            head_idx = i+1;
        }
    }
    get_ans(ans, head, n-head_idx);
}

int main (void) {
    int i;
    int n;
    int h[100];
    long long ans=0;

    scanf("%d", &n);
    for ( i=0; i<n; i++ )
        scanf("%d", &h[i]);

    get_ans(&ans, h, n);

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


Measured memory_bytes: 128
Q=[]
A=->*x{Q<<[?+,*x]*" "}
C=->*x{Q<<[?<,*x]*" "}

C[3,0,3]
0.upto(30){|i|
 A[3+i,3+i,4+i]
}

def to_b(x,s)
 A[x,3,x]
 31.downto(0){|i|
  A[3+i,s+33,s+32]
  C[s+32,x,s+i]
  A[s+i,2,s+32]
  i.times{A[s+32,s+32,s+32]}
  A[s+32,s+33,s+33]
 }
end

to_b(0,67)
to_b(1,195)

30.times{|i|
 30.times{|j|
  A[67+i,195+j,324]
  C[3,324,325]
  A[326+i+j,325,326+i+j]
 }
}

58.downto(0){|i|
 2.times{A[326+i,327+i,326+i]}
}
A[2,326,2]

puts Q.size,Q

Measured memory_bytes: 14736
import bisect
N = int(input())
A,B = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
ans = N
id = bisect.bisect_right(P,A)
ans = min(ans,id)
prev = id
id = bisect.bisect_right(P,B)
ans = min(ans,id - prev)
ans = min(ans,N - id)
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
int main(void)
{
	int n, m, l;
	int i, j, k;
	int a[100][100] = {0};
	int b[100][100] = {0};
	long long int c[100][100] = {0};
	
	scanf("%d %d %d", &n, &m, &l);
	for (i=0; i<n; i++){
		for (j=0; j<m; j++){
			scanf("%d", &a[i][j]);
		}
	}
	for (i=0; i<m; i++){
		for (j=0; j<l; j++){
			scanf("%d", &b[i][j]);
		}
	}
	for (i=0; i<n; i++){
		for (k=0; k<m; k++){
			for (j=0; j<l; j++){
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	for (i=0; i<n; i++){
		for (j=0; j<l; j++){
			if (j!=0){
				printf(" ");
			}
			printf("%lld", c[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = INT64_MAX;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    ll S;
    cin >> S;
    ll fst = S / 100, snd = S % 100;
    ll ans = 0;
    if(fst == 0 && (snd >= 13 || snd == 0)) {
        out("NA");
        return;
    }
    if(snd == 0 && (fst >= 13 || fst == 0)) {
        out("NA");
        return;
    }
    if(fst >= 13 && snd >= 13) {
        out("NA");
        return;
    }
    if(fst > 0 && fst <= 12 && (snd >= 13 || snd == 0)) {
        out("MMYY");
        return;
    }
    if(snd > 0 && snd <= 12 && (fst >= 13 || fst == 0)) {
        out("YYMM");
        return;
    }
    if(fst > 0 && fst <= 12 && snd > 0 && snd <= 12) {
        out("AMBIGUOUS");
        return;
    }
}

int main() {
    fast_io;
    solve();
    return 0;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * 1602.cc: ICPC Calculator
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 20;

/* typedef */

typedef pair<int,int> pii;

enum { ADD = 10, MUL = 11 };

/* global variables */

char s[32];
pii ps[MAX_N];

/* subroutines */

int calc(int &u) {
  int pd = ps[u].first, pv = ps[u].second;
  u++;

  if (pv == ADD) {
    int r = 0;
    while (ps[u].first == pd + 1) r += calc(u);
    return r;
  }

  if (pv == MUL) {
    int r = 1;
    while (ps[u].first == pd + 1) r *= calc(u);
    return r;
  }

  return pv;
}

/* main */

int main() {
  for (;;) {
    int n;
    scanf("%d", &n);
    if (n == 0) break;

    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      int d = 0;
      while (s[d] == '.') d++;
      ps[i].first = d;

      if (s[d] == '+') ps[i].second = ADD;
      else if (s[d] == '*') ps[i].second = MUL;
      else ps[i].second = s[d] - '0';
    }
    ps[n] = pii(-1, -1);

    //for (int i = 0; i <= n; i++)
    //printf("(%d,%d)", ps[i].first, ps[i].second);
    //putchar('\n');

    int u = 0;
    int ans = calc(u);
    printf("%d\n", ans);
  }
  return 0;
}



Measured memory_bytes: 3184
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;


vector<int> G[1<<17];
int n,k;
int ans;


int dfs(int v,int c){
    int ret = 0;
    for (int i = 0; i < G[v].size(); i++) {
        int res = dfs(G[v][i],c+1);
        if(res == k && v != 0) ans++;
        else ret = max(ret,res);
    }
    return ret+1;
}


int main(){
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int a;cin >> a;
        a--;
        if(i==0) ans+=(a!=i);
        else G[a].pb(i);
    }
    dfs(0,0);
    cout << ans << endl;
    return 0;
}



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


bool is_prime(int a) {
  int max_candidate = static_cast<int>(std::sqrt(a));
  if (a % 2 == 0 && a != 2)
    return false;
  for(int i = 3; i <= max_candidate; i += 2){
    if ( a % i == 0 )
      return false;
  }
  return true;
}


int main(){
  int N;
  std::cin >> N;

  std::vector<int> list(N);
  int input;
  while(std::cin >> input){
    list.push_back(input);
  }

  int num_of_prime = 0;
  for(const auto& num : list)
    if (is_prime(num))
      ++num_of_prime;

  std::cout << num_of_prime << std::endl;
}

Measured memory_bytes: 3264
#include<stdio.h>

typedef struct{
  int have;
  int link[100];
  int min;
  int weight[100];
  int flag;
}Tree;

Tree data[100];

void input(int);
void shokika(int);
void shori(int,int,int);
void listprint(int);
void debug_listprint1(int);
void debug_listprint2(int);

int main(){

  int n, i;

  scanf("%d",&n);

  shokika(n);
  input(n);
  //debug_listprint1(n);
  shori(0,0,-1);
  listprint(n);

  return 0;
}

void shori(int now, int weight, int back)
{
  int i, x, a;
  data[now].flag = 1;
  for(i = 0; data[now].link[i] != -1; i++)
  {
    //debug_listprint2(5);
    x = data[now].weight[i];
    a = data[now].link[i];
    if(data[a].min > weight + x && data[a].flag == 0 && a != back)
    {
      //printf("data[%d].link[%d] = %d|weight:%d|t_weight:%d\n",now,i,a,x,weight);
      //printf("%d → %d\n",now,data[now].link[i]);
      data[data[now].link[i]].min = weight + x;
      shori(data[now].link[i], weight + data[now].weight[i], now);
      //printf("%d ← %d\n",now,data[now].link[i]);
    }
  }
  data[now].flag = 0;
}
void debug_listprint1(int n)
{
  int i, j;
  for(i = 0; i < n; i++)
  {
    printf("---------\n");
    printf("%d:link-%d-\n",i,data[i].have);
    for(j = 0; j < data[i].have; j++)
    {
      printf("%d:%d → %d : ",j,i,data[i].link[j]);
      printf("weight -%d-\n",data[i].weight[j]);
    }
  }
}

void debug_listprint2(int n)
{
  int i;
  printf("------------------\n");
  for(i = 0; i < n; i++)
  {
    printf("data[%d].flag = %d||data[%d].min = %d\n",i,data[i].flag,i,data[i].min);
  }
  printf("------------------\n");
}

void shokika(int n)
{
  int i, j;

  for(i = 0; i < n; i++)
  {
    for(j = 0; j < n; j++)
    {
      data[i].link[j] = -1;
      data[i].weight[j] = -1;
    }
    data[i].min = 99999999;
    data[i].flag = 0;
  }
  data[0].min = 0;
}

void input(int n)
{
  int i, j, x;

  for(i = 0; i < n; i++)
  {
    scanf("%d%d",&x,&data[i].have);
    for(j = 0; j < data[i].have; j++)
    {
      scanf("%d",&data[i].link[j]);
      scanf("%d",&data[i].weight[j]);
    }
  }
}

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



Measured memory_bytes: 2112
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

constexpr ll BIT_SIZE = (1ll<<18)+10;

ll N;
ll A[BIT_SIZE];
ll dp[BIT_SIZE], dp2[BIT_SIZE];

int main() {
  std::cin >> N;

  rep( i, 1ll<<N )
    std::cin >> A[i], dp[i] = A[i];

  rep( j, N ) rep( i, 1ll<<N ) if( i>>j&1 ) {
    ll pi = i & ~(1<<j);
    if( dp[i] < dp[pi] ) {
      dp2[i] = dp[i];
      dp[i] = dp[pi];
    } else if( dp2[i] < dp[pi] ) {
      dp2[i] = dp[pi];
    }
  }

  ll ans = 0;

  repi( k, 1, 1ll<<N ) {
    chmax( ans, dp[k]+dp2[k] );

    std::cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 9772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int64_t XORsum(int64_t n){
    int64_t v;
    if(n%2==0){
        v=(n%4>0);
        v+=n;
    }else{
        v=!((n-1)%4);
    }
    cerr<<v<<endl;
    return v;
}

int main(){
    int64_t A,B; cin>>A>>B;

    int64_t ans=XORsum(B);
    ans^=XORsum(max((int64_t)0,A-1));
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong();
		in.close();

		long div = (int) Math.sqrt(n);
		while ( 0 < div ) {
			if ( n % div == 0 ) {
				long ans = n / div + div - 2;
				System.out.println(ans);
				return;
			} else {
				div--;
			}
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define MP make_pair
#define PB push_back
using namespace std;

typedef long long ll;

class UnionFind
{
  public:
    vector<ll> parent, size;

    UnionFind(ll length)
    {
        parent.resize(length);
        size.resize(length);
        for (ll i = 0; i < length; i++)
        {
            parent[i] = i;
            size[i] = 1;
        }
    }

    ll root(ll x)
    {
        if (x == parent[x])
            return x;
        else
            return parent[x] = root(parent[x]);
    }

    void unite(ll x, ll y)
    {
        x = root(x);
        y = root(y);
        if (x == y)
            return;

        if (size[x] >= size[y])
        {
            parent[y] = x;
        }
        else
        {
            parent[x] = y;
        }
        size[x] = size[y] = size[x] + size[y];
    }

    ll siz(ll x)
    {
        return size[root(x)];
    }

    bool issame(ll x, ll y)
    {
        return root(x) == root(y);
    }
};

int main()
{
    ll n, m;
    ll a[100000] = {}, b[100000] = {};
    ll res[100000] = {};
    cin >> n >> m;
    FOR(i, 0, m)
    {
        cin >> a[i] >> b[i];
    }
    UnionFind uf(n + 1);
    res[m - 1] = (long long)(n * (n - 1) / 2);
    for (ll i = m - 1; i > 0; i--)
    {
        res[i - 1] = uf.root(a[i]) != uf.root(b[i]) ? res[i] - (ll)(uf.siz(a[i]) * uf.siz(b[i])) : res[i];
        uf.unite(a[i], b[i]);
    }

    FOR(i, 0, m)
    {
       cout << ((res[i] < 0) ? 0 : res[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 5248
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int n,x,i,sum,cnt,l[100];
	scanf("%d %d",&n,&x);
	for(i=0;i<n;i++)	scanf("%d",&l[i]);
	sum=0;	cnt=1;
	for(i=0;i<n;i++)	{
		sum+=l[i];
		if(sum>x)	break;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
//include
//------------------------------------------
#include <bits/stdc++.h> // only for GCC

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

//repetition
//------------------------------------------
#define loop(i,a,b) for(ull i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define riter(i,c) for(auto i=(c).rbegin(); i!=(c).rend(); ++i)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T>ostream&operator<<(ostream&os, vector<T>const&v){
        iter(it,v) os<<*it<<(it+1==v.end()?"":",");
        return os;
    }
    template<typename T, typename U>ostream&operator<<(ostream&os,const pair<T,U>&p){
        return os << "[" << p.dirst << "," << p.second << "]";
    }
}

//clear memory
// ------------------------------------------
#define clr(a,i) memset((a), (i) ,sizeof(a))

int main(){
   int n,m;
   while(cin >> n && n){
      int m;
      vvi b;
      int ans=-1;
      bool c=true;
      
      rep(i,n+1){
         cin >> m;         
         vi a(m);
         rep(i,m) cin >> a[i];
         sort(all(a));
         b.pb(a);
      }
      rep(i,n){
         if(b[i].size()>=b[n].size()){
            rep(j,b[n].size()){
               if(count(all(b[i]),b[n][j])==0) break;
               else if(j==b[n].size()-1){
                  if(ans==-1) ans=i+1;
                  else{
                     c=false;
                     break;
                  }
               }
            }
         }
      }
      if(c!=false) cout << ans << endl;
      else cout << -1 << endl;
   }
}

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

string rev(string s){
  reverse(s.begin(), s.end());
  return s;
}

int main(void){
  int n; cin >> n;
  while(n--){
    string str; cin >> str;
    set < string > abcd;
    for(int i=1; i < str.length(); i++){
      string str1, str2;
      str1 = str.substr(0, i);
      str2 = str.substr(i, str.length()-i);
      abcd.insert(str1+str2);
      abcd.insert(str2+str1);
      abcd.insert(rev(str1)+str2);
      abcd.insert(str1+rev(str2));
      abcd.insert(rev(str2)+str1);
      abcd.insert(str2+rev(str1));
      abcd.insert(rev(str2)+rev(str1));
      abcd.insert(rev(str1)+rev(str2));
    }
    cout << abcd.size() << endl;
  }
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			while ((x = in.readLine()) != null) {
				if (x.equals("0 0")) break;
				
				String[] values = x.split(" ");
	
				int a = Integer.parseInt(values[0]);
				int b = Integer.parseInt(values[1]);
				
				for (int i = 0; i < a; i++) {
					for (int j = 0; j < b; j++) {
						System.out.print('#');
					}
					System.out.println();
				}
				System.out.println();
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 37548
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define f first
#define s second
typedef long long ll;
typedef unsigned long long ull;

void IO(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("test.txt","r",stdin);
    #endif
}

const int N=1e6+3,M=1e3+5,mod=1e9+7,dx[]={1,-1,0,0},
                                    dy[]={0,0,1,-1};
const double eps=1e-9;

int n,a,b,c;

int& get(char cc){
    if (cc == 'A')
        return a;
    else if (cc == 'B')
        return b;
    else
        return c;
}

vector<int> nxt[3];

int main(){
    //IO();
    cin >> n >> a >> b >> c;
    int zeros = (a == 0) + (b == 0) + (c == 0);
    vector<char> v;
    vector<string> ss(n);
    for(int i = 0 ; i < n ; i++){
        cin >> ss[i];
        nxt[ss[i][0] - 'A'].push_back(i);
        nxt[ss[i][1] - 'A'].push_back(i);
    }
    for(int i = 0 ; i < n ; i++){
        string& s = ss[i];
        int& x = get(s[0]);
        int& y = get(s[1]);
        if (!x){
            x++;
            y--;
            v.push_back(s[0]);
        }
        else if (!y){
            y++;
            x--;
            v.push_back(s[1]);
        }
        else if (x > 1 || y > 1){
            if (x < y){
                x++;
                y--;
                v.push_back(s[0]);
            }
            else{
                x--;
                y++;
                v.push_back(s[1]);
            }
        }
        else{
            int p = s[0] - 'A';
            int nxt_x = upper_bound(nxt[p].begin(),nxt[p].end(),i) - nxt[p].begin();
            if (nxt_x == sz(nxt[p]))
                nxt_x = 1e9;
            else
                nxt_x = nxt[p][nxt_x];
            p = s[1] - 'A';
            int nxt_y = upper_bound(nxt[p].begin(),nxt[p].end(),i) - nxt[p].begin();
            if (nxt_y == sz(nxt[p]))
                nxt_y = 1e9;
            else
                nxt_y = nxt[p][nxt_y];
            if (nxt_x < nxt_y){
                x++;
                y--;
                v.push_back(s[0]);
            }
            else{
                x--;
                y++;
                v.push_back(s[1]);
            }
        }
        if (a < 0 || b < 0 || c < 0){
            assert(zeros >= 2);
            return !printf("No\n");
        }
    }
    printf("Yes\n");
    for(auto c : v)
        printf("%c\n",c);
}


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

int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d.at(i);
  int s = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      s += d.at(i) * d.at(j);
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  boost::for_each(vc, [&os](T value) {
    os << value << " ";
    });
  return os;
}

template<class T1, class T2>
inline
std::ostream&
operator<<(std::ostream& os, const std::pair<T1, T2>& p)
{
  return os << p.first << " " << p.second << " ";
}

void solve(void)
{
  ui  N{}; std::cin >> N;
  ull K{}; std::cin >> K;

  typedef std::vector<ui> Vector;
  Vector A(N);
  std::map<ui, Vector> idx;
  rep(0, N)
  {
    std::cin >> A[i];
    idx[A[i]].push_back(i); // 出現位置
  }

  ui LOG_K = (ui)log2(K);
  ui LOG_N = (ui)log2(N);
  assert(LOG_K + LOG_N < 58); // 制約チェック

  typedef std::vector<ull> Vector_ull;
  std::vector<Vector_ull> dp(LOG_K + LOG_N + 1, Vector_ull(N));
  for (auto p : idx)
  {
    ui sz = p.second.size();
    p.second.push_back(p.second[0] + N);
    rep(0, sz)
    {
      dp[0][p.second[i]] = p.second[i + 1] - p.second[i] + 1; // 移動距離
    }
  }

  rep(1, dp.size())
  {
    rep_uj(0, N)
    {
      dp[i][j] = std::min(
        std::numeric_limits<ull>::max() / 3,
        dp[i - 1][j] + dp[i - 1][(dp[i - 1][j] + j) % N]);
    }
  }

  ull it{ 0 };
  ull it_max = K * N - 1;
  for(ui i = dp.size() - 1;;)
  {
    if (it + dp[i][it % N] <= it_max)
    {
      it += dp[i][it % N];
    }
    if(!i--)
      break;
  }
  assert(it <= it_max);

  Vector ans;
  ans.reserve(N);

  it %= N;
  std::set<ui> dic;
  while(it < N)
  {
    if (dic.count(A[it]))
    {
      while (true)
      {
        ui last = ans.back();
        ans.pop_back();
        dic.erase(last);
        if (last == A[it])
          break;
      }
    }
    else
    {
      ans.push_back(A[it]);
      dic.insert(A[it]);
    }
    ++it;
  }

  std::cout << ans << "\n";

  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 120676
#include <stdio.h>
int main()
{
  int i,n,j,count = 0;
  scanf("%d",&n);
  for(int i=1;i<=n;i++)
  {
    scanf("%d" ,&j);
    if( j != i )
      count++;
  }
  if( count == 0 || count == 2)
    printf("YES\n");
  else
    printf("NO\n");
  return 0;
}


Measured memory_bytes: 2084
def divc(num):
    count = 0
    for i in range(1, num+1):
        if num % i == 0:
            count += 1
    
    return count

n = int(input())
ans = 0
for i in range(1, n+1):
    if i % 2 != 0 and divc(i) == 8:
        ans += 1

print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N; cin >> N;
  vector<int> a(N);
  int onButton = 1, cnt = 0;
  for(int i = 0; i < N; i++)
    cin >> a.at(i);
  for(cnt = 1; cnt < N + 1; cnt++) {
    if(a.at(onButton - 1) == 2) {
      cout << cnt << endl;
      return 0;
    }
    onButton = a.at(--onButton);
  }
  cout << -1 << endl;
}

Measured memory_bytes: 640
// 1_3_B
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
    char name[10];
    int time;
} process_t;

typedef struct {
    int front, rear, queue_size;
    process_t *elements;
} queue;

void SetProcess(process_t *p, char *name, int time){
    strcpy(p->name, name);
    p->time = time;
    return;
}

void InitQueue(queue *q, int ps){
    q->front = 0;
    q->rear = 0;
    q->queue_size = ps;
    return;
}

void Putq(queue *q, process_t p){
    q->elements[q->rear] = p;
    if(q->rear == q->queue_size){
        q->rear = 0;
    } else{
        q->rear += 1;
    }
    return;
}

process_t Getq(queue *q){
    process_t p;
    p = q->elements[q->front];
    if(q->front == q->queue_size){
        q->front = 0;
    } else{
        q->front += 1;
    }
    return p;
}

int QueueEmpty(queue *q){
    return (q->front == q->rear);
}

int main(){
    int ps, quantum, i, time, total_time;
    char name[10];
    process_t process;
    queue q;

    // ??\?????????????????????????????????????????±????????\??????????´?
    scanf("%d %d", &ps, &quantum);
    InitQueue(&q, ps);
    q.elements = (process_t *)malloc(sizeof(process_t)*(ps+1)); // ?????\???????????°???????????????????????????????????°??????1??????????????¢???????¢????
    for(i = 0; i < ps; i++){
        scanf("%s %d", name, &time);
        SetProcess(&process, name, time);
        Putq(&q, process);
    }

    // ?????????????????????
    while(!QueueEmpty(&q)){
        process = Getq(&q);
        if(process.time <= quantum){
            total_time += process.time;
            printf("%s %d\n", process.name, total_time);
        } else{
            process.time -= quantum;
            total_time += quantum;
            Putq(&q, process);
        }
    }

    free(q.elements);
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
string k;
int main()
{
	cin>>k;
	for(int i=0;i<k.size();i++)
	{
		if(k[i]=='C')
		{
			for(int j=i;j<k.size();j++)
			{
				if(k[j]=='F')
				{
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}

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

const int INF = 0x3f3f3f3f;

int main()
{
	string s;
	cin >> s;
	rep(i, s.size()) if(s[i] == ',') s[i] = ' ';
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int BUF = 100005;
const long long INF = 1LL << 60;

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

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


int nVal, limit;
int val[BUF];

void read() {
    cin >> nVal >> limit;
    for (int i = 0; i < nVal; ++i) cin >> val[i];
}


void work() {
    long long l = val[0];

    for (int i = 1; i < nVal; ++i) {
        if (l != INF) {
            l = lcm(l, val[i]);
            if (l / 2 >= limit) {
                l = INF;
            }
        }
    }

    if (l != INF) {
        for (int i = 0; i < nVal; ++i) {
            if (l / 2 < val[i] / 2 || (l / 2 - val[i] / 2) % val[i] != 0) {
                cout << 0 << endl;
                return;
            }
        }
    }
    
    if (l != INF) {
        cout << (limit - l / 2) / l + 1 << endl;
    } else {
        cout << 0 << endl;
    }
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

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



Measured memory_bytes: 3096
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll N;
    cin >> N;
    string s;
    cin >> s;
    rep(i,0,4) {
        vector<char> ans(N+3);
        if (i == 0) {
            ans[0] = 'S';
            ans[1] = 'S';
        } else if (i == 1) {
            ans[0] = 'S';
            ans[1] = 'W';
        } else if (i == 2) {
            ans[0] = 'W';
            ans[1] = 'S';
        } else {
            ans[0] = 'W';
            ans[1] = 'W';
        }
        rep(i,2,N+2) {
            if ((ans[i-1] == 'S' && s[(i-1)%N] == 'o') || (ans[i-1] == 'W' && s[(i-1)%N] == 'x')) {
                ans[i] = ans[i-2];
            } else {
                if (ans[i-2] == 'W') {
                    ans[i] = 'S';
                } else {
                    ans[i] = 'W';
                }
            }
        }
        if (ans[0] == ans[N] && ans[1] == ans[N+1]) {
            rep(i,0,N) {
                cout << ans[i];
            }
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}



Measured memory_bytes: 888
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	s := Scan()
	ans := 0
	for i := 0; i < 3; i++ {
		if s[i] == 'R' {
			ans++
		}
	}
	if ans == 2 && s == "RSR" {
		ans = 1
	}
	fmt.Println(ans)
}

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

using namespace std;

#define F first
#define S second

const int MAXN = 1e5 + 10;
const int C = 10 + 2;
const int INF = 1e9;

int n, m, col[MAXN];
int aa[MAXN], bb[MAXN], cc[MAXN], lv[MAXN][C];
vector<int> adj[MAXN];
pair<int, int> s[C * MAXN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m;
	while (m--){
		int a, b;	cin >> a >> b, a--, b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	int q;	cin >> q;
	for (int i = 0; i < q; i++)
		cin >> aa[i] >> bb[i] >> cc[i], aa[i]--;

	memset(lv, 63, sizeof(lv));
	int t = 0, h = 0;
	for (int i = q-1; ~i; i--){
		int v = aa[i], d = bb[i], c = cc[i];
		if (lv[v][d] < INF) continue;

		s[t++] = {v, d};
		lv[v][d] = 0;
		while (t-h){
			auto v = s[h++];
			if (!col[v.F]) col[v.F] = c;
			if (v.S == 0) continue;

			for (int u:adj[v.F])
				if (lv[u][v.S-1] >= INF){
					lv[u][v.S-1] = 0;
					s[t++] = {u, v.S - 1};
				}
		}
	}

	for (int i = 0; i < n; i++)
		cout << col[i] << "\n";
	return 0;
}


Measured memory_bytes: 22136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace aoj1
{
    class Program
    {
        static void Main()
        {
            int[] num = IntInput();
            int a = num[0];
            int b = num[1];
            if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }

        static int[] IntInput()
        {
            string[] strs = Console.ReadLine().Split(' ');
            int[] numbers = new int[strs.Length];
            for (int i = 0; i < strs.Length; i++)
            {
                numbers[i] = int.Parse(strs[i]);
            }
            return numbers;
        }
    }
}

Measured memory_bytes: 5312
while True :  
  n,x = map(int,input().split())
  if n == 0 and x == 0 :
    break
  
  else :
    count = 0
    for i in range(1,n+1) :
      for j in range(1,i) :
        for k in range(1,j) :
          if i+j+k == x :
            count = count + 1
           
          else :
            pass
    print (count)
  


Measured memory_bytes: 5596
import collections

N = int(input())
A = list(map(int,input().split()))
c = [0]*N
p = 0


c = collections.Counter(A)

for i in range(N):
  p += (c[i+1])*(c[i+1]-1)//2

for i in range(N):
  print(p-c[A[i]]+1)


Measured memory_bytes: 26772
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc =new Scanner(System.in);
        int S = sc.nextInt();        
        int[] num = new int[1000000];
        int ans = 0;
        num[0] = S;

        //計算処理          
        for(int i = 1; i <1000000; i++){
           if(S % 2 == 0){
               num[i] = S/2;
               S = S/2;
           }else if(S % 2 == 1){
               num[i] = 3*S + 1;
               S = 3*S + 1;
           }

            //評価
           for(int j = 0; j < i; j++){
               if(num[j] == num[i]){
                   ans = i+1;
               }
            }

            if(ans != 0){
                break;
            }
       }
       
       System.out.println(ans);
    }
}


Measured memory_bytes: 25684
/***
 ** " Love the life you live. Live the life you love. "
 **     -- Bob Marley
***/

/**
  *  Author: dhruv_gheewala
  *  Problem: __________
  *  Date:   19.04.2020
  *  Time:   17:44:29
**/

#if __has_include("debug.h")
    #include "debug.h"
#else
    #include<bits/stdc++.h>
    using namespace std;

    #define p(str) 7
    #define o(str) 42
    #define fundri 108
    #define debug(...) 1729
#endif

#define int long long
typedef pair<int,int> pii;
typedef vector<int> vi;

const bool testcases = 0;
#define ff first
#define ss second
#define endl '\n'
#define all(s) s.begin(), s.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr)

// if vector isn't soted then it will remove consecutive same elements
#define make_unique(vec) vec.erase(unique(all(vec)), vec.end())
#define test int TC = 1;if(testcases)cin >> TC;for(int tc = 1 ; tc <= TC ; tc++)
#define sort_by(cont,expr) sort(all(cont),[&](const auto &lhs,const auto &rhs){return expr;})

int seed;mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l=0,int r=INT_MAX){return uniform_int_distribution<int>(l,r)(rng);}

template<typename T>bool isPrime(T n){for(T i=2;i*i<=n;i++)if(n%i==0)return 0;return 1;}
template<typename T>inline bool in_range(T a,T l,T r){return (a>=l&&a<=r);}
template<typename T, typename U>inline istream& operator >>(istream& in, pair<T, U> &a){in >> a.ff >> a.ss;return in;}
template<typename T>inline istream& operator >>(istream& in, vector<T> &a){for(auto &x : a)in >> x;return in;}

int32_t main(int32_t argc, char **argv)
{
    #ifdef DHRUV_GHEEWALA
        std::chrono::time_point<std::chrono::high_resolution_clock> start_time, end_time;
        start_time = std::chrono::high_resolution_clock::now();

        freopen("INPUT.txt","r",stdin);
        freopen("OUTPUT.txt","w",stdout);
        freopen("DEBUG.txt","w",stderr);
    #endif

    fast;
    int n;
    cin >> n;
    vi freq(n + 1, 0);

    int val;
    for(int i = 1 ; i < n ; i++)
    {
    	cin >> val;
    	freq[val]++;
    }

    for(int i = 1 ; i <= n ; i++)
    	cout << freq[i] << endl;

    #ifdef DHRUV_GHEEWALA
        end_time = std::chrono::high_resolution_clock::now();
        int elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_time - start_time).count();
        cerr << endl << endl;
        cerr << "Elapsed Time: " << elapsed_time << " ms" << endl;
    #endif

    return 0;
}

Measured memory_bytes: 4808
from sys import stdin
input = stdin.readline


def main():
  N, K = list(map(int, input().split()))
  R, S, P = list(map(int, input().split()))
  T = input()[:-1]

  mem = []
  hand_map = {'r': 'p', 's': 'r', 'p': 's'}
  score_map = {'r': P, 's': R, 'p': S}

  score = 0

  for i in range(K):
    mem.append(hand_map[T[i]])
    score += score_map[T[i]]

  for i in range(K, N):
    if not mem[i-K] == hand_map[T[i]]:
      mem.append(hand_map[T[i]])
      score += score_map[T[i]]
      continue
    cand = ['r', 's', 'p']
    # print(mem[i-K])
    cand.remove(mem[i-K])
    if i+K < N and not(mem[i-K] == hand_map[T[i+K]]):
      cand.remove(hand_map[T[i+K]])
    mem.append(cand[0])

  print(score)


if(__name__ == '__main__'):
  main()


Measured memory_bytes: 79900
#include <stdio.h>

int main(void){

   long i, res = 0, n;
   int flag;

   scanf("%ld", &i);

   for(n =1;n< i+1 ;n++){
       flag =0;
       if(n%3 == 0){
           flag =1;
       }else if(n%5 == 0){
           flag =1;
       }
       if(flag == 0){
           res += n;
       }
   }
   printf("%ld\n", res);

   return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;

int main() {
  int n;
  cin >> n;
  P a[n];
  ll d[n+1];
  d[0]=0;
  for(int i=0; i<n; i++) {
    cin >> a[i].F >> a[i].S;
    d[i+1]=d[i]+a[i].S;
  }
  int dp[n][n];
  fill(dp[0],dp[n],0);
  for(int k=0; k<n; k++) {//k: 何人持ち上げたか
    for(int i=0; i<n; i++) {//i番目から右にk人が既に１つになっている
      if(i+k>=n) break;
      if(k==0) dp[i][i]=1;
      if(!dp[i][i+k]) continue;
      ll w=d[i+k+1]-d[i];
      if(i+k<n && w<=a[i+k+1].F) dp[i][i+k+1]=1;//右に持ってもらう
      if(i>0 && w<=a[i-1].F) dp[i-1][i+k]=1;//左に持ってもらう
    }
  }
  
  int dp2[n+1];
  for (int i=1; i<=n; i++) dp2[i]=MAX;
  dp2[0]=0;
  for(int j=1; j<=n; j++) {
    for(int i=1; i<=n; i++) {
      if(dp[i-1][j-1]) dp2[j]=min(dp2[j],dp2[i-1]+1);
    }
  }
  cout << dp2[n] << endl;
  return 0;
}


Measured memory_bytes: 5084
/* ex2_3
    riverstone*/

#include <stdio.h>
 
int main(void){
    //int型としてNとAを定義
    int N, A;
    //入力の受け取り
    scanf("%d%d", &N, &A);
    //全部でN×Nマスあり、白がAマスのため黒はN×N-Aマス
    printf("%d\n", N * N - A);
    return 0;
}

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

int main()
{
	int n; cin >> n;	
	
	string ans = "No";

	for (int i = 1; i <= 9; i++) {

		for (int j = 1; j <= 9; j++) {
			
			if (n == i * j) ans = "Yes";
		}
	
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int f[N][28];
set < pair < int, int >  > st[27];
int main(){
    string s;
    cin >> s;
    for(int i = 0 ; i < s.size() ; i++){
        if (i){
            for(int j = 0 ; j <26 ; j++){
                f[i][j] = f[i - 1][j];
            }
        }
        int cur = s[i] - 'a';
        f[i][cur]++;
        //cout <<' ' << 2 * f[i][cur] - i + 1 << endl;
        set < pair < int, int >  > :: iterator it = st[cur].lower_bound({2 * f[i][cur] - i + 1,0});
        if (st[cur].empty() || it == st[cur].begin()){
            st[cur].insert({2 * f[i][cur] - i , i});
            continue;
        }
        it--;
        return cout << it->second + 1 <<' ' << i + 1 ,0;
    }
    cout << -1 <<' ' << -1 ;
    return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  ll n,m;
  cin>>n>>m;
  int l=INT_MIN,r=INT_MAX;
  for(int i=0;i<m;i++)
  {
       int u,v;
       cin>>u>>v;
       l=max(u,l);
       r=min(r,v);
  }
  cout<<max(r-l+1,0)<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int r,n;
void solve() {
    map<int,int> h;
    double ans=INF;
    rep(i,n) {
        int x1,x2,t;
        cin>>x1>>x2>>t;
        for(int x=x1;x<x2;x++) h[x]=max(h[x],t);
    }
    for(int x=-r;x<r;x++) {
        int x1=x;
        double y=sqrt(r*r-x1*x1);
        //printf("%d : %d %.10f\n",x,h[x],r-y);
        ans=min(ans,h[x]+r-y);
        x1++;
        if(h.count(x1)) {
            double y=sqrt(r*r-x1*x1);
            //printf("%d : %d %.10f\n",x,h[x],r-y);
            ans=min(ans,h[x]+r-y);
        }
    }

    printf("%.10f\n",ans);
}
int main() {
    while(cin>>r>>n) {
        if(!r) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1228
require 'pp'

A,B,C = readline.chomp.split.map(&:to_i)
if A < B
  if A < C and C < B
    puts 'Yes'
  else
    puts 'No'
  end
else
  if B < C and C < A
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
long long fact(int x)
{
    if(x==0)
        return 1;
    else
        return x*fact(x-1);
}
long long permu(int x,int r)
{
    return (fact(x)/((fact(x-r))*fact(r)));
}
bool pali(char a[])
{
    int l=strlen(a),i;
    for(i=0;i<l;i++)
    {
        if(a[i]==a[l-1-i])
            continue;
        else
            return false;
    }
    return true;
}
int main()
{
    fast;
    char s[110],a[110],b[110];
    int l,i,j=0;
    bool k,m,n;
    cin>>s;
    k=pali(s);
    l=strlen(s);
    for(i=0;i<(l-1)/2;i++)
    {
        a[i]=s[i];
    }
    a[i]='\0';
    m=pali(a);
    for(i=((l+3)/2-1);i<l;i++)
    {
        b[j++]=s[i];
    }
    b[j]='\0';
    n=pali(b);
    if(k && n && m)
        cout<<"Yes";
    else
        cout<<"No";
}


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

int inf = 9999999;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    vector<vector<int>> step(H, vector<int>(W, inf));
    queue<pair<int, int>> q; 
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (grid[i][j] == 'S') {
                step[i][j] = 0;
                q.push({i, j});
            }
        }
    }
    vector<pair<int, int>> ds = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
    while (!q.empty()) {
        int x = q.front().first;
        int y = q.front().second;
        q.pop();
        for (pair<int, int> d : ds) {
            int s = x+d.first;
            int t = y+d.second;
            if (s < 0 || s >= H || t < 0 || t >= W) continue;
            if (grid[s][t] == '.') {
                if (step[s][t] > step[x][y]+1) {
                    step[s][t] = step[x][y]+1;
                    q.push({s, t});
                }
            }
        }
    }
    int ans = inf;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int m = (min(i, H-1-i)+K-1)/K;
            int n = (min(j, W-1-j)+K-1)/K;
            if (step[i][j] <= K) ans = min(ans, 1+min(m, n));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    B = [0] * N
    for i in range(N):
        B[i] = A[i] - (i+1)
    B.sort()

    a, b = B[N//2-1], B[N//2]
    ans = 0
    tmp = 0
    for i in range(N):
        ans += abs(A[i] - (a + i + 1))
        tmp += abs(A[i] - (b + i + 1))
    ans = min(ans, tmp)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 83192
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll i,j,k,l,m,n,o,p,q,r,t,a[300001]={0};
    cin>>n;
    m=0;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        m^=a[i];
    }
    for(i=0;i<n;i++)
    {
        cout<<(m^a[i])<<" ";
    }
    cout<<endl;
    return 0;
}

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

#define ll long long

int main(){
  ll x, now= 100, cnt = 0;
  scanf("%lld", &x);
  do
  {
    now += now/100;
    cnt++;
    /* code */
  } while (x > now);
  
  printf("%lld\n", cnt);
  return 0;
}

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

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

    long _max = -1000002, _min = 1000002, _sum = 0;
    int loop;
    cin >> loop;

    rep(qi, loop) {
        long num;
        cin >> num;

        _max = max(_max, num);
        _min = min(_min, num);
        _sum += num;
    }
    cout << _min << " " << _max << " " << _sum << endl;
}


Measured memory_bytes: 3212