akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
typedef long long llint;

int main(){
    int l,r;
    scanf("%d %d",&l,&r);
    llint answer=2019;
    r=r-l<2019?r:l+2019;
    // if(r-l>2019*2) r=l+2019*2;
    for(llint i=l;i<=r;i++){
        for(llint j=i+1;j<=r;j++){
            llint a=(i*j)%2019;
            answer=a<answer?a:answer;
            // if(a<answer) answer=a; 
        }
    }
    printf("%d\n",answer);
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; 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;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int X;

int main() {
  cin >> X;

  for (int i = X; i >= 0; --i) {
    for (int j = 1; j * j <= i; ++j) {
      for (int k = 2; k <= 10; ++k) {
        if (pow(j, k) == i) {
          cout << i << endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 384
import sys

operator = sys.stdin.read().split()
	
top = 1
bottom = 6
south = 2
north = 5
east = 3
west = 4
sum = 1

for var in operator[1:]:
	if var == "North":
		north,top,south,bottom = top,south,bottom,north
		sum += top
	elif var == "South":
		south,top,north,bottom = top,north,bottom,south
		sum += top
	elif var == "West":
		west,top,east,bottom = top,east,bottom,west
		sum += top
	elif var == "East":
		east,top,west,bottom = top,west,bottom,east
		sum += top
	elif var == "Right":
		south,east,north,west = east,north,west,south
		sum += top
	elif var == "Left":
		south,west,north,east = west,north,east,south
		sum += top
	else:
		print sum
		top = 1
		bottom = 6
		south = 2
		north = 5
		east = 3
		west = 4
		sum = 1

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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int h, w, n;
    cin >> h >> w >> n;
    int maxx, minn;
    if(h > w) {
        maxx = h;
        minn = w;
    }
    else {
        maxx = w;
        minn = h;
    }
    for(int i=1;i<=minn;i++) {
        if(i * maxx >= n) {
            cout << i << '\n';
            break;
        }
    }
    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  string s ; 
  cin >> s ; 
  if(s.size() == 3)  reverse(all(s)) ;
  cout << s ;
}


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

struct StNode
{
  StNode* m_poParnt;
  StNode* m_poLeft;
  StNode* m_poRigt;
  int m_nKey;

  StNode(int nNo) :
    m_poParnt(nullptr), m_poLeft(nullptr), m_poRigt(nullptr), m_nKey(nNo)
  { }
};

void fnInsert(StNode*& rpoRoot, StNode* poNewNod)
{
  StNode* poParnt = nullptr;
  StNode* poNode = rpoRoot;

  while (poNode != nullptr)
  {
    poParnt = poNode;
    if (poNewNod->m_nKey < poNode->m_nKey)
      poNode = poNode->m_poLeft;
    else
      poNode = poNode->m_poRigt;
  }

  poNewNod->m_poParnt = poParnt;
  if (poParnt == nullptr)
    rpoRoot = poNewNod;
  else if (poNewNod->m_nKey < poParnt->m_nKey)
    poParnt->m_poLeft = poNewNod;
  else
    poParnt->m_poRigt = poNewNod;
}

void fnInOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnInOrder(poNode->m_poLeft);
  cout << " " << poNode->m_nKey;
  fnInOrder(poNode->m_poRigt);
}

void fnPreOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  cout << " " << poNode->m_nKey;
  fnPreOrder(poNode->m_poLeft);
  fnPreOrder(poNode->m_poRigt);
}

void fnBinSchTree(StNode*& rpoRoot)
{
  int nMaxSiz;
  cin >> nMaxSiz;

  for (int i = 0; i < nMaxSiz; ++i)
  {
    string sCmd;
    cin >> sCmd;
    if (sCmd[0] == 'i')
    {
      int nNo;
      cin >> nNo;
      StNode* poNewNod = new StNode(nNo);
      fnInsert(rpoRoot, poNewNod);
    }
    if (sCmd[0] == 'p')
    {
      fnInOrder(rpoRoot);
      cout << endl;
      fnPreOrder(rpoRoot);
      cout << endl;
    }
  }
}

void fnPstOrder(StNode* poNode)
{
  if (poNode == nullptr)  return;

  fnPstOrder(poNode->m_poLeft);
  fnPstOrder(poNode->m_poRigt);
  delete poNode;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  StNode* poRoot = nullptr;

  fnBinSchTree(poRoot);
//fnPstOrder(poRoot);
  return 0;
}

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  string s;
  cin >> s;
  int n = (int)s.length();
  for(int i=0; i<n/2; i++) {
    if(s[i]!=s[n-i-1])
      return (cout<<"No"),0;
  }
  for(int i=0; i<n/4; i++)
    if(s[i]!=s[n/2-i-1])
      return (cout<<"No"),0;
  cout << "Yes";
  return 0;
}

Measured memory_bytes: 256
def fact(n)
  (1..n).to_a.inject(1) do |num,i|
    num*i%(10**9+7)
  end
end
n,m=gets.split.map(&:to_i)
ans=fact(n)*fact(m)
if (n-m).abs==0
  puts 2*ans%(10**9+7)
elsif (n-m).abs==1
  puts ans%(10**9+7)
else
  puts 0
end


Measured memory_bytes: 3452
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int a, b; cin >> a >> b;
  int add = a + b;
  int sub = a - b;
  int mul = a * b;
  if (add >= sub && add >= mul) { 
    cout << add << endl;
    return 0;
  } else if (sub >= add && sub >= mul) {
    cout << sub << endl;
    return 0;
  } else if (mul >= sub && mul >= add) {
    cout << mul << endl;
    return 0;
  }
}


Measured memory_bytes: 888
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
typedef long long int ll;

struct cake{
  ll x; //kirei
  ll y; //osii
  ll z; // ninki
};


int main() {
  ll f[2]={1, -1};
  ll n, m;
  cin >> n >> m;
  vector<cake> c(n);
  rep(i, n)
    cin >> c.at(i).x >> c.at(i).y >> c.at(i).z;
  vector <ll> a(n);
  vector<ll> sums(8, 0);
  rep(i,2){
    rep(j,2){
      rep(k,2){
        rep(ii,n){
          a.at(ii) = f[i]*c.at(ii).x + f[j]*c.at(ii).y + f[k]*c.at(ii).z;
        }
        sort(a.rbegin(),a.rend());
        rep(ii, m){
          sums.at(i+2*j+4*k) += a.at(ii);
        }

      }
    }
  }

  cout << *max_element(sums.begin(), sums.end()) << endl;

  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;

int n;
vector<vector<int>> a(3);

ll solve () {
  ll ans = 0;
  rep (j, n) {
    int tmp = a[1][j];
    ll comb = lower_bound(a[0].begin(), a[0].end(), tmp) - a[0].begin();
    comb *= a[2].end() - upper_bound(a[2].begin(), a[2].end(), tmp);
    ans += comb;
  }
  return ans;
}

int main() {
  while (cin >> n) {
    rep (i, 3) {
      a[i].resize(n);
      rep (j, n) cin >> a[i][j];
      sort(a[i].begin(), a[i].end());
    }
    cout << solve() << endl;
  }
  return 0;
}


Measured memory_bytes: 4552
#include <bits/stdc++.h>
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int main()
{
    double w,h,x,y;
    cin>>w>>h>>x>>y;
    cout<<w*h/2<<" ";
    if(2*x==w&&2*y==h)cout<<1<<endl;
    else cout<<0<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi atan(1.0)*4
#define pb(x) push_back(x)
#define in(x) insert(x)
#define fl(x,y) for(ll i=x;i<y;i++)
#define all(cont) cont.begin(),cont.end()
#define sz size()
bool isprm(ll a){for(ll i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
int main()
{
    ll a,b,t,n,k,p,q,r,sum,ct=0,flag=0;
    string s,s1,s2,s3;
    set<ll>st;
    map<ll,ll>mp;
      vector<ll>v,vv;
      cin>>n>>k; flag=0;
      if(n*2==k) {cout<<"Yes"<<endl; return 0;}
      else if(n*4==k) {cout<<"Yes"<<endl; return 0;}
      else
      {
          flag=0;
       for(ll i=1;i<=n/2;i++)
       {
           p=n-i;
           if((2*i+4*p)==k) {flag=1; cout<<"Yes"<<endl; break;}
           else if((2*p+4*i)==k) {flag=1; cout<<"Yes"<<endl; break;}

       }
       if(flag==0) cout<<"No"<<endl;
      }
      return 0;
}







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

int main() {
  int n;
  cin >> n;
  vector<int64_t> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  sort(v.begin(), v.end());
  bool flag = 1;
  for (int i = 0; i < n-1; ++i) {
    if (v[i] == v[i+1]) {
      flag = 0;
      break;
    }
  }
  if (flag) cout << "YES\n";
  else cout << "NO\n";
}

Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace AtCoder.B
{
    public class Program
    {
        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var (X, Y) = Read2Longs();
            var a = (Y - 2 * X) / 2D;
            var b = X - a;

            if (a != (int)a || b != (int)b)
            {
                return "No";
            }

            if (a < 0 || b < 0)
            {
                return "No";
            }

            return "Yes";
        }

        #region Console.Read

        public static string ReadText() { return Console.ReadLine(); }
        public static List<string> ReadTexts() { return Console.ReadLine().Split(' ').ToList(); }
        public static long ReadLong() { return long.Parse(Console.ReadLine()); }
        public static (long, long) Read2Longs() { var ls = ReadLongs(); return (ls[0], ls[1]); }
        public static (long, long, long) Read3Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2]); }
        public static (long, long, long, long) Read4Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3]); }
        public static (long, long, long, long, long) Read5Longs() { var ls = ReadLongs(); return (ls[0], ls[1], ls[2], ls[3], ls[4]); }
        public static List<long> ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }

        #endregion
    }
}


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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, "\e[31;1m"); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\e[0m")
#else
    #define eprintf(...) 42
#endif

ll solve(const std::string& T)
{
    return (T.size() / 2) - std::accumulate(T.begin(), T.end(), 0, [](int a, char v){
        if ('p' == v)
        {
            return a + 1;
        }
        return a;
    });
}

int main(void)
{
    std::string T;
    std::cin >> T;
    std::cout << solve(T) << std::endl;
    return 0;
}

Measured memory_bytes: 512
import sys
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

s = str(stdin.readline().rstrip())
t= str(stdin.readline().rstrip())
#l = list(map(int, stdin.readline().rstrip().split()))
#A, B, C = map(int, stdin.readline().rstrip().split())
#numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
#word = [stdin.readline().rstrip() for _ in range(n)]
#number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
#zeros = [[0] * w for i in range(h)]
t = t[:len(t)-1]
if s == t:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9040
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
		int n = Integer.parseInt(br.readLine());
		ArrayList<Integer> A = new ArrayList<Integer>();
		ArrayList<Integer> B = new ArrayList<Integer>();
		for(int i=0;i<n;i++){
		    String[] line = br.readLine().split(" ");
		    A.add(Integer.parseInt(line[0]));
		    B.add(Integer.parseInt(line[1]));
		}
		
		long ans = 0;
		for(int i=n-1;i>=0;i--){
		    long a = A.get(i);
		    long b = B.get(i);
		    if((a+ans)%b!=0)
    		    ans += b-(a+ans)%b;
		}
		System.out.println(ans);
	}
}

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

int main() {
  string s, t, u; cin >> s >> t;
  int a, b; cin >> a >> b;
  cin >> u;
  if (u == s)
    a--;
  if (u == t)
    b--;
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
	
	int n, r;
	int[][] cut;
	
	int solve() {
		Stack<Integer> cards = new Stack<Integer>();
		for (int i = 1; i <= n; i++) {
			cards.push(i);
		}
		
		for (int i = 0; i < cut.length; i++) {
			Stack<Integer> p, c;
			p = new Stack<Integer>();
			c = new Stack<Integer>();
			for (int j = 0; j < cut[i][0] - 1; j++) p.push(cards.pop());
			for (int j = 0; j < cut[i][1]; j++)     c.push(cards.pop());
			while (!p.isEmpty()) cards.push(p.pop());
			while (!c.isEmpty()) cards.push(c.pop());
		}
		return cards.lastElement();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		String output = "";
		while (sc.hasNext()) {
			n = sc.nextInt();
			r = sc.nextInt();
			if (n == 0 && r == 0) {
				break;
			} else {
				cut = new int[r][];
				for (int i = 0; i < r; i++) {
					cut[i] = new int[]{sc.nextInt(), sc.nextInt()};
				}
				output += solve() + "\n";
			}
		}
		sc.close();
		System.out.print(output);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll k,t;cin>>k>>t;
  ll maxbuf=0;
  rep(i,0,t){
    ll a;cin>>a;
    chmax(maxbuf,a);
  }
  if(maxbuf<=(k+1)/2)cout<<0<<endl;
  else if(~k&1)cout<<1+(maxbuf-1-k/2)*2<<endl;
  else cout<<(maxbuf-k/2-1)*2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=4000000000000000000;
ll MOD=1000000007;



int main() {
  ll n;
  cin >> n;
  vector<vector<pair<ll,ll>>> a(n+1,vector<pair<ll,ll>>(0));
  ll f,g,h;
  rep(i,n-1){
    cin >> f >> g >> h;
    a.at(f).push_back(make_pair(g,h));
    a.at(g).push_back(make_pair(f,h));
  }
  ll Q,k;
  cin >> Q >> k;
  vector<ll> d(n+1);
  rep(i,n+1) d.at(i)=INF;
  queue<ll> q;
  q.push(k);
  d.at(k)=0;
  while(!q.empty()){
    ll x=q.front();
    q.pop();
    for (int i=0;i<a.at(x).size();i++){
      if (d.at(a.at(x).at(i).first)>d.at(x)+a.at(x).at(i).second){
        d.at(a.at(x).at(i).first)=d.at(x)+a.at(x).at(i).second;
        q.push(a.at(x).at(i).first);
      }
    }
  }
  ll e,r;
  rep(i,Q){
    cin >> e >> r;
    cout << d.at(e)+d.at(r) << endl;
  }
}


Measured memory_bytes: 9984
import sys
input = sys.stdin.readline
from collections import *

N, K = map(int, input().split())
A = list(map(int, input().split()))
log_size = 65
#行き先ではなく移動量をダブリングする
dp = [[-1]*N for _ in range(log_size)]
idx = defaultdict(int)

for i in range(2*N):
    if A[i%N] in idx and idx[A[i%N]]<N:
        dp[0][idx[A[i%N]]] = i+1-idx[A[i%N]]
    
    idx[A[i%N]] = i

for i in range(1, log_size):
    for j in range(N):
        #値が大きくなりすぎるとTLEする
        dp[i][j] = min(10**18, dp[i-1][j]+dp[i-1][(j+dp[i-1][j])%N])

now = 0
NK = N*K

for i in range(log_size-1, -1, -1):
    if NK-dp[i][now]>=0:
        NK -= dp[i][now]
        now = (now+dp[i][now])%N

if NK==0:
    print()
    exit()
    
q = deque([])
cnt = defaultdict(int)

for i in range(now, N):
    if cnt[A[i]]>0:
        while cnt[A[i]]>0:
            rem = q.pop()
            cnt[rem] -= 1
    else:
        cnt[A[i]] += 1
        q.append(A[i])

print(*q)

Measured memory_bytes: 183548
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

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

    int n,m;
    cin>>n>>m;
    vector<vector<int>> adj(n);
    for(int i=0; i<m; i++){
        int a,b;
        cin>>a>>b;
        adj[a-1].push_back(b-1);
        adj[b-1].push_back(a-1);
    }

    queue<int> q;
    vector<int> answer(n,-1);
    q.push(0);
    while(!q.empty()){
        int now=q.front();
        q.pop();
        for(int nxt : adj[now]){
            if(answer[nxt]==-1){
                answer[nxt]=now;
                q.push(nxt);
            }
        }
    }
    bool check=true;
    for(int i=1; i<n; i++) if(answer[i]==-1) check=false;
    if(!check) cout<<"No";
    else{
        cout<<"Yes\n";
        for(int i=1; i<n; i++) cout<<answer[i]+1<<"\n";
    }
    return 0;
}


Measured memory_bytes: 10176
#include<iostream>

using namespace std;

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

	if(X>=2100){
		cout << 1 << endl;
		return 0;
	}else{
		int t1 = X/100;
		int t2 = X - 100*t1;
		if(t1 * 5 >= t2){
			cout << 1 << endl;
		}else{
			cout << 0 << endl;
		}
		return 0;
	}
}


Measured memory_bytes: 256
import math


def combinations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


problems = int(input())
scores = []
for i in range(problems):
    num = int(input())
    scores.append(num)


res = 0
scoreSum = sum(scores)
if scoreSum % 10 != 0:
    res = scoreSum
    print(res)
else:
    scores.sort()
    for j in range(len(scores)):
        scoreSum -= scores[j]
        if scoreSum % 10 != 0:
            res = scoreSum
            print(res)
            break
        else:
            scoreSum += scores[j]
    else:
        print(res)





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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    int n,m;cin>>n>>m;
    vii a(m);
    rep(i,m){
        cin>>a[i].F>>a[i].S;
    }
    sort(all(a));
    int l=a[0].F,r=a[0].S;
    int ans=1;
    for(int i=1;i<m;++i){
        if(r<=a[i].F||a[i].S<=l){
            ans++;
            l=a[i].F;r=a[i].S;
        }
        else{
            if(l<a[i].F)l=a[i].F;
            if(r>a[i].S)r=a[i].S;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
C = A - B
l, r = 0, 1<<30
while r - l > 1:
    m = (l + r) // 2
    if sum([max((h - B * m + C - 1) // C, 0) for h in H]) <= m:
        r = m
    else:
        l = m
print(r)

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

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  MAX                 1234567899
#define  mod                 1000000007
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  vi                  vector<int>
#define  hi                  pf(" HI \n")
#define  pp                  pair<int,int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  unsigned long long int ulli;
int dx4[] = { 0 , 0 , -1 , 1 } ;
int dy4[] = { -1 , 1 , 0 , 0 } ;
bool valid( int r , int c , int x , int y ){
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ; return 0 ;}

using namespace std;

int main ()
{
    int h,a;
    cin >> h >> a;
    int p = h/a;
    if(h%a!=0)
        p++;
    cout << p <<endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
    private static Scanner sc;

    public static void main(final String[] args) {
        sc = new Scanner(System.in);
        String a = sc.next();
        if(a.substring(2,3).equals(a.substring(3,4)) && 
           a.substring(4,5).equals(a.substring(5,6)))System.out.println("Yes"); 
        else System.out.println("No");
    }
}








Measured memory_bytes: 35580
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<stdio.h>

long long calcce(long long pt[]){
  if(pt[0]==pt[1]&&pt[1]==pt[2]&&pt[2]==pt[3]){return 4;}
  if(pt[0]==pt[2]&&pt[1]==pt[3]){return 2;}
  return 1;
}

long long cha[1024][4];
long long ispt(long long tg,long long hash){
  if(cha[tg][0]==hash){return 1;}
  if(cha[tg][1]==hash){return 1;}
  if(cha[tg][2]==hash){return 1;}
  if(cha[tg][3]==hash){return 1;}
  return 0;
}

long long calc(long long cnt[]){
  long long i,j,k,l,res=0,dt;
  long long pj,pk,pl,lm=0;
  for(i=8;i<16;i++){lm+=cnt[i];}
  //printf("%lld\n",lm);
  //for(i=0;i<16;i++){printf("[%lld]",cnt[i]);}printf("\n");
  for(i=1;i<16;i+=2){//if((i&1)==0){continue;}
    if(cnt[i]==0){continue;}
    if(i&8ll){lm--;}
    dt=cnt[i];cnt[i]--;
    pj=dt;
    for(j=0;j<16;j++){if((j&2)==0){continue;}
      if(cnt[j]==0){continue;}
      if(j&8ll){lm--;}
      dt*=cnt[j];cnt[j]--;
      pk=dt;
      for(k=0;k<16;k++){if((k&4)==0){continue;}
        if(cnt[k]==0){continue;}
        if(k&8ll){lm--;}
        dt*=cnt[k];cnt[k]--;
        res+=dt*lm;
        //for(l=8;l<16;l++){//if((l&8)==0){continue;}
        //  if(cnt[l]==0){continue;}
        //  dt*=cnt[l];cnt[l]--;
        //  res+=dt;
        //  cnt[l]++;
        //  dt=pl;
        //}
        if((k&8ll)!=0){lm++;}
        cnt[k]++;
        dt=pk;
      }
      if((j&8ll)!=0){lm++;}
      cnt[j]++;
      dt=pj;
    }
    if((i&8ll)!=0){lm++;}
    cnt[i]++;
  }
  return res;
}

int main(){
  srand(0);
  long long n,i,j,k,l,m,f,ce,res=0,tf,mem;
  long long c[512][4];
  long long jt[4],kt[4];
  long long md[4][4];
  long long cnt[16]={0};
  long long nha,mha[4];
  scanf("%lld",&n);
  //n=400;
  for(i=0;i<n;i++){
    nha=0;
    for(j=0;j<4;j++){
      scanf("%lld",&c[i][j]);
      //c[i][j]=rand()%4;
      nha|=(c[i][j]<<(10*j));
    }
    for(j=0;j<4;j++){
      cha[i][j]=nha;
      mem=(nha&((1ll<<10)-1));
      //printf("[%lld]<%lld>",cha[i][j],mem);
      nha>>=10;
      nha|=(mem<<30);
    }//printf("\n");
  }
  for(i=0;i<n;i++){
    for(j=0;j<4;j++){jt[j]=c[i][j];}
    for(j=i+1;j<n;j++){
      for(k=0;k<4;k++){
        for(l=0;l<4;l++){
          kt[l]=c[j][(4+k-l)&3ll];
        }
        ce=1;
        for(l=0;l<4;l++){
          md[l][0]=jt[l];
          md[l][1]=jt[(l+3)&3ll];
          md[l][2]=kt[(l+3)&3ll];
          md[l][3]=kt[l];
          mha[l]=(md[l][0]|(md[l][1]<<10)|(md[l][2]<<20)|(md[l][3]<<30));
          //printf("<%lld %lld %lld %lld : %lld>\n",md[l][0],md[l][1],md[l][2],md[l][3],mha[l]);
          ce*=calcce(md[l]);
        }
        for(l=0;l<16;l++){cnt[l]=0;}
        tf=0;
        for(l=i+1;l<n;l++){
          if(l==j){continue;}
          f=0;
          for(m=0;m<4;m++){
            if(ispt(l,mha[m])==1){f|=(1ll<<m);}
          }
          //printf("%lld\n",f);
          tf|=f;
          cnt[f]++;
        }
        if(tf!=15){continue;}
        res+=ce*calc(cnt);
      }
    }
  }
  printf("%lld\n",res);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
	int x, n; cin >> x >> n;
	x += 200;
	int p[400] = {};
	for (int i = 0; i < n; i++)
	{
		int y;
		cin >> y;
		p[y+200] = 1;
	}

	int i = 0;
	while (true)
	{
		if(p[x - i] == 0){
			cout << x - i - 200 << endl;
			break;
		}
		if(p[x + i] == 0) {
			cout << x + i - 200 << endl;
			break;
		}
		i++;
	}


	return 0;
}


Measured memory_bytes: 3648
# SUN MON TUE WED THU FRI SAT

A = input()

if A == "SUN":
  print(7)
elif A == "MON":
  print(6)
elif A == "TUE":
  print(5)
elif A == "WED":
  print(4)
elif A == "THU":
  print(3)
elif A == "FRI":
  print(2)
elif A == "SAT":
  print(1)


Measured memory_bytes: 2940
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N; long long K;
	cin >> N >> K;
	vector<int> c(50);
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		long long x;
		cin >> x;
		for (int j = 49; j >= 0; --j) {
			if ((x >> j) & 1) ++c[j];
		}
		ans += x ^ K;
	}
	for (int i = 49; i >= 0; --i) {
		if ((K >> i) & 1) {
			long long sum = (long long)(c[i]) << i;
			for (int j = 0; j < i; ++j) {
				sum += (long long)max(c[j], N - c[j]) << j;
			}
			for (int j = i + 1; j <= 49; ++j) {
				if ((K >> j) & 1) {
					sum += (long long)(N - c[j]) << j;
				}
				else {
					sum += (long long)(c[j]) << j;
				}
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
string s,ans;
int n;
 
P getNum(string str,int x){
  int r=0;
  while('0'<=str[x]&&str[x]<='9')
    r=r*10+str[x]-'0',x++;
  return P(x,r);
}
 
void dfs(int b,int e){
  int p=b;
  while(p<=e&&ans.size()<=n){
    if('0'<=s[p]&&s[p]<='9'){
      P r=getNum(s,p);
      int x=r.first,num=r.second;
      int y=r.first,z=r.first;
      if(s[x]=='('){
    int c=1;
    y=x+1;
    for(z=y;z<=e&&c;z++){
      if(s[z]=='(')c++;
      if(s[z]==')')c--;
    }
    p=z;
    z-=2;
    while(num--)dfs(y,z);
      }else{
    while(num--)ans+=s[x];
    p=x+1;
      }
    }
   if('A'<=s[p]&&s[p]<='Z')
      ans+=s[p++];
  }
}
 
int main(){
  while(1){
    cin>>s>>n;
    if(s=="0"&&!n)break;
    dfs(0,s.size()-1);
    if(ans.size()<n+1)
      cout<<0<<endl;
    else cout<<ans[n]<<endl;
    ans.clear();
  }
  return 0;
}

Measured memory_bytes: 2116
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));

        StringTokenizer st=new StringTokenizer(f.readLine());
        int n=Integer.parseInt(st.nextToken());
        int m=Integer.parseInt(st.nextToken());
        int[]arr=new int[n];
        int[]arr2=new int[m];
        st=new StringTokenizer(f.readLine());
        for(int i=0;i<n;i++){
            arr[i]=Integer.parseInt(st.nextToken());
        }
        st=new StringTokenizer(f.readLine());
        for (int j=0;j<m;j++){
            arr2[j]=Integer.parseInt(st.nextToken());
        }
        long MOD=1000000007;
        long[][]dp=new long[n+1][m+1];
//        prefix[0][0]=1;
        dp[0][0]=1;
        for(int i=0;i<=n;i++){
            prefix[i][0]=1;
        }
        for(int i=0;i<=m;i++)prefix[0][i]=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
//                if(i==0 && j==0)continue;
                if(i!=0 && j!=0){
                    prefix[i][j]=+prefix[i-1][j]+prefix[i][j-1]-prefix[i-1][j-1]+prefix[i][j];
                }
                else if(i!=0){
                    prefix[i][j]=prefix[i][j]+prefix[i-1][j];
                }
                else if(j!=0){
                    prefix[i][j]=prefix[i][j]+prefix[i][j-1];
                }
                if(arr[i-1]==arr2[j-1]){
                    dp[i][j]++;
                    dp[i][j]+=query(1,1,i-1,j-1);;

                }
                prefix[i][j]+=dp[i][j];
                prefix[i][j]%=MOD;
                dp[i][j]%=MOD;
                if(prefix[i][j]<0)prefix[i][j]+=MOD;
                if(dp[i][j]<0)dp[i][j]+=MOD;
                prefix[i][j]%=MOD;
                dp[i][j]%=MOD;
            }
        }
        System.out.println(prefix[n][m]);



        f.close();
    }

    static long[][]prefix=new long[2200][2200];
    static long query(int x1,int y1, int x2,int y2){
        if(x2<0){
            return 0;
        }
        if(y2<0){
            return 0;
        }
        long ret=prefix[x2][y2];
        if(x1!=0 && y1!=0){
            ret-=prefix[x1-1][y2];
            ret-=prefix[x2][y1-1];
            ret+=prefix[x1-1][y1-1];
        }
        else if(y1!=0){
            ret-=prefix[x2][y1-1];
        }
        else if (x1!=0){
            ret-=prefix[x1-1][y2];
        }
        return ret;

    }
}


Measured memory_bytes: 129060
program sample
  implicit none
  character(10) :: s
  integer :: slen,i
  integer,allocatable :: t(:)

  read(*,*) s
  s=trim(s)
  slen=len(s)
  allocate(t(0:slen))
  t=0
  
  do i=1,slen
     if(s(i:i)=='A'.or.s(i:i)=='C'.or.s(i:i)=='G'.or.s(i:i)=='T')then
        t(i)=t(i-1)+1
     else
        t(i)=0
     endif
  enddo

  write(*,*) maxval(t)

  stop
  
end program sample

Measured memory_bytes: 2828
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
int main() {
	int N;
	cin >> N;
	vector<int> L(2 * N);
	for (int i = 0; i < 2 * N; i++) {
		cin >> L[i];
	}
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < L.size(); i += 2) {
		ans += L[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

int main()
{
    ll r, D, x2000;
    ll xvalue;

    cin >> r >> D >> x2000;

    auto calc = [r, D](ll x) {
        return (ll)(r * x - D);
    };
    xvalue = calc(x2000);

    for (int i = 0; i < 10; i++) {
        cout << xvalue << endl;
        xvalue = calc(xvalue);
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(x,n) for(int x = 0; x < n; x++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) ((int)(a).size())
#define FIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back
#define fore(i,a,b) for(int i = a; i < b; i++)
using namespace std;
typedef long long ll;

const int MXN = 101;
int A[MXN][MXN];

int main() {
  string s; cin >> s;

  int mn = SZ(s);
  FOR(x,26) {
    FOR(y,SZ(s)) A[SZ(s)][y] = s[y]-'a';

    int i = SZ(s);
    while(i > 0){
      bool valid = true;
      FOR(y,i) valid &= A[i][y] == x;
      if(valid) break;

      i--;
      FOR(y,i)
        A[i][y] = A[i+1][y] == x ? x : A[i+1][y+1];
    }

    mn = min(mn, SZ(s)-i);
  }

  cout << (mn == SZ(s) ? -1 : mn) << "\n";
}

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

int main() {
    string S;
    cin >> S;
    ll K;
    cin >> K;
    char first = S[0];
        for (int i = 0; i < min((long long)S.size(), K); ++i) {
            if (S[i] >= '2') {
                cout << S[i] << endl;
                return 0;
            }
    }
    cout << '1' << endl;
    return 0;
}

Measured memory_bytes: 256
x=int(input())
x_lst=list(map(int,input().split()))
count = 0
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

if x==1:
    print(x[0])
else:
    element = gcd(x_lst[0], x_lst[1])
    if x==2:print(element)
    else:
        for i in range(2,x):
            element=gcd(element,x_lst[i])
while element % 2 == 0:
  element = element / 2
  count += 1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n,m;
	cin>>n>>m;
	if(n%m!=0)cout<<n/m+1<<endl;
	else cout<<n/m<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<algorithm>
    using namespace std;
     
    int main()
    {
      int L, R;
      cin>>L>>R;
      if(R-R%2019-2019>=L) cout<<0<<endl;
      else
      {
        int ans=2019;
        for(int i=L; i<R; i++)
        {
          for(int j=i+1; j<=R; j++)
          {
            ans=min(ans, ((i%2019)*(j%2019))%2019);
          }
        }
        cout<<ans<<endl;
      }
      return 0;
    }

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

#define ll long long
#define ar array

void solve() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x[5];
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  for (int i=0; i<5; i++) {
    if (x[i] == 0) {
      cout << i+1 << "\n";
      return 0;
    }
  }
}


Measured memory_bytes: 3596
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int a[3333];

int dfs(vv<int> &g,int v,int p){
  for(int w:g[v])if(w!=p && a[v]>a[w] && dfs(g,w,v)==0) return 1;
  return 0;
}

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int n;
  cin>>n;
  rep(i,n) cin>>a[i];
  vv<int> g(n);
  rep(i,n-1){
    int x,y;
    cin>>x>>y; --x; --y;
    g[x].pb(y);
    g[y].pb(x);
  }
  vector<int> re;
  rep(i,n) if(dfs(g,i,-1)) re.pb(i);
  rep(i,re.size()){
    if(i) cout<<" ";
    cout<<re[i]+1;
  }
  cout<<endl;
  return 0;
}


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

int main(){
	int N;
	cin>>N;
	int a[N], i, j;
	long long dp[N];
	for(i=0; i<N; i++)cin>>a[i];
	dp[0] = 0;
	for(i=1; i<N; i++){
		int temp1=100000, temp2=100000;
		if(i > 0)temp1 = dp[i-1] + abs(a[i]-a[i-1]);
		if(i > 1)temp2 = dp[i-2] + abs(a[i]-a[i-2]);
		dp[i] = min(temp1, temp2);
	}
	cout<<dp[N-1];
	return 0;
} 

Measured memory_bytes: 1408
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
	
		int[] arr = new int[n+1];
		
		for(int i=0; i<m; i++){
			int c1 = sc.nextInt();
			int c2 = sc.nextInt();
			
			arr[c1]++;
			arr[c2]++;
		}
		
		for(int i=1; i<n+1; i++){
			System.out.println(arr[i]);
		}
	}
}

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

#define ll long long int

int main() {
  ll m = 1000000007;
  ll n, a, ps=0, sm=0;
  cin >> n;
  for(ll i=0;i<n;i++) {
	cin >> a;
    if(i==1)
      ps = (sm*a)%m;
    else
      ps += (sm*a)%m;
    sm = (sm+a)%m;
  }
  cout << ps%m;
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int dp[101][10001];
int main(){
    int n,W;
    cin >> n >> W;
    vector<int> w(n),v(n);
    for(int i=0;i<n;i++)    cin >> v[i] >> w[i];
    for(int i=0;i<=W;i++)   dp[0][i] = 0;
    
    for(int i=0;i<n;i++){
        for(int j=0;j<=W;j++){
            if(j>=w[i]) dp[i+1][j] = max(dp[i][j-w[i]]+v[i],dp[i][j]);
            else    dp[i+1][j] = dp[i][j];
        }
    }
    cout << dp[n][W] << endl;
    return 0;
} 


Measured memory_bytes: 7044
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

vector<vector<int>> graph;
vector<int> cost;

int dfs(int from = 0, int p = -1){
    int res = 0;
    for(int to : graph[from]){
        if(to == p) continue;
        res += min(cost[from], cost[to]);
        res += dfs(to, from);
    }
    return res;
}

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

    int n;
    cin >> n;
    graph.resize(n);
    cost.assign(n, -1);
    for(int i = 0; i < n - 1; ++i){
        int u, v;
        cin >> u >> v;
        --u, --v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }
    priority_queue<int> que;
    for(int i = 0; i < n; ++i){
        int c;
        cin >> c;
        que.push(c);
    }

    int st = -1;
    int degree = 0;
    for(int i = 0; i < n; ++i){
        if(graph[i].size() > degree){
            degree = graph[i].size();
            st = i;
        }
    }

    queue<int> vertex;
    vertex.push(st);
    cost[st] = que.top();
    que.pop();
    while(!vertex.empty()){
        int from = vertex.front();
        vertex.pop();
        for(int to : graph[from]){
            if(cost[to] != -1)  continue;
            cost[to] = que.top();
            que.pop();
            vertex.push(to);
        }
    }
    cout << dfs() << endl;
    for(int i = 0; i < n; ++i){
        cout << cost[i] << ((i == n - 1) ? "\n" : " ");
    }
}

Measured memory_bytes: 1792
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
#include <cmath>
#include <iomanip>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
#define outD(fpv) cout << setprecision(20) << fpv << endl;
inline void yes(bool cond) { cond ? puts("YES") : puts("NO"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
template<typename Type> inline void unique(Type& arr) { sort(arr); arr.erase(unique(arr.begin(), arr.end()), arr.end()); }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    string S;
    cin >> S;
    char p = -1;
    for(auto& ch:  S)
    {
        if (ch == p)
        {
            puts("Bad");
            return 0;
        }
        p = ch;
    }
    puts("Good");
    //
    return 0;
}

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

int ppl[100005];

int main()
{
	int n, k, q;
	cin>>n >>k >>q;
	int im=q-k+1;
	for(int i=0; i<q; i++)
	{
		int a;
		cin>>a;
		ppl[a]++;
	}
	for(int i=1; i<=n; i++)
	{
		if(ppl[i]>=q-k+1) cout<<"Yes" <<endl;
		else cout<<"No" <<endl;
	}
}

Measured memory_bytes: 1024
unittest
{
	assert( [ "36", "24" ].parse.expand.solve == "GREATER" );
	assert( [ "850", "3777" ].parse.expand.solve == "LESS" );
	assert( [ "9720246", "22516266" ].parse.expand.solve == "LESS" );
	assert( [ "123456789012345678901234567890", "234567890123456789012345678901" ].parse.expand.solve == "LESS" );

	assert( [ "123", "123" ].parse.expand.solve == "EQUAL" );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto a = input.front.strip;
	input.popFront;
	auto b = input.front.strip;
	return tuple( a, b );
}

auto solve( string a, string b )
{
	if( a.length < b.length ) return "LESS";
	if( b.length < a.length ) return "GREATER";
	if( a < b ) return "LESS";
	if( b < a ) return "GREATER";
	return "EQUAL";
}


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

using namespace std;
using ll = long long;

const ll mod = 1000000007;

int main()
{
    string a;
    cin >> a;
    for(auto &i : a)i -= '0';
    int n = a.size();
    vector<vector<ll>> dp(n + 1, vector<ll>(2));
    dp[0][0] = 1;

    for(int i = 0; i < n; i++){                       //何桁目まで見たか
        for(int j = 0; j <= 1; j++){                  //前の状態
            for(int k = 0; k <= (j ? 1 : a[i]); k++){ //遷移の方向

                //1を作り出す遷移は二通り
                if(k){
                    dp[i + 1][j || (k < a[i])] += dp[i][j] * 2;
                }else{
                    dp[i + 1][j || k < (a[i])] += dp[i][j];
                }
                dp[i + 1][j || (k < a[i])] %= mod;
            }
        }
    }
    cout << (dp[n][0] + dp[n][1]) % mod << endl;
}

Measured memory_bytes: 5760