akhauriyash/Code-Regression huggingface dataset:
S=input()
N=len(S)

idx=N-1
ans="YES"
while idx>=0:
    now=S[idx]
    if now=="m":
        if S[idx-4:idx+1]!="dream":
            ans="NO"
            break
        else:idx-=5
    elif now=="e":
        if S[idx-4:idx+1]!="erase":
            ans="NO"
            break
        else:idx-=5
    elif now=="r":
        if S[idx-5:idx+1]=="eraser":
            idx-=6
        elif S[idx-6:idx+1]=="dreamer":
            idx-=7
        else:
            ans="NO"
            break
print(ans)

Measured memory_bytes: 9196
import sys
input=sys.stdin.readline
class LCA:
  def __init__(self,n,s,edge):
    self.logn=n.bit_length()
    self.parent=[n*[-1]for _ in range(self.logn)]
    self.dist=[0]*n
    stack=[s]
    visited={s}
    for i in stack:
      for j in edge[i]:
        if j in visited:continue
        stack.append(j)
        visited.add(j)
        self.parent[0][j]=i
        self.dist[j]=self.dist[i]+1
        for k in range(1,self.logn):self.parent[k][j]=self.parent[k-1][self.parent[k-1][j]]
  def query(self,a,b):
    if self.dist[a]<self.dist[b]:a,b=b,a
    if self.dist[a]>self.dist[b]:
      for i in range(self.logn):
        if (self.dist[a]-self.dist[b])&(1<<i):a=self.parent[i][a]
    if a==b:return a
    for i in range(self.logn-1,-1,-1):
      if self.parent[i][a]!=self.parent[i][b]:
        a=self.parent[i][a]
        b=self.parent[i][b]
    return self.parent[0][a]
  def path_range(self,a,b):return self.dist[a]+self.dist[b]-2*self.dist[self.query(a,b)]
  def x_in_abpath(self,x,a,b):return self.path_range(a,x)+self.path_range(b,x)==self.path_range(a,b)
n=int(input())
edge=[[]for _ in range(n)]
for i in range(n):
  k=list(map(int,input().split()))
  for j in range(k[0]):edge[i].append(k[j+1])
lca=LCA(n,0,edge)
q=int(input())
for u,v in [list(map(int,input().split()))for _ in range(q)]:
  print(lca.query(u,v))


Measured memory_bytes: 54152
n, m = map(int, input().split())
a_mtx = []
for i in range(n):
    a_mtx.append(list(map(int, input().split())))
b_mtx = []
for j in range(m):
    b_mtx.append(int(input()))

c_mtx = []
for a in a_mtx:
    accu = 0
    for b, c in zip(a, b_mtx):
        accu += b*c
    c_mtx.append(accu)

for cc in c_mtx:
    print(cc)


Measured memory_bytes: 6012
s = input()

l = len(s)
cent = int((l - 1) / 2)

# 1
for i in range(cent):
    if s[i] != s[l-i-1]:
        print('No')
        exit(0)

# 2
for i in range(cent//2):
    if s[i] != s[cent - i - 1] or s[cent + 1 + i] != s[l-i-1]:
        print('No')
        exit(0)

print('Yes')

Measured memory_bytes: 3060
#include<stdio.h>
int main(void){

    int n,x;
    int i,j,k;
    int b;

    while(1){
        scanf("%d %d",&n,&x);
        if(n==0 && x==0){
            break;
        }
        b=0;
        for(i=1;i<=n;i++){
            for(j=i+1;j<=n;j++){
                for(k=j+1;k<=n;k++){
                        if(i+j+k==x){
                            b++;
                        }
                }
            }
        }
         printf("%d\n",b);
    }
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int a, b;

int main()
{
    cin>>a>>b;
    FOR(i,1,1251) {
        if ((int)(i / 100.0 * 8) == a && (int)(i / 100.0 * 10) == b) {
            cout<<i<<endl;
            exit(0);
        }
    }
    cout<<-1<<endl;

    return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int c = a * b;
  if (c % 2 == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	string s,r;
	int ans = 0;
	cin >> s;
	r = s;
	reverse(r.begin(),r.end());
	rep(i,s.size() / 2) {
		if (s.at(i) != r.at(i)) {
			ans++;
		}
	}

	cout << ans;
	
}

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

#include <unistd.h>
 
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 ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx_ori[4] = { -1,0, 1,0 }, dy_ori[4] = { 0,1,0,-1 };
int dx[4] = {0, 0, 0, 0}, dy[4] = {0, 0, 0, 0};
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


signed main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  string t;
  rep (i, s.size()) {
    int now = s[i] - 'A';
    now = (now + n) % 26;
    t += 'A' + now;
  }
  cout << t << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

  unsigned long long x,y;
  cin >> x >> y;
  if (x % y == 0 || y == 1) {
    cout << -1 << endl;
    return 0;
  }

  unsigned long long maxNum = 1000000000000000000;

  for (unsigned long long i = 1; i * x <= maxNum; ++i) {
    if ((i * x) % y != 0) {
      cout << x << endl;
      return 0;
    }
  }

  cout << -1 << endl;
}

Measured memory_bytes: 3620
object Main extends App {
  import scala.io.StdIn._

  val suspects = readLine.trim
  val index = suspects.indexWhere(_ == '?')
  val correct = ('0' to '9').filter(c ⇒ isValid(suspects.updated(index, c)))
  println(if (correct.length > 1) "MULTIPLE" else correct.head)
  def isValid(suspects: String): Boolean = {
    val q = (1 to 11).map(n ⇒ if (1 <= n && n <= 6) n + 1 else n - 5)
    val checkDigit = suspects.last.asDigit
    checkDigit == (q.zip(suspects.reverse.tail).map(it ⇒ it._1 * it._2.asDigit).sum % 11).let(i ⇒ if (i <= 1) 0 else 11 - i)
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline def let[A](@inline func: T ⇒ A): A = func(value)
  }
}


Measured memory_bytes: 45240
/*
     “You just can’t beat the person who won’t give up.”
                                                            */
#include <bits/stdc++.h>
#define ll long long
#define oo 0x3f3f3f3f3f3f3f3fLL
#define lp(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
const int maxn=2e5+5;
const  double EPS = 1e-9;
const int mod = 1e9+7;

inline void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}

int main()
{
    ios_base::sync_with_stdio(0);
    File();
    ll a,b,g;
    vector<ll>ans;
    cin>>a>>b;
    g=__gcd(a,b);
    for(ll i=2LL; i*i<=g; i++)
        if(g%i==0)
        {
            ans.pb(i);
            while(g%i==0)
                g/=i;
        }
    if(g>1)
        ans.pb(g);
    cout<<sz(ans)+1;
}


Measured memory_bytes: 3656
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


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

  vector<int> p(n);
  int ans=50000000;
  rep(i,n){
  cin>>p[i];
  }
  
  for(int i=-100;i<=100;i++){
    int sum=0;
    rep(j,n){
    sum+=(i-p[j])*(i-p[j]);
    }
    ans=min(ans,sum);
  }
  
  cout << ans << endl;
  
}


Measured memory_bytes: 256
from collections import deque
S = list(input())
s = deque(S)
Q = int(input())
t = 0
for i in range(Q):
    qi = input()
    if qi == "1":
        t += 1
    else:
        qi = list(qi)
        if (int(qi[2])+t) % 2 ==0:
            s.append(qi[4])
        else:
            s.appendleft(qi[4])

s = list(s)
if t % 2 == 1:
    ans = [[] for j in range(len(s))]
    for i in range(len(s)):
        ans[i] = s[len(s)-i-1]
else:
    ans = s

print("".join(ans))

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

int main()
{
    long long a,b,n,p,q,ans=0;
    cin>>a>>b>>n;
    q=b/n;
    b=q*n;
    if(a==0) a=0;
    else if(a<=n) a=n;
    else if(a%n==0)  a=a;
    else
    {
      p=a/n;
      a=n*(p+1);
    }
    ans=((b-a)/n)+1;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3600
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(m)]
for i in range(n):
    mindis = 10 ** 9
    for j in range(m):
        dis = abs(s[i][0] - p[j][0]) + abs(s[i][1] - p[j][1])
        if mindis > dis:
            point = j+1
            mindis = dis
    print(point)

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  vector<pair<int, P>> d = {pair<int, P>(1, P(0, 0)),
                            pair<int, P>(0, P(1, 0)),
                            pair<int, P>(0, P(0, 1)),
                            pair<int, P>(1, P(1, 0)),
                            pair<int, P>(1, P(0, 1)),
                            pair<int, P>(0, P(1, 1)),
                            pair<int, P>(1, P(-1, 0)),
                            pair<int, P>(1, P(0, -1)),
                            pair<int, P>(0, P(1, -1)),
                            pair<int, P>(1, P(1, 1)),
                            pair<int, P>(1, P(1, -1)),
                            pair<int, P>(1, P(-1, 1)),
                            pair<int, P>(1, P(-1, -1))};

  while(1) {
    int n, m, p; cin >> n >> m >> p;
    if(n == 0) break;
    vector<vector<vector<int>>> g(n);
    REP(i, n) {
      g[i].resize(n);
      REP(j, n) {
        g[i][j].resize(n, 0);
      }
    };
    vi xv(p), yv(p);
    REP(i, p) {
      cin >> xv[i] >> yv[i];
      xv[i]--;
      yv[i]--;
    }
    REP(i, p) {
      int x = xv[i], y = yv[i];
      RFOR(j, n-1, 1) {
        if(g[x][y][j-1] != 0) {
          g[x][y][j] = ((i%2) ? 1 : -1);
          break;
        }
        if(j == 1) g[x][y][0] = ((i%2) ? 1 : -1);
      }
      int ma = 0;
      REP(j, n) {
        REP(k, n) {
          REP(l, n) {
            int col = g[j][k][l];
            if(col == 0) continue;
            REP(s, SZ(d)) {
              int dx = d[s].fi, dy = d[s].se.fi, dz = d[s].se.se;
              int nowj = j+dx, nowk = k+dy, nowl = l+dz;
              int cnt = 1;
              while(0 <= nowj && nowj < n &&
                    0 <= nowk && nowk < n &&
                    0 <= nowl && nowl < n) {
  
                if(g[nowj][nowk][nowl] == col) {
                  cnt++;
                  nowj += dx;
                  nowk += dy;
                  nowl += dz;
                } else {
                  break;
                }
              }
              ma = max(ma, cnt);
            }
          }
        }
      }
      // cout << i << ":" << ma << endl;
      if(ma >= m) {
        cout << ((i%2) ? "White " : "Black ") << i+1 << endl;
        break;
      }
      if(i == p-1) {
        cout << "Draw" << endl;
      }
    }
  }
}



Measured memory_bytes: 3028
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;




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









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

int main()
{
	ll x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	ll i,p;

	priority_queue <ll> r, g, col;
	for(i=0;i<a;i++)
	{
		cin>>p;
		r.push(p);
	}
	for(i=0;i<b;i++)
	{
		cin>>p;
		g.push(p);
	}
	for(i=0;i<c;i++)
	{
		cin>>p;
		col.push(p);
	}

    ll rt, gt, colt ;
	ll sum = 0;
	ll left = 0;
	while(x >= 0 && y>=0)
	{
		if(x+ y == left)
			break;
		if(x>0 && r.size() > 0)
		{
			rt = r.top();
		}
		else
		{
			rt = 0;
		}
		if(y > 0 && g.size() > 0)
		{
			gt = g.top();
		}
		else
		{
			gt = 0;
		}
		if(col.size() > 0)
			colt = col.top();
		else
			colt = 0;
		if(rt > gt)
		{
			if(rt > colt)
			{
				sum += rt;
				x--;
				r.pop();
			}
			else
			{
				sum+= colt;
				col.pop();
				left++;
			}
		}
		else 
		{
			if(gt > colt)
			{
				sum+= gt;
				y--;
				g.pop();
			}
			else
			{
				sum+= colt;
				col.pop();
				left++;
			}
		}
	}

	cout<<sum<<endl;


	   



      

	
	return 0;
}


Measured memory_bytes: 3316
while True:
    h,w = map(int, input().split())
     
    if h == 0 and w == 0:
        break
    for i in range(h):
        if i == 0 or i == h - 1:
            print('#' * w)
        else:
            print('#' + '.' * (w - 2) + '#')
    print()


Measured memory_bytes: 5608
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
const in mdl=1000000007;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in w=1;
  in n;
  cin>>n;
  in x;
  in inq=0;
  forn(z,n){
    cin>>x;
    if(x<=inq*2){
      w=w*(inq+1)%mdl;
      continue;
    }
    ++inq;
  }
  while(inq>=1){
    w=w*inq%mdl;
    --inq;
  }
  cout<<w<<endl;
  return 0;
}


Measured memory_bytes: 384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CSccPuzzle solver = new CSccPuzzle();
        solver.solve(1, in, out);
        out.close();
    }

    static class CSccPuzzle {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long s = in.nextLong();
            long c = in.nextLong();

            // C二個でSを作れるので…
            // まずsを使いきれるか
            if (s * 2 <= c) {
                long ans = s;
                c -= s * 2;
                out.println(ans + c / 4);
            } else {
                out.println(c / 2);
            }

        }

    }
}



Measured memory_bytes: 21460
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
	crap;

	int k;
	cin >> k;

	string str;
	cin >> str;

	int n = str.length();
	if (n <= k) {
		cout << str << endl;
	} else {
		cout << str.substr(0, k) + "..." << endl;
	}

	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        string si = to_string(i);
        int count = 0;
        for(int j = 0; j < si.size(); j++){
            count += si[j] - '0';
        }
        if(a <= count && count <= b) ans += i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import exp, ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, e
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
import random
import time
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

start = time.time()

D = INT()
C = LIST()
s = [LIST() for _ in range(D)]

def decrease(d, j):  # d:日にち, j:開催するコンテスト
    tmp = 0
    for i in range(26):
        if i == j: continue
        tmp += C[i]*(d-last[i])
    return tmp 

def init():  # 貪欲でとった解を1度保存する
    global now
    for i in range(D):  # i+1日目
        ma = -INF
        ma_idx = None
        for j in range(26):  # 開催するコンテスト
            tmp = now
            tmp += s[i][j]
            tmp -= decrease(i+1, j)
            if tmp > ma:
                ma = tmp
                ma_idx = j
        now = ma
        last[ma_idx] = i+1
        score[ma_idx] += s[i][ma_idx]
        for j in range(26):
            score[j] -= C[j]*(i+1-last[j])
        last[ma_idx] = i+1
        ans[i] = ma_idx+1

def update(d, q):  # d日目のところをqに変更する
    d -= 1
    q -= 1
    c = ans[d]-1  # c:更新前
    ans[d] = q+1
    last_c = 0
    last_q = 0
    score_c = 0
    score_q = 0
    for j in range(D):
        if ans[j]-1 == c:
            last_c = j+1
            score_c += s[j][c]
        elif ans[j]-1 == q:
            last_q = j+1
            score_q += s[j][q]
        score_c -= C[c] * (j+1 - last_c)
        score_q -= C[q] * (j+1 - last_q)
    score[c] = score_c
    score[q] = score_q

def swap(d):  # d日目とd+1日目の開催を入れ替える
    update(d, ans[d])
    update(d+1, ans[d-1])

ans = [0]*D
last = [0]*26
score = [0]*26
now = 0

init()

TL = 1.8 - (time.time()-start)
start = time.time()
T0 = 2e3
T1 = 6e2
T = T0
randint = random.randint
rand = random.random
while 1:
    t = (time.time()-start)/TL
    if t >= 1:
        break
    T = pow(T0, 1-t)*pow(T1, t)
    if rand() < 0.5:  # 1点変更
        d = randint(1, D)
        q = randint(1, 26)
        old = ans[d-1]
        old_score = score.copy()
        s_old = sum(score)
        update(d, q)
        s_new = sum(score)
        if s_new <= s_old and exp((s_new-s_old)/T) <= rand():  # 戻す確率
            score = old_score
            ans[d-1] = old
    else:  # 2点入れ替え
        d = randint(1, D-1)
        old = ans[d-1]
        old_score = score.copy()
        s_old = sum(score)
        swap(d)
        s_new = sum(score)
        if s_new <= s_old and exp((s_new-s_old)/T) <= rand():
            score = old_score
            ans[d-1] = old

print(*ans, sep="\n")


Measured memory_bytes: 90620
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, tmp;
    cin >> n;
    int a[100000] = {0};
    for ( int i = 0 ; i < n ; i++ ) {
        cin >> tmp;
        if ( tmp > 0 ) {
            a[tmp - 1]++;
        }
        a[tmp]++;
        a[tmp + 1]++;
    }
    int c = 0;
    for ( int i = 0 ; i < 100000 ; i++ ) {
        c = max( a[i] , c );
    }
    cout << c;
}





Measured memory_bytes: 640
l,r=map(int,input().split())
a=[]
b=[]
if r-l>=2018:
  print(0)
else:
  for i in range(0,r-l+1):
    a.append((l+i)%2019)
  
  for j in range(0,r-l):
    for k in range(j+1,r-l+1):
      b.append((a[j]*a[k])%2019)
      
  print(min(b))    
    


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

int main() {
    int N;
    cin >> N;
    vector<long long int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    long long int ans = 1;
    long long int prev = 1;
    for(int i = 0; i < N; i++) {
        if(A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i = 0; i < N; i++) {
        if(A[i] <= 1000000000000000000/ans) {
            ans *= A[i];
        } else {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3988
h, n = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(n)]
A = [a for a, b in AB]
B = [b for a, b in AB]
inf = 10**10
# DP[i][j]=i個以内で体力j以上削るための消費魔力の最小値
DP = [[inf for j in range(h+1)] for i in range(n+1)]
DP[0][0] = 0
for i in range(1, n+1):
    for j in range(h+1):
        DP[i][j] = min(DP[i-1][j], DP[i][max(0, j-A[i-1])]+B[i-1])
print(DP[n][h])


Measured memory_bytes: 125404
from itertools import combinations

n = int(input())
lst = list(map(int, input().split()))
comb = combinations(lst, 3)
count = 0

for i in comb:
  if i[0] != i[1] and i[1] != i[2] and i[0] != i[2]:
    if i[0] + i[1] > i[2] and i[1] + i[2] > i[0] and i[0] + i[2] > i[1]:
      count += 1
    
print(count)

Measured memory_bytes: 9128
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <algorithm>
#include <unordered_map>

#define rep(i, a, b) for (ll i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef unordered_map<string, ll> u_map;

// input
void input() {}
template <class Head, class... Tail>
void input(Head &&a, Tail &&... b)
{
    cin >> a;
    input(forward<Tail>(b)...);
}

template <class V>
void input(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &i) { input(i); });
}

// output
template <class V>
void output(vector<V> &v)
{
    for_each(v.begin(), v.end(), [](auto &x) { cout << x << " "; });
    cout << endl;
}

// math functions
ll mpow(ll a, ll n, ll p)
{
    ll x = 1;
    while (n > 0)
    {
        if (n & 1)
        {
            x = a * x % p;
        }
        a = a * a % p;
        n >>= 1;
    }

    return x;
}

ll mfact(ll n, ll p)
{
    ll res = 1;
    for (ll i = 2; i <= n; i++)
    {
        res = res * i % p;
    }
    return res;
}

ll mcomb(ll n, ll r, ll p)
{
    if (n == 0 && r == 0)
    {
        return 1;
    }
    if (n < r || n < 0 || r < 0)
    {
        return 0;
    }

    ll a = mfact(n, p);
    ll b = mfact(n - r, p);
    ll c = mfact(r, p);
    return (((a * mpow(b, p - 2, p)) % p) * mpow(c, p - 2, p)) % p;
}

ll gcd(ll a, ll b)
{
    if (a < b)
    {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    return b ? gcd(b, a % b) : a;
}

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

int main()
{
    string S, T;
    input(S, T);

    ll res = 0;
    rep(i, 0, S.size())
    {
        if (S[i] != T[i])
        {
            res++;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3848
#include "bits/stdc++.h"
 
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<VVLL> VVVLL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
 
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;
 
 
//debug func
template<typename T>
void vecprint(vector<T> v) {
    for(auto x : v) {
        cerr << x << " ";
    }
    cerr << endl;
}
 
template<typename T>
void vecvecprint(vector<vector<T>> v) {
    for(auto x :v) {
        REP(i, x.size()-1) {
            cerr << x[i] << " ";
        }
        cerr << x[x.size()-1] <<endl;
    }
}
 
template<typename T>
void pqprint(priority_queue<T> q) {
    while(!q.empty()) {
        cerr << q.top() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void qprint(queue<T> q) {
    while(!q.empty()) {
        cerr << q.front() << " ";
        q.pop();
    }
    cerr << endl;
}
 
template<typename T>
void vecqprint(vector<queue<T>> v) {
    for(int i = 0; i < v.size(); i++) {
        qprint(v[i]);
    }
}
 
template <typename Iterator>
inline bool next_combination(const Iterator first, Iterator k, const Iterator last)
{
   /* Credits: Thomas Draper */
   if ((first == last) || (first == k) || (last == k))
      return false;
   Iterator itr1 = first;
   Iterator itr2 = last;
   ++itr1;
   if (last == itr1)
      return false;
   itr1 = last;
   --itr1;
   itr1 = k;
   --itr2;
   while (first != itr1)
   {
      if (*--itr1 < *itr2)
      {
         Iterator j = k;
         while (!(*itr1 < *j)) ++j;
         iter_swap(itr1,j);
         ++itr1;
         ++j;
         itr2 = k;
         rotate(itr1,j,last);
         while (last != j)
         {
            ++j;
            ++itr2;
         }
         rotate(k,itr2,last);
         return true;
      }
   }
   rotate(first,k,last);
   return false;
}

inline double get_time_sec(void){
    return static_cast<double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count())/1000000000;
}

LL gcd(LL a, LL b) {
    if(a > b) swap(a, b);
    if(a == 0) return b;
    else return gcd(b-a, a);
}

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

int main(void) {
    LL a, b, c, d;
    cin >> a >> b >> c >> d;
    a--;
    LL ansb, ansa;
    ansb = b - b/c - b/d + b/lcm(c, d);
    ansa = a - a/c - a/d + a/lcm(c, d);
    cout << ansb - ansa << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

using namespace std;

int main() {
    
    int a,b;
    cin >> a >> b;
    
    vector<int> x{a+b,a-b,a*b};
    int max = *max_element(x.begin(),x.end());
    
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
# 度数法表記を弧度法表記へ変換
def rad (x)
  (x/180.0) * Math::PI
end

a,b,h,m = gets.chomp.split.map(&:to_i)

#短い針は1時間に6(=360/60)度進む
#長い針は1時間に30(=360/12)度、
#加えて1分毎0.5(=30/60)度進む
alpha = m*(30.0/60.0)
h_angle = h*(360.0/12.0)+alpha
m_angle = m*(360.0/60.0)
angle = rad(h_angle-m_angle)
c = Math.sqrt(a**2+b**2-2*a*b*Math.cos(angle))

print c

Measured memory_bytes: 14612
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);

  rep(i, N) {
    cin >> A[i];
    A[i]--;
  }

  int ans = 0;

  vector<int> B(N);
  rep(i, N) {
    cin >> B[i];
    ans += B[i];
  }

  vector<int> C(N - 1);
  rep(i, N - 1) cin >> C[i];

  rep(i, N - 1) {
    if (A[i] + 1 == A[i + 1])
      ans += C[A[i]];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let r: usize = sc.next();
    let c: usize = sc.next();
    let n: usize = sc.next();
    let v: Vec<Vec<usize>> = sc.next_mat(4, n);
    let mut ps: Vec<(usize,usize)> = Vec::new();
    for (i,xs) in v.iter().enumerate() {
        if (xs[0] == 0 || xs[0] == r || xs[1] == 0 || xs[1] == c) && (xs[2] == 0 || xs[2] == r || xs[3] == 0 || xs[3] == c) {
            ps.push((trans(xs[0],xs[1],r,c),i));
            ps.push((trans(xs[2],xs[3],r,c),i));
        }
    }
    ps.sort_by_key(|x| x.0);
    let mut st: Vec<usize> = Vec::new();
    for p in ps {
        if st.is_empty() || *st.last().unwrap() != p.1 {
            st.push(p.1);
        } else {
            st.pop();
        }
    }
    println!("{}", if st.is_empty() {"YES"} else {"NO"});
}

fn trans(x: usize, y: usize, r: usize, c: usize) -> usize {
    if y == 0 || x == r {
        x + y
    } else {
        2 * (r + c) - x - y
    }
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

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


Measured memory_bytes: 22252
#include<bits/stdc++.h>
using namespace std;
#define dbg_var(x) cout << #x << ": " << x << endl;
#define forn(i,a,b)for(int i=a;i<=b;++i)
template <typename T>
void dbg_vector(const T& v)
{
  for (size_t i = 0; i < v.size(); ++i) cout << v[i] << " ";
  cout << endl;
}
void dbg() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg(Head H, Tail... T)
{
  cerr << H << ' ';
  dbg(T...);
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
struct pair_hash {
    template <class T1, class T2>
    size_t operator () (const pair<T1,T2> &p) const {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);

        return h1 ^ h2;
    }
};
inline ll lmin(ll a,ll b){if(a<b)return a;return b;}
inline ll lmax(ll a,ll b){if(a>b)return a;return b;}
inline ll labs(ll a){if(a<0)return -a;return a;}
const ll INF=1e18;
const ll P_HASH=31;
const ll MOD=1e9+7;
const ld EPS=1e-8;

int main()
{
  /*freopen("input.txt","w",stdout);
  cout<<300000<<" "<<300000<<endl;
  for(int i=1;i<=299999;++i)
  {
    cout<<i<<" "<<i+1<<endl;
  }
  return 0;*/
  //freopen("input.txt","r",stdin);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int x;cin>>x;
  if(x==7||x==5||x==3)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

/*

*/


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

int main(){
  int N,M,C;cin>>N>>M>>C;
  int B[M];
  int A[N][M];
  
  rep(i,M) cin>>B[i];
  rep(i,N){
    rep(j,M){
      cin>>A[i][j];
    }
  }
  
  int ans=0;
  rep(i,N){
    int cnt=C;
    rep(j,M){
      cnt+=A[i][j]*B[j];
    }
    if(cnt>0) ans++;
  }
  cout<<ans<<endl;
}      

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

using namespace std;
typedef long long ll;

int main(){
    int n,m;
    cin >> n;
    vector<int> t(n);
    for(int i=0;i<n;i++){
        cin >> t[i];
    }
    cin >> m;
    vector<int> p(m),x(m);
    for(int i=0;i<m;i++){
        cin >> p[i] >> x[i];
    }
    for(int i=0;i<m;i++){
        int tm = 0;
        for(int j=0;j<n;j++){
            if(j+1==p[i])tm += x[i];
            else tm += t[j];
            //cout << tm  << "A"<< endl;
        }
        cout << tm << endl;
    }
    return 0;
}

Measured memory_bytes: 256
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) list($a[]) = ints();
// pos[x] := 並べ替え後のxの位置(0-indexed)
$pos = $a;
sort($pos);
$pos = array_flip($pos);
$cnt = 0;
for ($i = 0; $i < $n; ++$i) {
    // 並べ替えた後の位置と今の位置の差が奇数の場合は連続する二つを並べ替える必要あり
    if (abs($i - $pos[$a[$i]]) % 2) ++$cnt;
}
echo $cnt / 2, PHP_EOL; // 2つで1回反転するので2で割る
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 31260
#include <bits/stdc++.h>
using namespace std;
#define fastt ios_base::sync_with_stdio(false);cin.tie(NULL);
#define enl "\n"
#define ll long long
#define pb push_back
#define fi first
#define se second
#define vvl vector<vector<ll>> 
#define vl vector<ll> 
#define vpll vector<pair<ll,ll>>
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define mtc ll t; cin>>t; while(t--)
#define rep(i,s,n) for(ll i = s; i < n; ++i)
#define sz(a) (ll)a.size()
#define PI 3.14159265 
ll mod=1e9+7;
ll k;

ll findMax(vl &W,vl &v,vvl &dp,ll i,ll w){
    if(i>=sz(W)){
        return 0;
    }
    if(dp[i][w]!=-1)return dp[i][w];
    ll ans=findMax(W,v,dp,i+1,w);

    if(w+W[i]<=k){
        ans=max(ans,findMax(W,v,dp,i+1,w+W[i])+v[i]);
    }
    return dp[i][w]=ans;
}

 int main(){
     fastt;
     ll i,j;
   ll n,W;
   cin>>n>>W;
   k=W;
   vl w(n);vl v(n);
   rep(i,0,n){
       cin>>w[i]>>v[i];
   }
   vvl dp(n,vl(W+1,-1));
   cout<<findMax(w,v,dp,0,0)<<enl;
}


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

int main() {
  long long N, A, B;
  cin >> N >> A >> B;

  if ((A + B) == 0) {
    cout << 0 << endl;
    return 0;
  }

  long long n, r;
  n = N / (A+B);
  r = N % (A+B);

  long long ans;
  if (r < A) {
    ans = n * A + r;
  }
  else {
    ans = n * A + A;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math

n, k = map(int, input().split())
a = list(map(int, input().split()))

left = 0
right = max(a)

while True:
  mid = (left + right) // 2
  
  if mid == 0:
    cnt = 10 ** 10
  else:
    cnt = 0
    for _a in a:
      cnt += math.ceil(_a / mid - 1)
  
  if cnt > k:
    left = mid
  else:
    right = mid
  
  if right - left <= 1:
    break

print(right)

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) cin >> c[i];
	sort(a.begin(), a.end());
	sort(c.begin(), c.end());
	ll ans = 0;
	rep(i, n) {
		auto l = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
		auto u = c.end() - upper_bound(c.begin(), c.end(), b[i]);
		ans += l * u;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4536
N = int(input())
A = list(map(int, input().split()))
A.append(0)
A.insert(0,0)

total = 0
for i in range(1,N+2):
    total += abs(A[i]-A[i-1])

for i in range(1,N+1):
    print(total - abs(A[i+1]-A[i]) - abs(A[i]-A[i-1]) + abs(A[i+1]-A[i-1]))

Measured memory_bytes: 14048
// https://qiita.com/drken/items/dc53c683d6de8aeacf5a#a-%E5%95%8F%E9%A1%8C---frog-1
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N; cin >> N;
  vector<int> h(N); REP(i, N) cin >> h[i];

  vector<int> dp(100010);
  ll INF = pow(10, 9) + 7;
  REP(i, 100010) {
    dp[i] = INF;
  }

  dp[0] = 0;
  dp[1] = dp[0] + abs(h[1] - h[0]);

  for(int i = 2; i < N; ++i) {
    chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
  }
  
  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
case = 1

while 1:
    W = input()
    if W == 0: break
    N = input()
    v, w = [0]*N, [0]*N
    for i in range(N):
        v[i], w[i] = map(int, raw_input().split(','))
    dp = [0]*(W+1)
    for i in range(N):
        for j in range(W,0,-1):
            if j-w[i] >= 0:
                dp[j] = max(dp[j-w[i]]+v[i], dp[j])
    av, aw = 0, 0
    for w, v in enumerate(dp):
        if av < v:
            av = v
            aw = w
    print 'Case {}:'.format(case)
    print av
    print aw
    case += 1

Measured memory_bytes: 4332
#include <iostream>
#include <iterator>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  copy_n(istream_iterator<int>(cin), N, A.begin());
  sort(A.begin(), A.end());
  int m = A[0] + K - A[N - 1];
  for (int i = 1; i < N; ++i) {
    if (m < A[i] - A[i - 1]) m = A[i] - A[i - 1];
  }
  cout << (K - m) << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
 
int a[100005];
int cnt[100005];
 
int main(void) {
	int n;
	scanf("%d", &n);

	for ( int i = 0; i < n; i++ ) {
	scanf(" %d", &a[i]);
	cnt[a[i]]++;
	}
 
	int ans = 0;
	for ( int i = 1; i < 100000; i++ ) {
		if ( cnt[i-1] + cnt[i] + cnt[i+1] > ans ) {
		ans = cnt[i-1] + cnt[i] + cnt[i+1];
		}
	}
	printf("%d\n", ans);
 
	return 0;
}

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int> > gyo(n,vector<int>(m));
  vector<int> vec(m);
  vector<int> output(n);
  for (int i=0; i<n; i++) {
      for (int j=0; j<m; j++) {
          cin >> gyo.at(i).at(j);
      }
  }
  for (int i=0; i<m; i++) {
      cin >> vec.at(i);
  }
  for (int i=0; i<n; i++) {
      output.at(i)=0;
      for (int j=0; j<m; j++) {
          output.at(i)+=vec.at(j)*gyo.at(i).at(j);
      }
      cout << output.at(i) << endl;
  }
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  ll N;
  cin >> N;
  
  vi pcount;
  ll num=N;
  for(ll i=2; i*i<=N; i++) {
    if(!(num%i)) {
      int k=0;
      while(!(num%i)) {
        num/=i;
        k++;
      }
      pcount.push_back(k);
    }
  }
  if(num!=1) pcount.push_back(1);
  
  int ans=0;
  for(int x:pcount) {
    int k=1;
    while((k+2)*(k+1)/2<=x) k++;
    ans+=k;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int Q=2005;
int lk[Q][Q],als=0;
int top[Q][Q],fa[Q][Q];
int las[Q],e[Q<<1],nn[Q<<1],inc=0;
void ins(int x,int y)
{
    e[++inc]=y;
    nn[inc]=las[x];
    las[x]=inc;
}
void fin(int x,int last,int rig)
{
    if(lk[last][x]){
        last=x;
        ++als;
    }
    for(int t=las[x];t;t=nn[t]){
        int y=e[t];
        if(fa[rig][x]==y)continue;
        fin(y,last,rig);
    }
}
void rdfs(int x,int rig)
{
    for(int t=las[x];t;t=nn[t]){
        int y=e[t];
        if(fa[rig][x]==y)continue;
        fa[rig][y]=x;
        rdfs(y,rig);
    }
}
int tp=0,px[Q*Q],py[Q*Q];
void dfs(int x,int tx,int ty)
{
    if(top[x][ty]){
        lk[top[x][ty]][ty]=lk[ty][top[x][ty]]=0;
        if(x==tx){
            printf("%d %d %d %d ???\n",tx,ty,top[tx][ty],top[ty][tx]);
        }
        assert(x!=tx);
        px[++tp]=x,py[tp]=tx;
        return;
    }
    top[x][ty]=tx;
    for(int t=las[x];t;t=nn[t]){
        int y=e[t];
        if(fa[ty][x]==y)continue;
        dfs(y,tx,ty);
    }
}
void ad(int x,int y)
{
    if(lk[x][y]||x==y)return;
    if(top[y][x])swap(x,y);
    if(top[x][y]){
        ad(x,top[x][y]);
        return;
    }
    lk[x][y]=lk[y][x]=1;
    int rem=tp;
    top[x][y]=top[y][x]=0;
    dfs(x,x,y);
    dfs(y,y,x);
    while(tp!=rem)
        --tp,ad(px[tp+1],py[tp+1]);
}
int main()
{
    int n,qaq;
    scanf("%d%d",&n,&qaq);
    for(int i=1,x,y;i<n;i++)
        scanf("%d%d",&x,&y),ins(x,y),ins(y,x);
    for(int i=1;i<=n;i++)
        rdfs(i,i);
    for(int i=1,x,y;i<=qaq;i++)
        scanf("%d%d",&x,&y),ad(x,y);
    for(int i=1;i<=n;i++)
        fin(i,i,i);
    printf("%d\n",als>>1);
    return 0;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

//ａをbで割る
long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

int num[1111111];

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

	ll seica = 1;
	ll n;cin >> n;
	vector<ll> v(n);
	vector<ll> g(n);
	REP(i, n)cin >> v[i], g[i] = v[i];
	REP(i, n){
		for(int j = 2;j * j <= g[i];j++){
			int cou = 0;
			while(g[i] % j == 0){
				cou++;
				g[i] /= j;
			}
			num[j] = max(num[j], cou);
		}
		num[g[i]] = max(num[g[i]], 1);
	}

	ll sum = 1;
	REP(i, 1111111)REP(j, num[i])sum = sum * i % MOD;
	ll ans = 0;
	REP(i, n)ans = (ans + mod_div(sum, v[i])) % MOD;
	cout << ans << endl;

	return 0;
}


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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((c-a+b)>=0)
    cout<<c-(a-b)<<endl;
    else
        cout<<0<<endl;
    return 0;
}


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

int main(){
  int A,B,K;
  cin>>A>>B>>K;
  multiset<int> x;
  for (int i=1; i<=100; i++){
    if ((A%i==0)&&(B%i==0)){
      x.insert(i);
    }
  }
  int k=1;
  while (K>k){
    x.erase(*x.rbegin());
    k++;
  }
  cout<<*x.rbegin()<<endl;
}

Measured memory_bytes: 256