akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int n,k,ans;
int b[10000];
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9'){if (c=='-') t=-1;c=getchar();}
	while (c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*t;
}
int main()
{
	n=read(); k=read();
	for (int i=1;i<=n;i++)
	  b[i]=read();
	sort(b+1,b+n+1);
	for (int i=1;i<=n;i++)
	  if (abs(b[i])<=abs(k-b[i])) ans+=2*abs(b[i]);
	  else ans+=2*(abs(k-b[i]));
	out(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll w,h,p,q,sum,d[2];
vector<P> v;

int main(){
  cin>>w>>h;
  d[0]=w+1;
  d[1]=h+1;
  for(int i=0;i<w;i++){
    cin>>p;
    v.push_back(P(p,0));
  }
  for(int i=0;i<h;i++){
    cin>>q;
    v.push_back(P(q,1));
  }
  sort(v.begin(),v.end());
  for(int i=0;i<v.size();i++){
    sum+=v[i].first*d[!v[i].second];
    d[v[i].second]--;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
using namespace std;
int main(void)
{
	vector<int> v;
	int q,x,p,i,n;
	scanf("%d",&q);
	for(i=0;i<q;i++)	{
		scanf("%d",&n);
		if(n==0)	{
			scanf("%d",&x);
			v.push_back(x);
		}
		else if(n==1)	{
			scanf("%d",&p);
			printf("%d\n",v[p]);
		}
		else v.pop_back();
	}
	return 0;
}



Measured memory_bytes: 3448
#include <stdio.h>
int main(void) {
  char a[100], b[100];
  int q,resp=0,i;
  scanf("%s", a);
  scanf("%s", b);
  q=strcmp(a,b);
  if(q==0) {
    resp=strlen(a);
  } else if(q>0){
    for(i=0;i<strlen(b);i++){
      if(*(a+i) == *(b+i)) resp++;
    }
  } else {
    for(i=0;i<strlen(a);i++){
      if(*(a+i)==*(b+i)) resp++;
    }
  }
  printf("%d", resp);
  return 0;
}



Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int n, i, debt = 100000, init = 100000;
	
	scanf("%d",&n);
	
	for(i = 0;i < n;i++){
		debt += debt / 20;
		
		if(debt % 1000 != 0){
			debt -= debt % 1000;
			debt += 1000;
		}
	}
	
	printf("%d\n",debt);
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;

  M m;
  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        int calc = pow(x+y,2) + pow(y+z,2) + pow(z+x, 2);
        m[calc]++;
      }
    }
  }
  REP(i,n) {
    COUT(m[(i+1)*2]);
  }

  return 0;
}


Measured memory_bytes: 5396
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 
#define CERR if(false) cerr

using namespace std;

int main(){

    int n;
    cin >> n;

    cout << n / 3 << endl;

    return 0; 
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;

class Student
{
public:
	int mid, fin, re;
	Student()
	{
		mid = fin = re = -1;
	}
};

int main(void)
{
	Student s;

	while(true)
	{
		cin >> s.mid >> s.fin >> s.re;
		int sum = s.mid + s.fin;
		if (s.mid == -1 && s.fin == -1 && s.re == -1) break;
		if (s.mid == -1 || s.fin == -1) cout << "F" << endl;
		else if (sum >= 80) cout << "A" << endl;
		else if (65 <= sum && sum < 80) cout << "B" << endl;
		else if (50 <= sum && sum < 65) cout << "C" << endl;
		else if (30 <= sum && sum < 65)
		{
			if (s.re >= 50) cout << "C" << endl;
			else cout << "D" << endl;
		}
		else cout << "F" << endl;
	}
	return 0;
}


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

int main() {
    int n; cin >> n;
    vector<int> a(n+1);
    for (int x = 1; x <=100; x++) {
        for (int y = 1; y <= 100;y++) {
            for (int z = 1; z <= 100; z++) {
                int ii = x*x + y*y + z*z + x*y + y*z + z*x;
                if (ii >n ) continue;
                //printf("x=%d, y=%d, z=%d = %d\n", x, y, z, x*x + y*y + z*z + x*y + y*z + z*x);
                a[ii-1]++;
                
            }
        }
    }
    for (int i = 0; i <n;i++) {
        cout << a[i] << endl;
    }
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  if (((A < C) && (C < B)) || ((B < C) && (C < A))) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))
mod = 998244353
distance_dict = {}
if d[0] != 0:
    print(0)
    exit()
for i in range(1,n):
    if d[i] == 0:
        print(0)
        exit()
    distance_dict[d[i]] = 0

for i in range(1,n):
    distance_dict[d[i]] += 1
pre = 1
ans = 1
for i in range(1,n):
    if i in distance_dict:
      ans *= pre ** distance_dict[i]
      pre = distance_dict[i]
      ans %= mod
      if i != 1 and i - 1 not in distance_dict:
          print(0)
          exit()
print(ans)

Measured memory_bytes: 18680
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x, y;
    cin >> x >> y;
    if(x == y)
        cout << "Draw" << endl;
    else if(x==1)
        cout << "Alice" << endl;
    else if(y==1)
        cout << "Bob" << endl;
    else
    {
        if(x>y)
            cout << "Alice" << endl;
        else if(y>x)
            cout << "Bob" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll a[200005];
ll kosu[200005] = {};
ll sel[200005] = {};
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		kosu[a[i]]++;
	}
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		sel[a[i]] = (kosu[a[i]] * (kosu[a[i]] - 1)) / 2;
	}

	for (int i = 1; i <= n; i++) {
		sum += sel[i];
	}
	

	for (int i = 0; i < n; i++) {
		ll ans = sum;
		ans = ans - sel[a[i]] + ((kosu[a[i]] - 1) * (kosu[a[i]] - 2)) / 2;
		cout << ans << endl;
	}
	
	return 0;

}



Measured memory_bytes: 6272
#include <stdio.h>

int IsPossible() {
  char row[10];
  int H, W;
  scanf("%d %d", &H, &W);
  int last = 0;
  for(int i = 0; i < H; i++) {
    scanf(" %s", row);
    int x;
    for(x = 0; x < last; x++)
      if(row[x] == '#') return 0;
    if(row[last] != '#') return 0;
    for(x = last + 1; x < W; x++) {
      if(row[x] != '#') break;
      last++;
    }
    for(; x < W; x++) {
      if(row[x] == '#') return 0;
    }
  }
  return (last == W - 1);
}

int main() {
  puts(IsPossible() ? "Possible" : "Impossible");
  return 0;
}

Measured memory_bytes: 128
#include <iostream> 
#include <cstdio> 
#include <fstream> 
#include <algorithm> 
#include <cmath> 
#include <deque> 
#include <vector> 
#include <queue> 
#include <string> 
#include <cstring> 
#include <map> 
#include <stack> 
#include <set> 
using namespace std;
typedef long long ll;
ll  abs2(ll a)
{
    if (a >= 0)
        return a;
    else
        return -a;
}

int main()
{
    ll X, Y;
    cin >> X >> Y;
    if (abs2(X - Y) >= 2)
        cout << "Alice\n";
    else
        cout << "Brown\n";
}


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

using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<char>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
#define chmax(x,y) x = max(x,y);
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };
const ll INF = 1e18;
// auto mod int int で入れてmodで割った値を返すLibrary
const int  mod = 1000000007;
struct mint {
	ll x;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator -() const { return mint(-x); }
	mint& operator +=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator -=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*= (const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a)const { return mint(*this) += a; }
	mint operator-(const mint a)const { return mint(*this) -= a; }
	mint operator*(const mint a)const { return mint(*this) *= a; }

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime mode
	mint inv() const { return pow(mod - 2); }
	mint& operator /= (const mint a) { return *this *= a.inv(); }
	mint operator / (const mint a) const { return mint(*this) /= a; }
};
istream& operator >>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator <<(ostream& os, const mint& a) { return os << a.x; }

ll sum(ll l, ll r) {
	return (l + r) * (r - l + 1) / 2;
}

int main() {
	int n, k;
	cin >> n >> k;
	mint ans;
	for (int i = k; i <= n+1; i++)
	{
		ll l = sum(0, i - 1), r = sum(n - i + 1, n);
		ans += r - l + 1;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

// advance_nはansのn桁目以降が0出なければ切り上げ、0ならそのままにする
//  12000 12345 - (12345 % 10^3
int advance_n(int ans,int n)
{
	return (ans - ans % int(pow(10,n)) + (ans % int(pow(10,n)) != 0)*int(pow(10,n)));
}

int how_much_debt(int n)
{
	if (n==0)
		return 100000;
	else{
		// cout << "(advance_n (how_much_debt(n-1),3))=" << (advance_n (how_much_debt(n-1),3)) << endl;
		return 1.05 * (advance_n (how_much_debt(n-1),3));
	}
		
}

int main()
{
	int a;
	cin >> a;
	// cout << how_much_debt(a) << endl;
	cout << advance_n(how_much_debt(a),3) << endl;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (ll)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=105;
int n,m;
char a[maxn][maxn];
int main()
{
    IO;
    cin >> n >> m;
    vector<bool> row(n,0),col(m,0);
    for(int i=0;i<n;++i)
        for(int j=0;j<m;++j)
            cin >> a[i][j];
    for(int i=0;i<n;++i){
        int cnt=0;
        for(int j=0;j<m;++j)
            cnt+=a[i][j]=='.';
        if(cnt==m)row[i]=true;
    }
    for(int i=0;i<m;++i){
        int cnt=0;
        for(int j=0;j<n;++j)
            cnt+=a[j][i]=='.';
        if(cnt==n)col[i]=true;
    }
    bool ok=false;
    for(int i=0;i<n;++i,((ok)?cout<<endl,ok=false:ok=ok))
        for(int j=0;j<m;++j)
            if(!row[i]&&!col[j])
                cout<<a[i][j],ok=true;
    re 0;
}

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

using namespace std;
using Integer = long long;

int main () {
  Integer N, T;
  cin >> N >> T;

  Integer prev, curr, sum = 0;
  for (Integer i = 0; i < N; i++) {
    cin >> curr;
    if (i > 0) sum += max(curr - prev - T, (Integer) 0);
    prev = curr;
  }

  cout << curr + T - sum << "\n";
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

template <class T>
class EdgeBase
{
public:
    int to;
    T cost;
    EdgeBase(){};
    EdgeBase(int to0, T cost0){to = to0; cost = cost0;}
};
typedef EdgeBase<long long> Edge;

template<class T>
void shortestPath(const vector<vector<EdgeBase<T> > >& edges, int start, vector<T>& dist)
{
    const T INF = numeric_limits<T>::max();
    const T EPS = static_cast<T>(1.0e-10);

    dist.assign(edges.size(), INF);
    dist[start] = 0;
    priority_queue<pair<T,int>, vector<pair<T,int> >, greater<pair<T,int> > > q;
    q.push(make_pair(0, start));

    while(!q.empty()){
        pair<T, int> p = q.top();
        q.pop();
        int v = p.second;
        if(dist[v] < p.first - EPS)
            continue;
        for(unsigned i=0; i<edges[v].size(); ++i){
            EdgeBase<T> e = edges[v][i];
            if(dist[v] + e.cost < dist[e.to] - EPS){
                dist[e.to] = dist[v] + e.cost;
                q.push(make_pair(dist[e.to], e.to));
            }
        }
    }
}

int main()
{
    int n, m, s, t;
    cin >> n >> m >> s >> t;
    -- s;
    -- t;

    vector<vector<Edge> > edges1(n), edges2(n);
    for(int i=0; i<m; ++i){
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        -- u;
        -- v;
        edges1[u].push_back(Edge(v, a));
        edges1[v].push_back(Edge(u, a));
        edges2[u].push_back(Edge(v, b));
        edges2[v].push_back(Edge(u, b));
    }

    vector<long long> dist1, dist2;
    shortestPath(edges1, s, dist1);
    shortestPath(edges2, t, dist2);

    vector<long long> ans(n);
    for(int i=n-1; i>=0; --i){
        ans[i] = dist1[i] + dist2[i];
        if(i < n - 1)
            ans[i] = min(ans[i], ans[i+1]);
    }

    for(int i=0; i<n; ++i)
        cout << (1000000000000000ll - ans[i]) << endl;

    return 0;
}


Measured memory_bytes: 19012
//ANTIHYPE
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;

int n;
ll c[N], p[N], l[N], dp[N];

int main()
{

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> c[i];
        p[i] = l[c[i]];
        l[c[i]] = i;
    }
    dp[1] = 1;
    for (int i = 2; i <= n; ++i)
    {
        if (c[i] == c[i - 1])
        {
            dp[i] = dp[i - 1];
            continue;
        }
        dp[i] = (dp[i - 1] + dp[p[i]]) % mod;
    }
    cout << dp[n];

}


Measured memory_bytes: 6528
require 'set'

loop do
  n = gets.to_i
  break if n==0
  num = Hash.new(0)
  hash = Hash.new{|hash,key| hash[key]=Set.new}
  n.times do
    gets.chomp.split.each do |w|
      num[w]+=1
      hash[w.split("")[0]]<<w
    end
  end
  k = gets.chomp
  if hash[k].empty?
    puts "NA"
    next
  end
  ans = hash[k].sort{|a,b|
    if num[b]!=num[a]
      num[b]-num[a]
    else
      a<=>b
    end}
  if ans.size>=5
    puts ans[0,5].join(" ")
  else
    puts ans.join(" ")
  end
end

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
    ll n;
    cin >> n;

    ll ans = 1000 - n % 1000;
    if (ans == 1000) {
      COUT(0);
    }
    else {
      COUT(1000 - n % 1000);
    }

}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*

3 2
*/


Measured memory_bytes: 3688
import java.util.*;

class Pair implements Comparable {
    int p;
    int y;
    int shiIdx;

    Pair(int p, int y, int shiIdx) {
        this.p = p;
        this.y = y;
        this.shiIdx = shiIdx;
    }

    @Override
    public int compareTo(Object o) {
        Pair other = (Pair) o;
        return this.y - other.y;
    }
}


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

        int N = sc.nextInt();
        int M = sc.nextInt();

        Pair[] pairs = new Pair[M];
        for (int i = 0; i < M; i++) {
            int p = sc.nextInt();
            int y = sc.nextInt();
            pairs[i] = new Pair(p, y, i);
        }

        Arrays.sort(pairs);

        // Map<Integer, Integer> map = new HashMap<>();
        int[] count = new int[N+1];

        String[] ids = new String[M];

        for (int i = 0; i < M; i++) {
            Pair pair = pairs[i];
            count[pair.p]++;
            int num = count[pair.p];

            // pair.pを6桁に変換 + numを6桁に変換 = id
            ids[pair.shiIdx] = String.format("%06d", pair.p) + String.format("%06d", num);
        }

        for (int i = 0; i < M; i++) {
            System.out.println(ids[i]);
        }
    }
}

Measured memory_bytes: 169196
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int q,w;
  char a[100],b;
  cin>>q>>w;
  for(int i=0;i<q;i++){
    cin>>a[i];
  }
  for(int i=0;i<q;i++){
    if(i==w-1){
      a[i]=a[i]+32;
      cout<<a[i];
    }
    else cout<<a[i];
  }
  cout<<"\n";
}


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

int main() {
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(), greater<char>());
  if(s<t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
const ll mod = 1000000000+7;
const int N = 100000+50;

ll dp[100+4][N];
ll w[N],v[N];

ll go(int x,int t){
	if(x==0||t==0)return 0;
	if(dp[x][t]!=-1)return dp[x][t];
	return dp[x][t] = max(go(x-1,t),t>=w[x] ? v[x]+ go(x-1,t-w[x]) : 0);
}

main()
{ 
	SPEED;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n ;
	int W;
	cin >> n >> W;
	memset(dp,-1,sizeof(dp));
	for(int i = 1 ; i <=n ; i++){
		cin >> w[i] >> v[i];
	}
	cout << go(n,W) << endl;
}

Measured memory_bytes: 81536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    for(int i=0;i<3;i++)
    {
        if(s[i]==s[i+1])
        {
            cout<<"Bad";
            return 0;
        }
    }
    cout<<"Good";
    return 0;
}


Measured memory_bytes: 256
n = int(input())

t = [[0] * 10 for _ in range(10)]

for i in range(1,n+1):
    sentou = int(str(i)[0])
    matsubi = int(str(i)[-1])
    t[sentou][matsubi] += 1
    
result = 0
for i in range(10):
    for j in range(10):
        result += t[i][j] * t[j][i]
        
print(result)

Measured memory_bytes: 3064
import collections

N, P = map(int, input().split())
ans = 1

def cal(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n //= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

c = collections.Counter(cal(P)).most_common()

if N == 1:
    print(P)
elif P == 1:
    print(1)
else:
    for x, y in c:
        if y >= N:
            ans *= x**(y//N)
    print(ans)

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

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    int la = ceil(a * 100 / 8.0), ra = ceil((a + 1) * 100 / 8.0);
    auto lb = b * 100 / 10, rb = (b + 1) * 100 / 10;
    auto l = max(la, lb), r = min(ra, rb); 
    cout << (l < r ? l : -1) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n;
  vector<string> b(n);//blue:n, red:m
  for(int i=0;i<n;i++)
    cin >> b.at(i);
  cin >> m;
  vector<string> r(m);//blue:n, red:m
  for(int i=0;i<m;i++)
    cin >> r.at(i);
  
  //blueで+1, redで-1
  //maxを出力すること
  //vector<int> num(n,0);//b(i)を言ったときの金額の合計:num(i) <- bad_allocエラーのため削除
  int x = 0, y;
  for(int i=0;i<n;i++){
    y=0;
    for(int j=0;j<n;j++)
      if(b.at(i) == b.at(j))
        y++;//num.at(i)++;
    for(int j=0;j<m;j++)
      if(b.at(i) == r.at(j))
        y--;//num.at(i)--;
    x = max(x, y);
  }

  cout << x << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


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


int main() {

	ll N;
	cin >> N;

	vector<ll> T(N + 1);
	repn(i, N) cin >> T[i];

	ll ans = 1;

	repn(i, N) ans = lcm(ans, T[i]);

	cout << ans;


	system("PAUSE");

	

}


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

using namespace std;

template<typename T>
class SegTree {
public:
    explicit SegTree(int n, T def) : N(calcN_(n)), def(def), mVal(2*calcN_(n)-1, def) {}
    void update(int idx, T value){
        int i = N + idx - 1;
        update_(mVal[i], value);
        while(i > 0){
            i = (i-1)/2;
            mVal[i] = operate(mVal[2*i+1], mVal[2*i+2]);
        }
    }
    T get(int l, int r){
        l = max(0, l);
        r = min(N, r);
        int offset = N;
        T resL = def;
        T resR = def;
        while(offset > 0){
            if(l >= r) break;
            if(l&1){ resL = operate(resL, mVal[offset+l-1]); l++; }
            if(r&1){ resR = operate(mVal[offset+r-2], resR); }
            l /= 2;
            r /= 2;
            offset /= 2;
        }
        return operate(resL, resR);
    }
private:
    int calcN_(int n){
        int res = 1;
        while(res < n) res *= 2;
        return res;
    }
    void update_(T& data, T val) { data = val; }
    T operate(T a, T b) { return a+b; }
    const int N;
    const T def;
    vector<T> mVal;
};

struct Query {
    explicit Query(int l, int r, int id) : l(l), r(r), id(id){}
    int l, r, id;
    bool operator < (const Query& q) const { return r < q.r; }
};

int main(){
    int N, Q; cin >> N >> Q;
    vector<int> c(N);
    for(auto& t : c){ cin >> t; --t; }
    vector<Query> vq;
    for(int i=0;i<Q;i++){
        int l, r; cin >> l >> r;
        --l;
        vq.emplace_back(l, r, i);
    }
    sort(vq.begin(), vq.end());
    vector<int> res(Q);
    vector<int> last(N, -1);
    int end = 0;
    SegTree<int> seg(N, 0);
    for(auto& q : vq){
        for(int i=end;i<q.r;i++){
            if(last[c[i]] != -1) seg.update(last[c[i]], 0);
            seg.update(i, 1);
            last[c[i]] = i;
        }
        end = q.r;
        res[q.id] = seg.get(q.l, q.r);
    }
    for(auto& t : res) cout << t << endl;
}

Measured memory_bytes: 19524
#include <cstdio>

const int N=105;
bool flag[N];
int a,b,c,num=1;

int main(){
	scanf("%d%d%d",&a,&b,&c);
	while(!flag[a*num%b]){
		flag[a*num%b]=true;
		if(a*num%b==c){
			printf("YES\n");
			return 0;
		}
		num++;
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#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()
const double PI=3.141592653589;
const int INF=1000000007;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);ll c=a%b;while(c!=0){a=b;b=c;c=a%b;}return b;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};


int main(){
  int n; cin>>n;
  ll ans=1;
  rep(i,n){
    ll t; cin>>t;
    ans=ans/gcd(ans,t)*t;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
#ifdef _debug
#define dout(i) cout << #i << ' ' << i
#else 
#define dout(i)
#endif
using ll = long long;
using ull = unsigned long long;
using ul = unsigned;
using db = double;
int v[3];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> v[0] >> v[1] >> v[2];
	sort(v, v + 3);
	// int res = 1 << 29;
	// for(int i = -10;i <= 60;++i){
	// 	int tmp = 0;
	// 	for(int cnt = 0, j = 2;j >= 0;--j){
	// 		if(v[j] < i){
	// 			tmp += (i-v[j])/2;
	// 			if(i-v[j]&1){
	// 				++tmp;
	// 				if(cnt)--cnt;
	// 				else ++cnt, ++tmp;
	// 			}
	// 		}
	// 		else{

	// 		}
	// 	}
	// }
	int res = (v[2]-v[0])/2 + (v[2]-v[1])/2;
	int cnt = (v[2]-v[0]&1) + (v[2]-v[1]&1);
	int ans  = 1 << 29;
	// dout(res) << '\n';
	if(cnt == 2)ans = res + 1;
	if(cnt == 1)ans = res + 2;
	if(cnt == 0)ans = res;
	cout << ans << '\n';
}

Measured memory_bytes: 256
/// @file wsap.cc
/// @brief wsap の実装ファイル
/// @author Yusuke Matsunaga (松永 裕介)
///
/// Copyright (C) 2019 Yusuke Matsunaga
/// All rights reserved.


#include <vector>
#include <string>
#include <iostream>

using namespace std;

int
z_algorithm(const string& s,
	    int base)
{
  int n = s.size() - base;
  vector<int> Z(n);
  Z[0] = n;
  int i = 1;
  int j = 0;
  int max_val = 0;
  while ( i < n ) {
    while ( (i + j) < n && s[base + j] == s[base + i + j] ) {
      ++ j;
    }
    Z[i] = j;
    if ( j == 0 ) {
      ++ i;
    }
    else {
      if ( j <= i && max_val < j ) {
	max_val = j;
      }
      int k = 1;
      while ( (i + k) < n && k + Z[k] < j ) {
	Z[i + k] = Z[k];
	++ k;
      }
      i += k;
      j -= k;
    }
  }

  return max_val;
}

int
main(int argc,
     char** argv)
{
  int n;
  cin >> n;

  string s;
  cin >> s;

  int max_len = 0;
  for ( int i = 0; i < n; ++ i ) {
    int val = z_algorithm(s, i);
    if ( max_len < val ) {
      max_len = val;
    }
  }
  cout << max_len << endl;
}


Measured memory_bytes: 504
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse import csr_matrix

import numpy as np

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

a = np.array(a)

g = csr_matrix(a)
dist = floyd_warshall(g)

bl = dist == a

if bl.all():
    sm = dist.sum()
    INF = 10 ** 18 + 1
    inf = np.array([INF] * n)
    inf = np.diag(inf)
    dist += inf
    for u in range(n):
        for v in range(n):
            if u == v:
                continue

            mn = np.min(dist[u] + dist[v])
            if mn == dist[u, v]:
                sm -= dist[u, v]

    ans = int(sm) // 2
    print(ans)

else:
    print(-1)


Measured memory_bytes: 21376
#include <stdio.h>
int main(void)
{
    
    int H, W,i,j;
    while(1){
    scanf("%d %d",&H,&W);
    if(H==0&&W==0)
    break;
    
    
    for(i=1;i<=H;i++){
        for(j=1;j<=W;j++){
            if(i>1&&i<H&&j<W&&j>1)
            printf(".");
            else
            printf("#");
            }printf("\n");
            }printf("\n");
        }
    return 0;
}



Measured memory_bytes: 1980
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define mp make_pair
#define inf 1000000007
#define int long long
using namespace std;
vector<int> p[214514];
int iro[214514];
signed main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x,y;
		cin>>x>>y;
		y+=100000;
		p[x-1].pb(y-1);
		p[y-1].pb(x-1);
	}
	ll ans = -n;
	for(int i=0;i<200000;i++){
		if(iro[i]==0){
			iro[i]=1;
			int cx=0,cy=0;
			queue<int> que;
			que.push(i);
			if(i<100000)cx++;else cy++;
			while(!que.empty()){
				int ci = que.front();que.pop();
				for(int j=0;j<p[ci].size();j++){
					int cd = p[ci][j];
					if(iro[cd]==0){
						iro[cd]=1;
						if(cd<100000)cx++;else cy++;
						que.push(cd);
					}
				}
			}
			ans += cx*cy;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10496
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int len;
char c[1005];
int main(){
	scanf("%s",c+1);
	len=strlen(c+1);
	if(c[len]=='s') c[len+1]='e',c[len+2]='s';
	else c[len+1]='s';
	printf("%s\n",c+1);
	return 0;
}


Measured memory_bytes: 1648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
//#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n; cin >> n;
    VI a(n); cin >> a;

    int Min = INF, itr = -1;
    FOR(i, 0, n)if (chmin(Min, a[i]))itr = i;
    cout << itr + 1 << "\n";
}



Measured memory_bytes: 3368
#include <bits/stdc++.h>
using namespace std;
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto x:v)cerr<<x<<' ';cerr<<endl;
#define INF 1000000007
#define LINF 1000000000000000007
#define EPS 1e-9
typedef long long ll;
 
signed main(){
  vector<pair<ll,ll>> vw1,vw2;
  vector<pair<ll,ll>> VW1,VW2;//2^20
  ll N,W;
  cin >> N >> W;
  ll v,w;
  if(N == 1){
    cin >> v >> w;
    if(w <= W){
      cout << v << endl;
    }
    else cout << 0 << endl;
    return 0;
  }
  FOR(i,0,N/2){
    cin >> v >> w;
    vw1.pb(make_pair(w,v));
  }
  FOR(i,0,(N+1)/2){
    cin >> v >> w;
    vw2.pb(make_pair(w,v));
  }
  VW1.pb(make_pair(0,0));
  VW2.pb(make_pair(0,0));
  FOR(i,0,vw1.size()){
    REP(j,0,VW1.size()){
      VW1.pb(make_pair(VW1[j].first+vw1[i].first,VW1[j].second+vw1[i].second));
    }
  }
  FOR(i,0,vw2.size()){
    REP(j,0,VW2.size()){
      VW2.pb(make_pair(VW2[j].first+vw2[i].first,VW2[j].second+vw2[i].second));
    }
  }
  sort(ALL(VW1));
  sort(ALL(VW2));
  map<ll,ll> m;
  vector<pair<ll,ll>> vvww;
  ll yay = -1;
  for(auto p:VW2){
    if(p.second > yay){
      vvww.pb(p);
      yay = p.second;
    }
  }
  ll ans = 0;
  for(auto p:VW1){
    if(p.first <= W){
      ans = max((*(upper_bound(ALL(vvww),make_pair(W-p.first,(ll)LINF))-1)).second+p.second,ans);
    }
  }
  cout << ans << endl;
}


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

using namespace std;

//int dirs[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
//int dirs[8][2]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};


void infinity()
{
    cout << "infinity" << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    //freopen("inp.in","r",stdin);
    //freopen("outp.out","w",stdout);
    long long T1, T2;
    long long A1, A2;
    long long B1, B2;
    cin >> T1 >> T2;
    cin >> A1 >> A2;
    cin >> B1 >> B2;
    if(A1==B1)
    {
        infinity();
        return 0;
    }
    if(A1*T1+A2*T2==B1*T1+B2*T2)
    {
        infinity();
        return 0;
    }
    long long dist1=A1*T1-B1*T1;
    long long dist2=(A1*T1+A2*T2)-(B1*T1+B2*T2);
    if(dist1>0 && dist2>0)
    {
        cout << 0 << endl;
        return 0;
    }
    else if(dist1<0 && dist2<0)
    {
        cout << 0 << endl;
        return 0;
    }
    if(dist1<0) dist1*=-1;
    if(dist2<0) dist2*=-1;
    dist2+=dist1;
    long long stap=dist2-dist1;
    long long ans=2*(dist1/stap);
    long long x=dist1%stap;
    if(x>0) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
//#include <unistd.h>
//#include <iostream>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
//#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();   
    int a, b;
    cin >> a >> b;
    rep1 (x, 1000) {
        int y = x * 0.08;
        int z = x * 0.1;
        if (a == y and b == z) {
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int a,b;
	cin >> a >> b;
	if(a>=b){
		for (int i = 0; i < a; ++i) {
			cout << b;
		}
		cout<<endl;
	}else{
		for (int i = 0; i < b; ++i) {
			cout << a;
		}
		cout<<endl;
	}
	return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N, L; cin >> N >> L;
	vector< string > str(N);
	for_(i,0,N) cin >> str[i];
	sort(str.begin(), str.end());
	for_(i,0,N) printf("%s", str[i].c_str());
	puts("");
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		if(x==3 || x==5 || x==7) {
			System.out.println("YES");
		}else {
			System.out.println("NO");
		}

	}

}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl


int main() {
    int N, M;  cin >> N >> M;
    vector<int> L(M);
    vector<int> R(M);
    rep(i, M) cin >> L[i] >> R[i];

    sort(all(L));
    sort(all(R));
    int ans = R[0] - L[L.size()-1] + 1;

    if (ans >= 0) print(ans);
    else print(0);

}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int a=0;
	for(int i=0; i < s.size(); i++)
	{
		if(s[i]=='+')
			a++;
		else
			a--;
	}
	cout<<a<<endl;
	return 0;
}


Measured memory_bytes: 3624
# 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1246588#1

while True:
	try:
		p, q = (int(x) for x in input().split())
		m = p % q
		i = -1
		decs = ['']
		mods = [m]
		while m != 0:
			d, m = divmod(m * 10, q)
			decs.append(str(d))
			if m not in mods:
				mods.append(m)
			else:
				i = mods.index(m)
				break
		if len(decs) == 0:
			print(0)
		else:
			print(''.join(decs))
			if m != 0 and i > -1:
				for j, dec in enumerate(decs):
					if j > i:
						decs[j] = '^' * len(decs[j])
					else:
						decs[j] = ' ' * len(decs[j])
				print(''.join(decs))
	except:
		break


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, a;
	cin >> n >> a;

	int s = n % 500;

	if (s <= a) out("Yes");
	else out("No");

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int K;
string S;

int main(){
    cin >> K;
    cin >> S;

    string ans = "";

    //cout << "S:" << S.length() << endl;
    //cout << "K:" << K << endl;

    if(S.length() > K){
        for(int i = 0;i < K;i++){
            ans += S[i];
        }
        ans += "...";
    }else{
        ans = S;
    }

    cout << ans << endl;

    
}

Measured memory_bytes: 3636
#include<stdio.h>
  
#define N 8
#define free -1
#define notfree 1
#define FALSE 2
#define TRUE 3
  
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];
int X[N][N];
  
void initialize(void);
void printboard(void);
void recursive(int);
  
void initialize(){
  int i;
  
  for(i=0;i<N;i++){
    row[i] = free;
    col[i] = free;
  }
  
  for(i=0;i<2*N-1;i++){
    dpos[i] = free;
    dneg[i] = free;
  }
}
  
void printboard(){
  int i,j;
  
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      if(X[i][j] == TRUE){
    if(row[i] != j)return;
      }
  
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i] == j)printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}
  
void recursive(int i){
  int j;
  
  if(i == N){
    printboard();
    return;
  }
  
  for(j=0;j<N;j++){
    if(notfree == col[j] || notfree == dpos[i+j] || notfree == dneg[i-j+N-1])continue;
    row[i] =j;
    col[j] = dpos[i+j] = dneg[i-j+N-1] = notfree;
    recursive(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+N-1] = free;
  }
}
int main(){
  int i,j,k,r,c;
  
  initialize();
  
  for(i=0;i<N;i++)
    for(j=0;j<N;j++)
      X[i][j] = FALSE;
  
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    X[r][c] = TRUE;
  }
  
  recursive(0);
  
  return 0;
}

Measured memory_bytes: 572
#include <cstdio>
#include <iostream>
#include <sstream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int count=0;
	for(int i=a;i<=b;i++)
	{
		stringstream ss;
		string s;
		ss<<i;
		ss>>s;
		int l=s.length();
		string s1;
		//cout<<s<<endl;
		for(int i=0;i<l;i++)
		{
			//cout<<s[l-i-1]<<endl;
			s1[i]=s[l-i-1];
			//cout<<s1[i]<<endl;
		}
		int j=0;
		for(j=0;j<l;j++)
		{
			if(s[j]==s1[j]) continue;
			else break;
		}
		if(j==l) count++;
		else continue;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
using namespace std;
int main() {
	int a, b;
	int r;
	char op;
	while(true) {
		scanf("%d %c %d", &a, &op, &b);
		if (op == '?') {
			break;
		} else if (op == '+') {
			r = a+b;
		} else if (op == '-') {
			r = a-b;
		} else if (op == '*') {
			r = a * b;
		} else if (op == '/') {
			r = a/b;
		}
		printf("%d\n", r);
	}
}


Measured memory_bytes: 2748
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll h,w; cin>>h>>w; 
    char arr[h+1][w+1]; ll dp[h+1][w+1];
    memset(dp,0,sizeof(dp));
    for(ll i=1;i<=h;i++)
    {
     for(ll j=1;j<=w;j++)
     {
      cin>>arr[i][j];
       if(arr[i][j]=='#')
       {
         dp[i][j]=-1;
       }
     }
    }
    for(ll i=1;i<=w;i++)
    {
     if(dp[1][i]==0) dp[1][i]=1;
      else break;
    }
    for(ll i=2;i<=h;i++)
    {
     if(dp[i][1]==0) dp[i][1]=1;
      else break;
    }
    for(ll i=2;i<=h;i++)
    {
     for(ll j=2;j<=w;j++)
     {
       if(dp[i][j]!=-1)
       {
         if(dp[i-1][j]>0) dp[i][j]=(dp[i][j]+dp[i-1][j])%M;
         if(dp[i][j-1]>0) dp[i][j]=(dp[i][j]+dp[i][j-1])%M;
       }
     }
    }
    cout<<dp[h][w];
    return 0;
}


Measured memory_bytes: 12312
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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; }

int n;
vector<int> h;
vector<int> dp;

int main(){
    cin >> n;
    h.resize(n); dp.resize(n, -1);
    rep(i, n) cin >> h[i];

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for(int i = 2; i < n; i ++){
        int one = dp[i-1] + abs(h[i] - h[i-1]);
        int two = dp[i-2] + abs(h[i] - h[i-2]);
        dp[i] = min(one, two);
    }

    cout << dp[n-1] << ln;
}

Measured memory_bytes: 1024
import java.io.PrintWriter
import scala.io.StdIn._
object Main extends App {
  val n = readInt
  var map = Map[String, Int]()

  for (_ <- 1 to n) {
    val s = readLine
    map.get(s) match {
      case Some(i) => map = map + (s -> (i + 1))
      case None    => map = map + (s -> 1)
    }
  }
  val m = map.toSeq.sortWith(_._2 > _._2)
  val max = m.head._2

  val pw = new PrintWriter(System.out)
  m.collect { case v if v._2 == max => v._1 }.sorted.foreach(pw.println(_))
  pw.flush()
}


Measured memory_bytes: 111380
import java.util.*;

class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int r=sc.nextInt();
    int d=sc.nextInt();
    int w=sc.nextInt();
    int a[]=new int[11];
    for(int i=0;i<11;i++){
      a[i]=w;
      w*=r;
      w-=d;
    }
    for(int i=1;i<=10;i++){
      System.out.println(a[i]);
    }
  }
}

Measured memory_bytes: 21844
import Control.Applicative

type Dice
    = [Int]

type Problem
    = (Dice, Dice)

type Result
    = Bool

roll :: Dice -> String -> Dice

roll dice []
    = dice

roll [s1, s2, s3, s4, s5, s6] (char:string)
    = case char of
        'N' -> roll [s2, s6, s3, s4, s1, s5] string
        'S' -> roll [s5, s1, s3, s4, s6, s2] string
        'E' -> roll [s4, s2, s1, s6, s5, s3] string
        'W' -> roll [s3, s2, s6, s1, s5, s4] string
        'C' -> roll [s1, s3, s5, s2, s4, s6] string

equal :: Dice -> Dice -> Bool

equal dice1 dice2
    = and $ zipWith (==) dice1 dice2
    
rollTo :: Int -> Dice -> [Dice]

rollTo s dice@[s1, s2, s3, s4, s5, s6]
    = filter (/= []) [case1, case2, case3, case4, case5, case6] where
        case1 = if s == s1 then roll dice "" else []
        case2 = if s == s2 then roll dice "N" else []
        case3 = if s == s3 then roll dice "W" else []
        case4 = if s == s4 then roll dice "E" else []
        case5 = if s == s5 then roll dice "S" else []
        case6 = if s == s6 then roll dice "NN" else []
        
spinTo :: Int -> Dice -> [Dice]

spinTo s dice@[_, s2, s3, s4, s5, _]
    = filter (/= []) [case2, case3, case4, case5] where
        case2 = if s == s2 then roll dice "" else []
        case3 = if s == s3 then roll dice "C" else []
        case4 = if s == s4 then roll dice "CCC" else []
        case5 = if s == s5 then roll dice "CC" else []

solve :: Problem -> Result

solve (dice1@(top:front:_), dice2)
    = any (equal dice1) spuns where
        rolleds = rollTo top dice2
        spuns = concatMap (spinTo front) rolleds

output :: Result -> String

output bool
    = if bool then "Yes" else "No"
    
input :: IO Problem

input
    = do
        dice1 <- map read <$> words <$> getLine
        dice2 <- map read <$> words <$> getLine
        return (dice1, dice2)

main :: IO ()

main
    = putStrLn <$> output =<< solve <$> input

Measured memory_bytes: 3704