akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG
#define llint long long
const double pi=3.141592653589793;

vector<int> dp(100010,0);
vector<int> p(100010,0);
vector<vector<int>> st(100010,vector<int>(0));
vector<vector<int>> ts(100010,vector<int>(0));

//sを始点とする最長パスをdpで求める

int ddpp(int s){
    if (p[s]==1){
        return dp[s];
    }
    else{
        p[s]=1;
        int m1=0;
        if (st[s].size()==0){
            dp[s]=0;
            return 0;
        }
        for (int x:st[s]){
            m1=max(m1,ddpp(x));
        }
        dp[s]=1+m1;
        return dp[s];
    }
}
int main() {
    int n,m;
    cin>>n>>m;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        st[x].push_back(y);
        ts[y].push_back(x);
    }
    for (int i=1;i<n+1;i++){
        if (ts[i].size()==0){
            ddpp(i);
        }
    }
    int mmm=0;
    for (int i=1;i<n+1;i++){
        mmm=max(mmm,dp[i]);
    }
    cout<<mmm<<endl;

    

    return 0;
}

Measured memory_bytes: 16768
// 第k子串.cpp: 定义控制台应用程序的入口点。
//

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fod(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const int maxn = 500007;
int i, j, l, tt, n, m, T, ans1, ans2, k;
int last, num;

struct node {
	int fa, len, sum;
	int son[26];
}t[maxn * 2];

char s[maxn * 2];
int a[maxn * 2], b[maxn * 2], cc[maxn * 2], p, np, q, nq;

void extend(int c) {
	p = last, np = ++num;
	t[np].len = t[p].len + 1; np = num; cc[np] = 1;
	while (p && !t[p].son[c])t[p].son[c] = np, p = t[p].fa;
	if (!p)t[np].fa = 1;
	else {
		q = t[p].son[c];
		if (t[p].len + 1 == t[q].len)t[np].fa = q;
		else {
			nq = ++num;
			t[nq] = t[q];
			t[num].len = t[p].len + 1;
			t[q].fa = t[np].fa = nq;
			while (p&&t[p].son[c] == q)t[p].son[c] = nq, p = t[p].fa;
		}
	}
	last = np;
}

int main() {
	//freopen("string.in", "r", stdin);
	//freopen("string.out", "w", stdout);
	//  freopen("fan.in","r",stdin);
	//  freopen("fan.out","w",stdout);
	tt = 0;
	scanf("%s", s + 1);
	scanf("%d", &k);
	n = strlen(s + 1); num = last = 1;
	fo(i, 1, n)extend(s[i] - 'a');
	fo(i, 1, num)a[t[i].len]++;
	fo(i, 1, n)a[i] += a[i - 1];
	fod(i, num, 1)b[a[t[i].len]--] = i;
	fod(i, num, 1) {
		int u = b[i];
		if (tt)cc[t[u].fa] += cc[u];
		else cc[u] = 1;
	}
	cc[1] = 0;
	fod(i, num, 1) {
		int u = b[i]; t[u].sum = cc[u];
		fo(j, 0, 25) {
			t[u].sum += t[t[u].son[j]].sum;
		}
	}
	if (t[1].sum<k)printf("-1\n");
	else {
		int x = 1;
		while (1) {
			if (k <= cc[x])return 0;
			k -= cc[x];
			fo(i, 0, 25) {
				if (t[x].son[i]) {
					if (k <= t[t[x].son[i]].sum) {
						putchar('a' + i);
						x = t[x].son[i];
						break;
					}
					k -= t[t[x].son[i]].sum;
				}
			}
		}
	}
}


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

typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<string>v;
    for (int i = 0; i < n; ++i){
        string tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    v.push_back("-");
    int max = 0;
    string output;
    int x = 1;
    for (int i = 1; i <= n; ++i){
        if (v.at(i) == v.at(i-1)){
            x++;
        }
        else{

            if (x > max){
                output = v.at(i-1);
                max = x;
            }
            else if (x == max){
                output += "\n";
                output += v.at(i-1);
            }
            x = 1;
            
        }
    }
    cout << output << "\n";
}

Measured memory_bytes: 16116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;

int main() {
    cin.sync_with_stdio(false);
	string a,b;
	cin >> a >> b;
	sort(a.begin(), a.end());
	sort(b.rbegin(), b.rend());
	if(a < b) cout << "Yes" << endl;
	else cout << "No" << endl;
	
    return 0;
}



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

long INF = 1000000000000000;

int main() {
	long A, B, Q; cin >> A >> B >> Q;
	set<long> s, t;
	s.insert(INF);
	s.insert(-INF);
	t.insert(INF);
	t.insert(-INF);
	for (int i = 0; i < A; i++) {
		long ps;
		cin >> ps;
		s.insert(ps);
	}
	for (int i = 0; i < B; i++) {
		long pt;
		cin >> pt;
		t.insert(pt);
	}


	for (int q = 0; q < Q; q++) {
		long x;
		cin >> x;

		long ls = abs(x - *(--s.upper_bound(x)));
		long rs = abs(x - *(s.lower_bound(x)));
		long lt = abs(x - *(--t.upper_bound(x)));
		long rt = abs(x - *(t.lower_bound(x)));

		cout << min(max(ls, lt), min(max(rs, rt), min(ls + rt + min(ls, rt), rs + lt + min(rs, lt)))) << endl;
	}

	return 0;
}

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

int main(){
	vector<int> v;
	int n,m,res = 0;
	cin >> n;
	for(int i = 0;i < n*2;i++){
		cin >> m;
		v.push_back(m);
	}
	sort(v.begin(),v.end());
	for(int i = 0;i < n;i++){
		res += v[i*2];
	}
	cout << res <<endl;
	return 0;
}

Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];

int main(){
	int N,M,K;
	//std::cin >> N;
    //std::cin >> N >> M;
    //std::cin >> N >> M >> K;
     string s;
     std::cin >> s;
    //std::vector<long long> v(N);
 	
 	//stack<int> sta;   
    //queue<int> que;
    
 	
    // 入力
    int cnt1;
    int cnt2;
    cnt1=0;
    cnt2=0;
    for(long long i=0; i<s.length(); i++){
		if(i%2==0){
		  if(s[i]!='0'){
			cnt2++;
		}
		}
		else{
		  if(s[i]!='1'){
			cnt2++;
		}
		}
	}
	for(long long i=0; i<s.length(); i++){
		if(i%2==0){
		  if(s[i]!='1'){
			cnt1++;
		}
		}
		else{
		  if(s[i]!='0'){
			cnt1++;
		}
		}
	}
	
    if(cnt1<cnt2){
    printf("%d",cnt1);
    }
    else{
		printf("%d",cnt2);
	}
    //printf("%d",N*M);
	return 0;
}

Measured memory_bytes: 512
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <cstddef>
#include <cstdint>

template <class T> const T &as_const(const T &v) noexcept { return v; }
class rep {
	const ::std::size_t f, l;

public:
	using value_type = ::std::size_t;
	using reference = value_type;
	class repitr {
		friend rep;
		value_type i;
		repitr(value_type x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		reference operator*() const noexcept { return i; }
		bool operator!=(const repitr x) const noexcept { return i != x.i; }
	};
	explicit rep(value_type first, value_type last) noexcept
		: f(first), l(last) {}
	repitr begin() const noexcept { return repitr(f); }
	repitr end() const noexcept { return repitr(l); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}

using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;

#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>

template <class T> using vec_alias = ::std::vector<T>;

u64 th(u64 a) {
	return a*a*a;
}

int main() {
	u64 n, k;
	::std::cin >> n >> k;
	u64 ret = th(n / k);
	if (!(k & 1)) {
		ret += th(n / (k >> 1) - n / k);
	}
	::std::cout << ret << ::std::endl;
	return 0;
}


Measured memory_bytes: 256
num = int(input())
L = [[ 0 for x in range(num)] for y in range(num)]
for _ in range(num):
    c,k,*v = [int(x)-1 for x in input().split()]
    for i in v:
        L[c][i] = 1
for i in range(num):
    print( *L[i] )




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

int main() {
  int N, P_cnt=0, W_cnt=0, G_cnt=0, Y_cnt=0;
  cin >> N;

  // ここにプログラムを追記
  for (int i = 0; i < N; i++)
  {
    string Color;
    cin >> Color;
    if (Color == "P") { P_cnt++;}
    if (Color == "W") { W_cnt++;}
    if (Color == "G") { G_cnt++;}
    if (Color == "Y") { Y_cnt++;}
  }
  if (P_cnt > 0 && W_cnt > 0 && G_cnt > 0 && Y_cnt > 0)
  {
    cout << "Four" << endl;
  } 
  else if (
    (P_cnt == 0 && W_cnt > 0  && G_cnt > 0  && Y_cnt >  0) ||
    (P_cnt > 0  && W_cnt == 0 && G_cnt > 0  && Y_cnt >  0) ||
    (P_cnt > 0  && W_cnt > 0  && G_cnt == 0 && Y_cnt >  0) ||
    (P_cnt > 0  && W_cnt > 0  && G_cnt > 0  && Y_cnt == 0)
    )
  {
    cout << "Three" << endl;
  }  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
#include <cmath>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define P(r) do{for(auto i:r){cout<<i<<' ';}cout<<'\n';}while(0)
int main()
{
    string s; cin >> s;
    int N = s.size();
    for (int c = 'a'; c <= 'z'; c++) {
        vector<bool> b(N);
        for (int i = 0; i < N; i++) b[i] = s[i] == c;
        for (int i = 0; i < N; i++) {
            if (!b[i]) continue;
            int ok = 1, ng = 0;
            while (i < N && ok >= ng) {
                i++;
                (b[i] ? ok : ng)++;
                if (ok + ng >= 2 && ok > ng) {
                    cout << i - (ok + ng) + 2 << " " << i + 1 << endl;
                    return 0;
                }
            }
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

void Do(int N){
  int i, A;
  double s;
  s = 0.;
  for(i = 0;i < N;i++){
    scanf("%d", &A);
    s += 1. / A;
  }
  printf("%g\n", 1 / s);
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,count1=0,count2=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%2==0)
        {
            count1++;
            if(a[i]%3==0 || a[i]%5==0)
            {
                count2++;
            }
        }
    }
    if(count1==count2)
    {
        cout<<"APPROVED";
    }
    else{cout<<"DENIED";}
}


Measured memory_bytes: 256
def megalomania(tasks)
  tasks.sort_by! { |task| task[1] }
  time = 0
  tasks.each do |task|
    if time + task[0] <= task[1]
      time += task[0]
    else
      return 'No'
    end
  end
  'Yes'
end

n = gets.to_i
tasks = []
n.times{ tasks << gets.split.map(&:to_i) }

puts megalomania(tasks)

Measured memory_bytes: 22520
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int cnt[3][4005];

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

  rep(i,N){
    if(i>0){
      rep(j,3) cnt[j][i] = cnt[j][i-1];
    }

    if(S[i] == 'R') cnt[0][i]++;
    if(S[i] == 'G') cnt[1][i]++;
    if(S[i] == 'B') cnt[2][i]++;
  }

  ll ret = 0;
  REP(i,1,N-1){
    if(S[i] == 'R'){
      ll lg = cnt[1][i-1];
      ll lb = cnt[2][i-1];
      ll rg = cnt[1][N-1] - cnt[1][i];
      ll rb = cnt[2][N-1] - cnt[2][i];
      ll tmp = lg*rb + lb*rg;
      int l=i-1, r=i+1;
      while(l>=0 && r<N){
        if((S[l] == 'G' && S[r] == 'B') || (S[l] == 'B' && S[r] == 'G')){
          tmp--;
        }
        l--;
        r++;
      }
      ret += tmp;
    }
    else if(S[i] == 'G'){
      ll lr = cnt[0][i-1];
      ll lb = cnt[2][i-1];
      ll rr = cnt[0][N-1] - cnt[0][i];
      ll rb = cnt[2][N-1] - cnt[2][i];
      ll tmp = lr*rb + lb*rr;
      int l=i-1, r=i+1;
      while(l>=0 && r<N){
        if((S[l] == 'R' && S[r] == 'B') || (S[l] == 'B' && S[r] == 'R')){
          tmp--;
        }
        l--;
        r++;
      }
      ret += tmp;
    }
    else {//B
      ll lr = cnt[0][i-1];
      ll lg = cnt[1][i-1];
      ll rr = cnt[0][N-1] - cnt[0][i];
      ll rg = cnt[1][N-1] - cnt[1][i];
      ll tmp = lr*rg + lg*rr;
      int l=i-1, r=i+1;
      while(l>=0 && r<N){
        if((S[l] == 'R' && S[r] == 'G') || (S[l] == 'G' && S[r] == 'R')){
          tmp--;
        }
        l--;
        r++;
      }
      ret += tmp;
    }
  }
  
  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>
#include <stack>

using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;

int main() {
  int s,w;
  cin >> s >> w;
  if(w >= s) {
    cout << "unsafe" << endl;
  }else {
    cout << "safe" << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
  
// #define int long long
#define pb push_back
  
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
 
template <class X> void print(X Target){ cout << Target << '\n'; }

bool less_len(string lhs, string rhs)
{
  if (lhs.size() != rhs.size()){
    return (lhs.size() < rhs.size());
  }
  else {
    return (lhs < rhs);
  }
}

signed main()
{
  ios::sync_with_stdio(false);
  map<string, int> order;
  vector<string> product;
  int n;

  cin >> n;
  while (n--){
    string input;
    int num;
    cin >> input >> num;
    bool same = false;
    for (int i = 0; i < product.size(); i++){
      if (product[i] == input){
        same = true;
        break;
      }
    }
    if (!same){
      product.pb(input);
      order[input] = num;
    }
    else {
      order[input] += num;
    }
  }

  sort(product.begin(), product.end(), less_len);
  for (int i = 0; i < product.size(); i++){
    cout << product[i] << " " << order[product[i]] << '\n';
  }

  return (0);
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
#define int long long
int ax[]={1,-1,0,0};
int ay[]={0,0,-1,1};
struct Dice{
  char s[6];
  void roll(char c){
    //the view from above
    // N
    //W E
    // S
    //s[0]:top
    //s[1]:south
    //s[2]:east
    //s[3]:west
    //s[4]:north
    //s[5]:bottom
    int b;
    if(c=='E'||c==0){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'||c==1){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'||c==2){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'||c==3){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    
    // migi neji (not verified)
    if(c=='R'){
      b=s[1];
      s[1]=s[3];
      s[3]=s[4];
      s[4]=s[2];
      s[2]=b;
    }
    if(c=='L'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }
    
  }
  char top() {
    return s[0];
  }
  char bottom() {
    return s[5];
  }

  int hash(){
    int res=0;
    for(int i=0;i<6;i++) res=res*256+s[i];
    return res;
  }
  
};

vector<Dice> makeDices(Dice d){
  vector<Dice> res;
  for(int i=0;i<6;i++){
    Dice t(d);
    if(i==1) t.roll('N'); 
    if(i==2) t.roll('S'); 
    if(i==3) t.roll('S'),t.roll('S');
    if(i==4) t.roll('L'); 
    if(i==5) t.roll('R'); 
    for(int k=0;k<4;k++){
      res.push_back(t);
      t.roll('E');
    }
  }
  return res;
}
struct st{
  int y,x,b,d;
  st(){}
  st(int y,int x,int b,int d):y(y),x(x),b(b),d(d){}
};
int dp[33][33][7][24];
signed main(){
  Dice d;
  string s="rmbygc";
  for(int i=0;i<6;i++) d.s[i]=s[i];
  vector<Dice> ds=makeDices(d);
  map<int,int> m;
  assert((int)ds.size()==24);
  for(int i=0;i<24;i++) m[ds[i].hash()]=i;

  int h,w;
  while(cin>>w>>h,h||w){
    //cout<<h<<" "<<w<<endl;
    string c[h];
    for(int i=0;i<h;i++) cin>>c[i];
    string v;
    cin>>v;
    memset(dp,-1,sizeof(dp));
    queue<st> q;
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	if(c[i][j]=='#')
	  dp[i][j][0][0]=0,q.push(st(i,j,0,0));
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)
	if(c[i][j]=='#') c[i][j]='w';
    
    int ans=-1;
    while(!q.empty()){
      st p=q.front();q.pop();
      int y=p.y,x=p.x,b=p.b;
      //cout<<y<<" "<<x<<" "<<b<<" "<<p.d<<":"<<dp[y][x][b][p.d]<<endl;
      if(b>=6){
	ans=dp[y][x][b][p.d];
	break;
      }
      d=ds[p.d];
      for(int k=0;k<4;k++){
	int ny=y+ay[k],nx=x+ax[k],nb=b;
	if(ny<0||h<=ny||nx<0||w<=nx) continue;
	if(c[ny][nx]=='k') continue;
	Dice t(d);
	t.roll(k);
	int nc=dp[y][x][b][p.d]+1,nd=m[t.hash()];
	if(c[ny][nx]=='w'){
	  if(dp[ny][nx][nb][nd]<0){
	    dp[ny][nx][nb][nd]=nc;
	    q.push(st(ny,nx,nb,nd));
	  }
	}else if(c[ny][nx]==v[b]&&t.top()==v[b]){
	  nb++;
	  if(dp[ny][nx][nb][nd]<0){
	    dp[ny][nx][nb][nd]=nc;
	    q.push(st(ny,nx,nb,nd));
	  }
	}
      }
    }
    if(ans<0) cout<<"unreachable"<<endl;
    else cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 4600
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
int w,h,n,x,y,a;
cin >> w >> h>>n;
int p[h][w];
for(int i=0;i<h;i++)for(int j=0;j<w;j++) p[i][j]=0;
for(int i=0;i<n;i++){
  cin >> x >> y>> a;
  if(a==1) {
    for(int j=0;j<h;j++){
    for(int i=0;i<x;i++){
      p[j][i]=1;
    }
  }
  }
  if(a==2) {
    for(int j=0;j<h;j++){
    for(int i=x;i<w;i++){
      p[j][i]=1;
    }
  }
  }
  if(a==3) {
    for(int i=0;i<y;i++){
      for(int j=0;j<w;j++){
      p[i][j]=1;
    }
  }
  }
  if(a==4) {
    for(int i=y;i<h;i++){
    for(int j=0;j<w;j++){
      p[i][j]=1;
    }
  }
  }
}
int cnt=0;
for(int i=0;i<h;i++){
  for(int j=0;j<w;j++){
  if(p[i][j]==0)  cnt++;
  }
}
cout << cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> sum(N + 2, 0);
  ll ans = 0;
  for (int i = 0; i < N + 1; i++) {
    sum[i + 1] += sum[i] + i;
    //cout << sum[i + 1] << endl;
  }
  for (int i = K; i < N + 2; i++) {
    ll l = sum[i] - 1;
    ll r = sum[N + 1] - sum[N + 1 - i];
    ans += (r - l);
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4848
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int M = sc.nextInt();
      
      // 偶数+偶数の方法の数を算出
      int even = 0;
      if(N >= 2){
        even = N * (N-1) / 2;
      }
      
      // 奇数+奇数の方法の数を算出
      int odd = 0;
      if(M >= 2){
        odd = M * (M-1) / 2;
      }
      
      // 方法の合計数
      int result = even + odd;
      
      // 出力
      System.out.println(result);
    }
    

}

Measured memory_bytes: 23764
# coding: utf-8
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
d = {}
for i in range(N):
    if A[i] in d.keys():
        d[A[i]] += 1
    else:
        d[A[i]] = 1
Q = int(input())
for i in range(Q):
    b, c = map(int, input().split())
    if b not in d.keys() or d[b] == 0:
        pass
    else:
        tmp = d[b]
        s -= d[b] * b
        s += d[b] * c
        d[b] = 0
        if c in d.keys():
            d[c] += tmp
        else:
            d[c] = tmp
    print(s)

Measured memory_bytes: 21040
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
#define INF 1e7
typedef pair<int, int> pii;
int h, w, x, x2, y, y2;
string grid[1000];
deque<pii> q;
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> h >> w >> x >> y >> x2 >> y2;
    x--, x2--, y--, y2--;
    for(int i = 0; i < h; i++) cin >> grid[i];
    vector<vector<int>> d(h, vector<int> (w, INF));
    d[x][y] = 0;
    q.push_front({x, y});
    while(!q.empty()){
        pii current = q.front();
        q.pop_front();
        if(current.first == x2 && current.second == y2) break;
        for(int i = -2; i <= 2; i++){
            for(int j = -2; j <= 2; j++){
                int row = current.first + i, col = current.second + j;
                if((row == current.first && col == current.second) || row < 0 || row >= h || col < 0 || col >= w || grid[row][col] == '#') continue;
                int w = 1;
                if((abs(row - current.first) == 1 && current.second == col) || (abs(col - current.second) == 1 && current.first == row)) w = 0;
                if(d[current.first][current.second] + w < d[row][col]){
                    d[row][col] = d[current.first][current.second] + w;
                    if(w) q.push_back({row, col});
                    else q.push_front({row, col});
                }
            }
        }
    }
    if(d[x2][y2] == INF) cout << -1;
    else cout << d[x2][y2];
    return 0;
}

Measured memory_bytes: 8808
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int A=sc.nextInt();
int B=sc.nextInt();
String S=sc.next();
int h=0;
for(int i=0;i<S.length();i++){
    if(i==A){
    if(S.charAt(i)=='-')h++;
    }else {
        if(S.charAt(i)=='-'){
        h=0;break;
        }
    }
    
}
if(h==1){System.out.println("Yes");}else{System.out.println("No");}

}
}

Measured memory_bytes: 22996
n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

for i in range(1000):
    num = list(str(i))
    if n != len(num):
        continue

    for s,c in sc:
        if num[s-1] != str(c):
            break
    else:
        print(i)
        exit()
    continue



print(-1)

Measured memory_bytes: 63132
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
void SRAND(){auto duration = std::chrono::system_clock::now().time_since_epoch();auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();srand(millis);}

ll ans,b[N],n;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	REP(i,n-1)cin>>b[i];
	ans=b[n-2]+b[0];
	REP(i,n-2)ans+=min(b[i],b[i+1]);
	cout<<ans<<"\n";
	return 0;
}



Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <x86intrin.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define V vector
template <typename T> bool chmin(T &a, const T &b) {if(a > b){a = b; return true;} return false;}
template <typename T> bool chmax(T &a, const T &b) {if(a < b){a = b; return true;} return false;}
template<typename A, size_t N, typename T> void Fill (A (&array)[N], const T & val) {fill ((T*)array, (T*)(array+N), val);}
V<int> dx = {-1, 1,  0, 0, -1, -1,  1, 1};
V<int> dy = { 0, 0, -1, 1, -1,  1, -1, 1};


// WeightedUnionFind
// coding:    https://youtu.be/TdR816rqc3s?t=726
// comment:   https://youtu.be/TdR816rqc3s?t=6822
// reference: https://qiita.com/drken/items/cce6fc5c579051e64fab
template<class Abel> struct WeightedUnionFind {
    vector<int> par;
    vector<Abel> diff_weight;
    WeightedUnionFind(int n=0, Abel SUM_UNITY=0): par(n,-1), diff_weight(n,SUM_UNITY) {}
    int root(int x) {
        if (par[x] < 0) return x;
        int r = root(par[x]);
        diff_weight[x] += diff_weight[par[x]];
        return par[x] = r;
    }
    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x,y), w = -w;
        par[x] += par[y];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -par[root(x)];}
    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }
    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main () {
    int n, m; cin >> n >> m;
    WeightedUnionFind<int> uf(n);
    rep(i, m) {
        int l, r, d; cin >> l >> r >> d; l--; r--;
        if (uf.same(l, r)) {
            int diff = uf.diff(l, r);
            if (diff != d) {
                puts("No");
                return 0;
            }
        }
        else {
            uf.merge(l, r, d);
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

const int maxV = 12345;
vector<int> graph[maxV];
int res[maxV];
bool visited[maxV];

int main(){
	int n; cin >> n;
	for( int i = 0; i < n-1; ++i ){
		int a, b; cin >> a >> b; --a; --b;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	vector<ll> c(n);
	for( auto &k : c ) cin >> k;
	if( n == 1 ){
		cout << 0 << endl;
		return 0;
	}
	cout << accumulate( c.begin(), c.end(), 0ll ) - *max_element( c.begin(), c.end() ) << endl;
	sort( c.begin(), c.end(), greater<ll>() );
	queue<int> q;
	q.push(0);

	int pnt = 0;
	while( !q.empty() ){
		int e = q.front(); q.pop();
		res[e] = c[pnt];
		visited[e] = true;
		for( auto to : graph[e] ){
			if( !visited[to] ) q.push(to);
		}
		++pnt;
	}
	for( int i = 0; i < n; ++i ){
		cout << res[i];
		if( i != n-1 ) cout << ' ';
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(c, i, n) for (int i = c; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    int count = 0;
    rep(0, i, N)
    {
        cin >> p.at(i);
        if (p.at(i) != i + 1)
        {
            count++;
        }
    }
    if (count > 2)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << " YES" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
arr = sorted([int(x) for x in input().split()])
total = 0
x = n-2
c = 0
for i in range(2, n):
    total += arr[x]
    c += 1
    if c == 2:
        c = 0
        x -= 1
print(total+arr[-1])


Measured memory_bytes: 31680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin>>n;
  vector<int> vec(n);
  vector<int> kawari(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
    kawari.at(i)=vec.at(i);
  }
  sort(kawari.begin(), kawari.end());
  reverse(kawari.begin(), kawari.end());
  if(kawari.at(0)==kawari.at(1)){
    k=1;
  }
  else{
    k=0;
  }
  for (int i = 0; i < n; i++) {
    if(vec.at(i)==kawari.at(0)){
      cout<<kawari.at(1)<<endl;
    }
    else{
      cout<<kawari.at(0)<<endl;
    }
  }
}
        

Measured memory_bytes: 3200
#include <iostream>
#include <vector>

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n)                       _range(i, 0, n)
#define _range(i, a, b)                  for (int i = int(a); i < int(b); ++i)
#define rep(...)                         _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)

#define _rrep(i, n)      _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...)        _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)

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


using ll = long long;
using namespace std;

using edge    = struct { int to, cap, cost, rev; };
using G       = vector<vector<edge>>;
const int inf = 1 << 29;

void add_edge(G &graph, int a, int b, int c, int d) {
    graph[a].push_back({b, c, d, int(graph[b].size())});
    graph[b].push_back({a, 0, -d, int(graph[a].size() - 1)});
}

int min_cost_flow(G &graph, int s, int t, int f) {
    using W = ll;
    W res   = 0;
    while (f) {
        int n = graph.size();
        int update;
        vector<W> dist(n, inf), pv(n, 0), pe(n, 0);
        dist[s] = 0;

        rep(loop, n) {
            update = false;
            rep(v, n) rep(i, graph[v].size()) {
                edge &e = graph[v][i];
                if (e.cap > 0 && chmin(dist[e.to], dist[v] + e.cost)) {
                    pv[e.to] = v, pe[e.to] = i;
                    update = true;
                }
            }
            if (!update) break;
        }

        if (dist[t] == inf) return -1;

        int d = f;
        for (int v = t; v != s; v = pv[v]) chmin(d, graph[pv[v]][pe[v]].cap);
        f -= d, res += d * dist[t];

        for (int v = t; v != s; v = pv[v]) {
            edge &e = graph[pv[v]][pe[v]];
            e.cap -= d;
            graph[v][e.rev].cap += d;
        }
    }
    return res;
}

int main(void) {
    int n, m;
    cin >> n >> m;

    vector<string> s(n);
    rep(i, n) cin >> s[i];

    int counter = 0;
    int src, dst;
    vector<vector<int>> id(n, vector<int>(m, 0));


    rep(i, n) rep(j, m) {
        id[i][j] = counter++;
    }
    src = counter++;
    dst = counter++;


    G graph(counter);

    int number = 0;
    rep(i, n) rep(j, m) {
        if (s[i][j] == 'o') {
            number++;
            add_edge(graph, src, id[i][j], 1, 0);
        }

        if (s[i][j] != '#') { add_edge(graph, id[i][j], dst, 1, 0); }
    }

    rep(i, n) rep(j, m) {
        if (s[i][j] == '#') continue;

        if (i + 1 < n and s[i + 1][j] != '#') {
            add_edge(graph, id[i][j], id[i + 1][j], number, -1);
        }

        if (j + 1 < m and s[i][j + 1] != '#') {
            add_edge(graph, id[i][j], id[i][j + 1], number, -1);
        }
    }

    const auto ans = -min_cost_flow(graph, src, dst, number);

    // for (auto &edge: graph.edges()) {
    //     cerr << edge.from << " " << edge.to << " " << edge.cap << " "
    //          << edge.cost << " " << edge.flow << endl;
    // }

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


Measured memory_bytes: 3604
def nob(n):
    nob_h=[n+1]

    for i in range(n+1):
        if i==0 or i==1:
            nob_h.append(1)
        elif i==2:
            nob_h.append(2)
        elif i>2:
            nob_h.append(nob_h[i]+nob_h[i-1]+nob_h[i-2])


    days=int(nob_h[n+1]/10)

    year=int(days/365)+1

    print(year)

n=[]

while True:
    i=input()
    if i == "0":
        break
    n.append(i)

for i in range(len(n)):
    nob(int(n[i]))

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

int main(){
  int N,D[100000];
  cin>>N;
  for (int i(0);i<N;i++) cin>>D[i];
  int cnt[100000]={0};
  for (int i(0);i<N;i++) cnt[D[i]]++;
  int maxi(0);
  for (int i(0);i<N;i++) maxi = max(maxi,D[i]);
  if (D[0] != 0 || cnt[0] != 1){
    cout << 0 << endl;
    return 0;
  }
  for (int i(0);i<=maxi;i++){
    if (cnt[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans(1);
	//for (int i(0);i<3;i++) cout << cnt[i] << " ";
  for (int i(0);i<maxi;i++){
    ll tmp(1);
    for (int j(0);j<cnt[i+1];j++){
      tmp*=cnt[i];
      tmp%=mod;
    }
    ans*=tmp;
		ans%=mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);

   int A, B, C;
   cin >> A >> B >> C;
   
   int K;
   cin >> K;

   FOR(nA, 0, K) {
      FOR(nB, 0, K-nA) {
         FOR(nC, 0, K-nA-nB) {
            int a = A*(1<<nA);
            int b = B*(1<<nB);
            int c = C*(1<<nC);
            if (a < b && b < c) {
               DEBUG(nA, a, nB, b, nC, c);
               cout << "Yes\n";
               return 0;
            }
         }
      }
   }
   cout << "No\n";

   return 0;
}


Measured memory_bytes: 3664
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

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


//main関数
int main() {
	int X,N;
	scanf("%d %d",&X,&N);
	int p[N];
	int sakoda=0;
	for(int i=0;i<N;i++){
		scanf("%d",&p[i]);
		if(X == p[i]){
			sakoda =1;
		}
	}
	if(sakoda == 0){
		printf("%d",X);
		return 0;
	}
	
	 int andy;
	 int count = 1;
	while(1) {
		andy = 0;
		for(int i=0;i<N;i++){
			if(X-count == p[i]){
				andy = 1;
			}
		}
		if(andy == 0){
			printf("%d",X-count);
			return 0;
		}
		
		andy = 0;
		for(int i=0;i<N;i++){
			if(X+count == p[i]){
				andy = 1;
			}
		}
		if(andy == 0){
			printf("%d",X+count);
			return 0;
		}
		count++;
	}
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define lol long long
using namespace std;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,h,w;
  cin >>n>>h>>w;
  h=n-h+1;
  w=n-w+1;
  cout <<h*w<<'\n';
  return (0);
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	ll n, k;
	cin >> n >> k;
	map<ll, ll> m;
	int a[n], b[n];
	REP(i, n){
		cin >> a[i] >> b[i];
		m[a[i]] += b[i];
	}

	for (auto x : m){
		if (x.second >= k){
			cout << x.first << endl;
			return 0;
		}
		k -= x.second;
	}


}


Measured memory_bytes: 4992
from collections import Counter
from itertools import takewhile
n=int(input())
s=[input() for _ in range(n)]
count=Counter(s)
v=count.most_common()[0][-1]
it=takewhile(lambda kv: kv[-1]==v,count.most_common())
for t in sorted(list(it)):
    print(t[0])

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

using namespace std;

typedef long long ll;

const int N = 1e5 + 5;

int x, y, a, b, c;
ll A[N], B[N], C[N], D[N * 2];

int main() {
    ios::sync_with_stdio(false);
    cin >> x >> y >> a >> b >> c;
    for (int i = 1; i <= a; i++) cin >> A[i];
    for (int i = 1; i <= b; i++) cin >> B[i];
    for (int i = 1; i <= c; i++) cin >> C[i];
    sort(A + 1, A + 1 + a, [](int x, int y) {
        return x > y; 
    });
    sort(B + 1, B + 1 + b, [](int x, int y) {
        return x > y; 
    });
    sort(C + 1, C + 1 + c, [](int x, int y) {
        return x > y; 
    });
    int tot = 0;
    for (int i = 1; i <= x; i++) D[++tot] = A[i];
    for (int i = 1; i <= y; i++) D[++tot] = B[i];
    for (int i = 1; i <= c; i++) D[++tot] = C[i];
    sort(D + 1, D + 1 + tot, [](int x, int y) {
        return x > y; 
    });
    ll ans = 0;
    for (int i = 1; i <= x + y; i++) ans += D[i];
    cout << ans << '\n';
    return 0; 
}

Measured memory_bytes: 4224
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
   	 static List<ArrayList<Integer>> list= new ArrayList<ArrayList<Integer>>();
//	 static int mod = 998244353;
	 public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int X = sc.nextInt();
	        int Y = sc.nextInt();
	        int A = sc.nextInt();
	        int B = sc.nextInt();
	        int C = sc.nextInt();
	        
	        long[] a = new long[A];
	        for (int i=0 ; i<A; i++) {
	            a[i] = Long.parseLong(sc.next());
	        }
	        long[] b = new long[B];
	        for (int i=0 ; i<B; i++) {
	            b[i] = Long.parseLong(sc.next());
	        }
	        long[] c = new long[C+1];
	        for (int i=0 ; i<C; i++) {
	            c[i] = Long.parseLong(sc.next());
	        }
	        Arrays.sort(a);
	        Arrays.sort(b);
	        Arrays.sort(c);
	        
	        long[] d=new long[X+Y];
	        for(int i=0;i<X;i++) {
	        	d[i]=a[A-1-i];
	        }
	        for(int i=0;i<Y;i++) {
	        	d[X+i]=b[B-1-i];
	        }
	        Arrays.sort(d);
	     	   int right=C+1;
	     	   int left=-1;
	     	   while(right-left>1) {
	     		   int mid=left+(right-left)/2;
	     		   if(mid>C)left=mid;
	     		   else if(mid>=X+Y||c[C-mid]<d[mid]) right=mid;
	     		   else left=mid;
	     	   }
	     	
	     	long ans=0;
	     	for(int i=0;i<X+Y-right;i++) {
	     		ans=ans+d[X+Y-i-1];
	     	}
	        for(int i=0;i<right;i++) {
	        	ans=ans+c[C-i];
	        }
	        
	        
	        	System.out.println(ans);
	        	        	        
	 }
}

Measured memory_bytes: 63500
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();

    List<String> cities = new ArrayList<>(n);
    List<Integer> scores = new ArrayList<>(n);

    for (int i = 0; i < n; i++) {
      cities.add(sc.next());
      scores.add(sc.nextInt());
    }

    IntStream.range(0, n)
        .boxed()
        .sorted((i1, i2) ->
            cities.get(i1).equals(cities.get(i2)) ? -scores.get(i1).compareTo(scores.get(i2)) :
                cities.get(i1).compareTo(cities.get(i2))
        ).map(i -> i + 1)
        .forEach(os::println);
  }
}

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

using namespace std;

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

	int X, Y, Z;
	cin >> X >> Y >> Z;
	swap(X, Y);
	swap(X, Z);
	cout << X << " " << Y << " " << Z << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args){
        int s;
        int m;
        int h;
        Scanner sc= new Scanner(System.in);
        s =sc.nextInt();
        m =s/60;
        h =m/60;
        s =s%60;
        m =m%60;
        h =h%60;
        System.out.println(h+":"+m+":"+s);
    }
}

Measured memory_bytes: 17356
#include<iostream>
using namespace std;
#include<queue>
#include<vector>
#include<algorithm>
#define int long long int
#define mod 1000000007;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    int arr1[a];
    int arr2[b];
    int arr3[c];
    int j;
    for(j=0;j<a;j++)
       cin>>arr1[j];
    for(j=0;j<b;j++)
       cin>>arr2[j];
    for(j=0;j<c;j++)
    {
		cin>>arr3[j];
	}
	sort(arr1,arr1+a);
	sort(arr2,arr2+b);
	sort(arr3,arr3+c);
	vector<int> v1,v2;
	int i=0;
	int ptr=a-1;
	for(i=0;i<x;i++)
	{
		v1.push_back(arr1[ptr]);
		ptr--;
	}
	ptr=b-1;
	for(i=0;i<y;i++)
	{
		v2.push_back(arr2[ptr]);
		ptr--;
	}
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    i=0;
    j=0;
    int k=c-1;
    while(i<x&&j<y&&k>=0)
    {
		int val=arr3[k];
		if(v1[i]<v2[j])
		{
			v1[i]=max(v1[i],val);
			i++;
		}
		else
		{
			v2[j]=max(v2[j],val);
			j++;
		}
		k--;
	}
	if(i==x)
	{
		while(j<y&&k>=0)
		{
			v2[j]=max(v2[j],arr3[k]);
			j++;
			k--;
		}
	}
	if(j==y)
	{
		while(i<x&&k>=0)
		{
			v1[i]=max(v1[i],arr3[k]);
			i++;
			k--;
		}
	}
	int answer=0;
	for(i=0;i<x;i++)
	   answer+=v1[i];
	for(i=0;i<y;i++)
	  answer+=v2[i];
    cout<<answer<<endl;
}


Measured memory_bytes: 4852
#include <stdio.h>
#include <math.h>

int mypow(int a, int b)
{
    int i, ans = 1;
    for (i = 0; i < b; i++)
    {
        ans *= a;
    }
    return ans;
}

int main()
{
    int n, i, j,k,h[100000];
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &h[i]);
    }
    /* if(n==1)
    {
        printf("Yes");
        return 0;
    }*/
    for (i = n-1; i>0; i--)
    {
        if(h[i-1]>h[i])
        {
            h[i-1] -= 1;
        }
    }
    for (i = 0; i < n - 1; i++)
    {
        if (h[i] > h[i + 1])
        {
            printf("No");
            return 0;
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 512
n = int(input())
r = [list(map(int,input().split())) for _ in range(n)]
b = [list(map(int,input().split())) for _ in range(n)]
r.sort(key=lambda x:x[1])
b.sort()
cnt = 0
for i in range(n):
    R = []
    for j in range(n):
        if 0 <= r[j][0] < b[i][0] and 0 <= r[j][1] < b[i][1]:
            R.append([r[j][1],j])
            
    R.sort(reverse=True)
    if len(R) >= 1:
        cnt += 1
        r[R[0][1]][0] = -1
        r[R[0][1]][1] = -1

print(cnt)

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

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 998244353;
const int N   = 2e2 + 2;    

pp A[N];
int iki[N];

signed main(){  
    int n;
    cin >> n;
    for(int i=iki[0]=1; i<=n; i++)
        iki[i] = iki[i-1] * 2 % mod;
    
    int ans = 0;
    for(int i=1; i<=n; i++){
        int x, y;
        cin >> x >> y;
        A[i] = mp(x,y);
        map < pp , int > M;
        for(int j=1; j<i; j++){
            pp t = A[j];    
            int a = x - t.st;
            int b = y - t.nd;
            if(a < 0){ a = -a; b = -b; }
                M[ mp(a / __gcd(a,b) , b / __gcd(a,b)) ]++;
        }
        
        map < pp , int > :: iterator it;
        for(it=M.begin(); it!=M.end(); it++){
            if(it->nd == 0) cout << "wtf";    
            ans = (ans + iki[ it->nd ] - 1) % mod;
    
        }
    }
    
    
    cout << (iki[n] - ans - n - 1 + mod) % mod;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

namespace MyInputAndOutput{
    class user_input  {} cin;
    class user_output {} cout;

    // 入力関係
    inline user_input& operator >> (user_input& stream, int& int_arg){
        scanf("%d", &int_arg); return stream;
    }
    inline user_input& operator >> (user_input& stream, long long int& int_arg){
        scanf("%lld", &int_arg); return stream;
    }
    template <typename T>
    inline user_input& operator >>(user_input& stream, std::vector<T>& vec){
        for(T& ele : vec) stream >> ele; return stream;
    }

    // 出力関係
    inline user_output& operator << (user_output& stream, const int int_arg){
        printf("%d", int_arg); return stream;
    }
    inline user_output& operator << (user_output& stream, const long long int int_arg){
        printf("%lld", int_arg); return stream;
    }
    inline user_output& operator << (user_output& stream, const char char_arg){
        putchar(char_arg); return stream;
    }
    template <typename T>
    inline user_output& operator << (user_output& stream, std::vector<T>& vec){
        const size_t size_of_vector = vec.size();
        if(size_of_vector == 0) return stream;
        stream << vec[0]; for(size_t index = 1; index < size_of_vector; ++index) stream << ' ' << vec[index];
        return stream;
    }
}; namespace MIO = MyInputAndOutput;

std::vector<int> A, B;

int main(void){
    int n; MIO::cin >> n;
    A.resize(n); MIO::cin >> A;
    B.resize(n); for(int i = 0; i < n; ++i) B[A[i] - 1] = i + 1;
    MIO::cout << B << '\n';
    return 0;
}

Measured memory_bytes: 1536
import sys
n = int(input())
a = list(map(int, input().split()))
q = 0
if q in a:
    print('0')
    sys.exit()
ans = 1
for i in range(n):
    ans = ans*a[i]
    if ans>10**18:
        print('-1')
        sys.exit()

print(ans)

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

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  long double a, b;
  cin >> a >> b;

  cout << (ll)(a * b) << endl;
  return 0;
}

Measured memory_bytes: 3792
main :: IO ()
main = do
  ls <- getLine
  let ls' = map read . words $ ls
  if any (0 > ) ls'
    then return ()
    else do
      print $ solve ls'
      main

solve :: [Int] -> Int
solve [y1,m1,d1,y2,m2,d2] = (getDay y2 m2 d2) - (getDay y1 m1 d1)
  where
    getDay :: Int -> Int -> Int -> Int
    getDay y m d = 365 * (y - 1) + (uru (y-1)) + (getDay2 y m d)
      where
        uru :: Int -> Int
        uru y = (y `div` 4) - (y `div` 100) + (y `div` 400)

        getDay2 :: Int -> Int -> Int -> Int
        getDay2 y m d = (sumDay (m-1) (months y)) + d

        sumDay :: Int -> [Int] -> Int
        sumDay 0 _ = 0
        sumDay n (x:xs) = x + (sumDay (n - 1) xs)

        months :: Int -> [Int]
        months y
          | ((y `mod` 4) == 0 && (y `mod` 100) /= 0) || (y `mod` 400) == 0 = [31,29,31,30,31,30,31,31,30,31,30,31]
          | otherwise = [31,28,31,30,31,30,31,31,30,31,30,31]

Measured memory_bytes: 4048
#include <stdio.h>

int weights[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};

int get_ans(int a, int rem)
{
	int i = a-1;

	while(rem >= weights[i] || i >= 0){
		if(rem > weights[i]) break;
		else if(rem == weights[i]) return weights[i];

		i--;
	}

	printf("%d ", get_ans(i, rem - weights[i]));

	return weights[i];
}

int main()
{
	int G, A;

	while(scanf("%d", &G) != EOF){
		printf("%d", get_ans(10, G));
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 600
N = int(input())
A = list(map(int, input().split()))
Adict = {}
for i in A:
    if i in Adict:
        Adict[i]=Adict[i]+1
    else:
        Adict.update({i:1})
B = [0, 0]
for i in Adict.keys():
    if Adict[i] >= 2:
        B.append(i)
    if Adict[i] >= 4:
        B.append(i)
B.sort()
print(B[-1]*B[-2])


Measured memory_bytes: 18060
N,M = map(int,input().split())
ls2 = []
for i in range(M):
    ls1 = list(map(int,input().split()))
    ls2.append(ls1)

ans = -1
if M == 0:
    if N==1:
        ans = 0
    else:    
        ans = 10**(N-1)
if N == 1:
    for i in range(10):
        for j in range(M):
            if not i//(10**(N-ls2[j][0]))%10 == ls2[j][1]:
                break
            if j == M-1:
                ans = i
                break
        if not ans == -1:
            break   

else:
    for i in range(10**(N-1),10**N):
        for j in range(M):
            if not i//(10**(N-ls2[j][0]))%10 == ls2[j][1]:
                break
            if j == M-1:
                ans = i
                break
        if not ans == -1:
            break
print(ans)          


Measured memory_bytes: 9168
#include <iomanip>
#include <string>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
const int inf = 10000;
long long int h, w, yan[10][10], a[210][210], ans = 0;
long long int calc(long long int A, long long int B) {
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				yan[i][j] = min(yan[i][j], yan[i][k] + yan[k][j]);
			}
		}
	}
	return yan[A][B];
}
int main()
{
	cin >> h >> w;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> yan[i][j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <=w; j++) {
			cin >> a[i][j];
			if (a[i][j] > 1||a[i][j]==0) {
				ans += calc(a[i][j], 1);
			}
		}
	}
	cout << ans << endl;
	return 0;
}	

Measured memory_bytes: 640