akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define MAX_N 200010
struct UF
{
	int par[MAX_N]; // 親
	// 初期化
	UF() {
		for(int i = 0; i < MAX_N; i++){
			par[i] = i;
		}
	}
	// 木の根を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		// 木の高さが高い方を代表ノードにする
		par[x] = y;
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
};

map<pair<int,int>,int> mp;

int main()
{
	UF D;
	UF T;
	
	int n,k,l;cin >> n >> k >> l;
	
	REP(i,k)
	{
		int p,q;cin>> p>>q;
		D.unite(p-1,q-1);
	}
	REP(i,l)
	{
		int r,s;cin>>r>>s;
		T.unite(r-1,s-1);
	}
	
	REP(i,n)
	{
		int a = D.find(i);int b = T.find(i);
		if(mp.find(MP(a,b)) == mp.end())mp[MP(a,b)] = 1;
		else mp[MP(a,b)]++;
	}
	
	REP(i,n-1)
	{
		cout << mp[MP(D.find(i),T.find(i))] << ' ';
	}
	cout << mp[MP(D.find(n-1),T.find(n-1))] << endl;
	
	return 0;
}

Measured memory_bytes: 13696
var
	S:String;
	N,P,w,k,i,t:Longint;
	cnt:Array[0..9999]of Longint;
	ans:int64;
begin
	readln(N,P);
	readln(S);
	cnt[0]:=1;
	k:=1;
	for i:=N downto 1 do begin
		t:=ord(S[i])-48;
		k:=k*10 mod P;
		if k=0 then if t mod p=0 then inc(ans,i)else else begin
			w:=(w+k*t)mod P;
			inc(ans,cnt[w]);
			inc(cnt[w]);
		end;
	end;
	writeln(ans);
end.


Measured memory_bytes: 384
n, k = map(int, input().split())
l = list(map(int, input().split()))

import collections
c = collections.Counter(l)
c2=[i for i in c.items()]
c2.sort(key=lambda x: x[1])
ans=0
for i in range(len(c2)-k):
    ans+=c2[i][1]

print(ans)

Measured memory_bytes: 105544
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
int main() {
        fast;
        ll n;
        cin >> n;
        int a[]= {500,100,50,10,5,1};
        
        ll ans = 0;
        while(n >4){
            if(n >= 500){
                n = n-500;
                ans +=1000;
            }
            else if(n >= 100){
                n = n- 100;
                ans += 100;
            }
            else if(n >= 50){
                n = n- 50;
                ans += 50;
            }
            else if(n >= 10){
                n = n- 10;
                ans += 10;
            }
            else if(n >= 5){
                n = n- 5;
                ans += 5;
            }
        }
        cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int N = 3004;
int dp[N][N], par[N][N];
string s, t;
int n, m;

void solve() {
   for (int i = 0; i <= n; ++i) dp[i][0] = 0;
   for (int j = 0; j <= m; ++j) dp[0][j] = 0;

   for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j)
   {
      if (s[i] == t[j]) dp[i][j] = dp[i-1][j-1] + 1;
      else {
         if (dp[i-1][j] > dp[i][j-1]) dp[i][j] = dp[i-1][j];
         else dp[i][j] = dp[i][j-1];
      }
   }

   string longest_ssq = "";
   int i = n, j = m;
   while (i && j) {
      if (s[i] == t[j]) longest_ssq += s[i], --i, --j;
      else if (dp[i][j] == dp[i-1][j]) --i;
      else --j;
   }
   reverse(longest_ssq.begin(), longest_ssq.end());
   cout << longest_ssq << "\n";
}

signed main() {
   IOS; PREC;
   cin >> s >> t;
   n = (int)s.size(), m = (int)t.size();
   s = " " + s, t = " " + t;
   solve();

   return EXIT_SUCCESS;
}


Measured memory_bytes: 35968
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
int main(){
  int n;cin >> n;
  vector<vector<int>> a(n,vector<int>(n-1));
  rep(i,n){
    rep(j,n-1){
      cin >> a[i][j];
      a[i][j]--;
    }
    reverse(a[i].begin(),a[i].end());
  }
  vector<P> q;
  auto check = [&](int i){
    if(a[i].size()==0) return;
    int j = a[i].back();
    if(a[j].size()==0) return;
    if(a[j].back()==i){
      P p(i,j);
      if(p.second<p.first) swap(p.first,p.second);
      q.push_back(p);
    }
  };
  rep(i,n){
    check(i);
  }
  int day = 0;
  while(q.size()>0){
    day++;
    sort(q.begin(),q.end());
    q.erase(unique(q.begin(),q.end()),q.end());
    vector<P> prevQ;
    swap(prevQ,q);
    for(P p : prevQ){
      int i = p.first,j=p.second;
      a[i].pop_back();
      a[j].pop_back();
    }
    for(P p : prevQ){
      int i=p.first,j=p.second;
      check(i);
      check(j);
    }
  }
  rep(i,n){
    if(a[i].size()!=0){
      puts("-1");
      return 0;
    }
  }
  cout << day << endl;
  return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ans = 1;
        for (int i = 1; i <= 5; i++) {
            int x = sc.nextInt();
            if (x == 0) {
                ans = i;
            }
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 35500
s = input()
t = input()

if len(t)>len(s):
  print("UNRESTORABLE")
  exit()

ans = []

for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != t[j] and s[i+j]!='?':
      # print('Aの方')
      break
  else:
      #:iまでの文字はSを引き継ぎ、tを足し、残りは引き継ぎ、?部分はaに
      # print('Bの方')
    ans.append((s[:i]+t+s[i+len(t):]).replace('?','a'))
      # print('s[i+j]',s[i+j],"t[j]",t[j])
      # print('i',i,"j",j)
      # print(ans)

if len(ans) == 0:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(ans[0])


Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a);

        int diff = 0;
        for (int i = 1; i < n; i++) {
            diff += a[i] - a[i-1];
        }

        System.out.println(diff);
    }
}


Measured memory_bytes: 21844
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXLEN=3000;

char s[MAXLEN+1]; int slen;
char t[MAXLEN+1]; int tlen;

int dp[MAXLEN+1][MAXLEN+1];
int act[MAXLEN+1][MAXLEN+1];
char ans[MAXLEN+1]; int nans;

void upd(int i,int j,int val,int a) {
	if(val<=dp[i][j]) return;
	dp[i][j]=val,act[i][j]=a;
}

void solve() {
	memset(dp,-1,sizeof(dp)); upd(0,0,0,-1);
	REPE(i,slen) REPE(j,tlen) if(dp[i][j]!=-1) {
		if(i<slen) upd(i+1,j,dp[i][j],0);
		if(j<tlen) upd(i,j+1,dp[i][j],1);
		if(i<slen&&j<tlen&&s[i]==t[j]) upd(i+1,j+1,dp[i][j]+1,2);
	}
	nans=0;
	for(int i=slen,j=tlen;act[i][j]!=-1;) {
		if(act[i][j]==0) { --i; continue; }
		if(act[i][j]==1) { --j; continue; }
		if(act[i][j]==2) { --i,--j; ans[nans++]=s[i]; continue; }
		assert(false);
	}
	reverse(ans,ans+nans);
}

void run() {
	scanf("%s",s); slen=strlen(s);
	scanf("%s",t); tlen=strlen(t);
	solve();
	printf("%s\n",ans);
}

int main() {
	run();
	return 0;
}


Measured memory_bytes: 70656
#pragma GCC optimize ("-O3")
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
ll NUM = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define zer ll(0)
 

int main()
{
    ll n;
    string s;
    cin>>n>>s;
    char c;
    c = s[0];
    ll num=1;

    forsn(i,1,n)
    {
        if(s[i]!=c)
        {
            num+=1;
            c = s[i];
        }
    }

    cout<<num;
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  vector<ll> v; 
  rep(i,0,n){
    ll a;
    cin>>a;
    v.pb(a);
  }
  sort(all(v));
  cout << v[v.sz-1]-v[0] << endl;

  return 0;
}

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

int main()
{
  int ar[3][3];
  map<int,pair<int,int>> m;
  for(int i=0;i<3;i++)
  {
    for(int j=0;j<3;j++)
    {
      cin >> ar[i][j];
      m[ar[i][j]] = {i,j};
    }
  }
  int n;
  cin >> n;
  bool v[3][3] = {false};
  for(int i=0;i<n;i++)
  {
    int x;
    cin >> x;
    if(m.count(x))
    {
      v[m[x].first][m[x].second] = true;
    }
  }
  bool hit = false;
  // row
    if(v[0][0] && v[0][1] && v[0][2]) hit = true;
    if(v[1][0] && v[1][1] && v[1][2]) hit = true;
    if(v[2][0] && v[2][1] && v[2][2]) hit = true;
  // col
    if(v[0][0] && v[1][0] && v[2][0]) hit = true;
    if(v[0][1] && v[1][1] && v[2][1]) hit = true;
    if(v[0][2] && v[1][2] && v[2][2]) hit = true;
  // diag
  	if(v[0][0] && v[1][1] && v[2][2]) hit = true;
  	if(v[2][0] && v[1][1] && v[0][2]) hit = true;
  
  if(hit) cout << "Yes";
  else cout << "No";
  
}
  


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	char s[21];
	int i = 0,j;
	
	while(scanf("%c",&s[i]) != EOF){
		i++;
	}
	
	for(j = i-2;j >= 0;j--){
		printf("%c",s[j]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 936
eval"N,*A="+`dd`.split*?,;p N*2-1;b,a=A.minmax;c=A.index a;d=A.index b;S=?\s;N.times{|i|puts a>-b ?[[c+1,i+1]*S,[i,i+1]*S*-2[i]]:[[d+1,j=N-i]*S,[j+1,j]*S*-2[i]]}

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

int main(){
	// sengen
	LL n,k;
	cin >> n >> k;
	// nyuryoku
	LL a[n];
	for(LL i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a,a+n,greater<LL>());
	LL left = 0,right = a[0];
	LL mid;
	while(right - left > 1){
		LL count = 0;
		mid = (right + left)/2;
		for(LL i=0;i<n;i++){
			if(a[i] <= mid){
				break;
			}
			count += a[i]/mid + (a[i]%mid != 0) - 1;
		}
		if(count <= k){
			right = mid;
		}else{
			left = mid;
		}
	}
	// keisan

	// syutsuryoku
	cout << right << endl;
}

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

using namespace std;

#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-label"

#define DEBUG(x) cout << "> " << #x << ": " << x << endl;

typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
const int inf = 1e9+7;
const ll longinf = 1LL<<60;

// Start Coding...

void solve() {
    int K;
    cin >> K;
    if (K < 10) {
        cout << K << endl;
        return;
    }
    ll res = 0;
    int cnt = 9;
    queue<ll> q;
    for (ll i = 1; i <= 9; i++) q.push(i);
    while (1) {
        ll p = q.front(); q.pop();
        ll last = p % 10;
        if (last > 0) {
            q.push(p * 10 + last - 1);
            cnt++;
            if (cnt == K) {
                res = p * 10 + last - 1;
                break;
            }
        }
        q.push(p * 10 + last);
        cnt++;
        if (cnt == K) {
            res = p * 10 + last;
            break;
        }
        if (last < 9) {
            q.push(p * 10 + last + 1);
            cnt++;
            if (cnt == K) {
                res = p * 10 + last + 1;
                break;
            }
        }
    }
    cout << res << endl;
    return;
}

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

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

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

  long long suma = 0,sumb = 0;
  vector<long long> a(N),b(N);
  for(int i = 0;i < N;i++) {
    cin >> a.at(i);
    suma += a.at(i);
  }

  for(int i = 0;i < N;i++) {
    cin >> b.at(i);
    sumb += b.at(i);
  }

  long long rest = max(0LL,sumb-suma);

  long long numa = 0,numb = 0;
  for(int i = 0;i < N;i++) {
    if(a.at(i) < b.at(i)) {
      numa += (b.at(i)-a.at(i)+1) / 2;
      if(a.at(i)% 2 != b.at(i) % 2) numb++;
    }else if(a.at(i) > b.at(i)) numb += a.at(i)-b.at(i);
  }

  long long ra = rest-numa,rb = rest-numb;
  bool can = true;
  if(ra < 0 || rb < 0 || ra*2 != rb) can = false; 
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;

}



Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    map<ll, ll> d;
    for(int i=0; i<n; i++){
        ll a;
        cin >> a;
        d[a]++;
    }
    int m;
    cin >> m;
    for(int i=0; i<m; i++){
        ll t;
        cin >> t;
        if(d[t]<1){
            cout << "NO" << endl;
            return 0;
        }else{
            d[t]--;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12800
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstdlib>
//#include<>                                                                    
using namespace std;


int main(){
  long N,W;
  long v[101],w[101];
  cin>>N>>W;
  for(long i=0;i<N;i++)cin>>v[i]>>w[i];

  long dp[101][10001]={};
  for(long i=1;i<=N;i++){
    for(long j=0;j<=W;j++)
      if(j-w[i-1]>=0)dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
      else dp[i][j]=dp[i-1][j];
  }
  cout<<dp[N][W]<<endl;
  return 0;
}

Measured memory_bytes: 9060
from typing import List


class Dice:

    def __init__(self, surface: List[int]):
        self.surface = surface

    def get_upper_sursurface(self) -> int:
        return self.surface[0]

    def invoke_method(self, mkey: str) -> None:
        print(type(mkey))
        if mkey == 'S':
            self.S()
        if mkey == 'N':
            self.N()
        if mkey == 'E':
            self.E()
        if mkey == 'W':
            self.W()
        raise ValueError(f'This method does not exist. : {mkey}')

    def S(self) -> None:
        tmp = [i for i in self.surface]
        self.surface[0] = tmp[4]
        self.surface[1] = tmp[0]
        self.surface[2] = tmp[2]
        self.surface[3] = tmp[3]
        self.surface[4] = tmp[5]
        self.surface[5] = tmp[1]

    def N(self) -> None:
        tmp = [i for i in self.surface]
        self.surface[0] = tmp[1]
        self.surface[1] = tmp[5]
        self.surface[2] = tmp[2]
        self.surface[3] = tmp[3]
        self.surface[4] = tmp[0]
        self.surface[5] = tmp[4]

    def E(self) -> None:
        tmp = [i for i in self.surface]
        self.surface[0] = tmp[3]
        self.surface[1] = tmp[1]
        self.surface[2] = tmp[0]
        self.surface[3] = tmp[5]
        self.surface[4] = tmp[4]
        self.surface[5] = tmp[2]

    def W(self) -> None:
        tmp = [i for i in self.surface]
        self.surface[0] = tmp[2]
        self.surface[1] = tmp[1]
        self.surface[2] = tmp[5]
        self.surface[3] = tmp[0]
        self.surface[4] = tmp[4]
        self.surface[5] = tmp[3]


data = [int(i) for i in input().split()]
order = list(input())
# data = [int(i) for i in '1 2 4 8 16 32'.split()]
# order = list('EESWN')

dice = Dice(data)
for o in order:
    if o == 'S':
        dice.S()
    if o == 'N':
        dice.N()
    if o == 'E':
        dice.E()
    if o == 'W':
        dice.W()

    # dice.invoke_method(o)
print(dice.get_upper_sursurface())



Measured memory_bytes: 7188
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define ll long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int main()
{
    int n,m,sum;
    scanf("%d %d",&n,&m);
    for(int i=1;i<n;i++){
        sum+=i;
    }
    for(int i=1;i<m;i++){
        sum+=i;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

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

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

void outYesOrNo(bool res)
{
    cout << (res ? "Yay!" : ":(") << endl;
}

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

    int n, a[112345];

    cin >> n;

    ll res = 1;

    int cnt[112345];

    memset(cnt, 0, sizeof(cnt));

    REP(i, n)
    {
        cin >> a[i];

        if (a[i] > 0)
        {
            (res *= cnt[a[i] - 1] - cnt[a[i]]) %= MOD;
        }
        else
        {
            (res *= 3 - cnt[a[i]]) %= MOD;
        }

        cnt[a[i]]++;
    }

    cout << res << endl;

    return 0;
}

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

int main()
{
 int x,n;
 cin>>x>>n;
 vector<int>a(n);
 int mindif=INT_MAX;
 int min=INT_MAX,cnt;
 for(int i=0;i<n;i++)
 {
  cin>>a[i];  
 }
 vector<int> :: iterator it;
 int left,right;
 for(int i=x;;i--)
 {
  it=find(a.begin(),a.end(),i);
  if(it==a.end())
  {
    left=i;
    break;
  }
 }
 for(int i=x;;i++)
 {
  it=find(a.begin(),a.end(),i);
  if(it==a.end())
  {
    right=i;
    break;
  }
 }
 if(abs(x-left)<=abs(x-right))
 {
  cout<<left<<endl;
 }
 else if(abs(x-left)>abs(x-right))
 {
  cout<<right<<endl;
 }
  return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

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

int main(void){
	int D,G,p[11],c[11];
	scanf("%d %d",&D,&G);
	int i;
	for(i=0;i<D;i++){
		scanf("%d %d",&p[i],&c[i]);
	}
	int ans = 1e9;
	for(int mask=0;mask<(1<<D);++mask){	// 1<<Dはより2^D回繰り返すってワケ。
		int s=0,num=0,rest_max=1;//rest_maxは残った問題のうちもっとも得点の高いヤツ。
		
		for(i=0;i<D;++i){		//問題の個数分このループを回す。ここは全て解く問題を選んでいる。
			if(mask>>i & 1){	//論理積をとっている。maskの分だけiをbitずらした場合論理積が1になる。
				s += 100* (i+1) * p[i] + c[i];//sは獲得した点数。
				num += p[i];	//numは解いた問題の数、解いた問題の数を加算している。
			}else{
				rest_max = i;	//iは解いていない中で最も配点の高い問題
			}
		}
		
		if(s<G){//もしも点数が上で足りていない場合以下を実行する。
			int s1 = 100*(rest_max + 1);//s1というのは解いていない中で最も配点が高い問題を解いた時の点数(ボーナスは含めない)
			int need = (G-s+s1-1)/s1;//必要な問題数は点数の残りを最高の問題で割って切り上げた数
			if(need > p[rest_max]){//問題数が足りず届かない場合は
				continue;//次のforループに向かう。
			}
			num += need;
		}
		ans = min(ans,num);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
na,nt = 1,1
for i in range(n):
    a,t = map(int, input().split())
    ra = (na-1)//a + 1        
    rt = (nt-1)//t + 1
    r = max(ra,rt)        
    na = a*r
    nt = t*r
    # print("t:a",t,a,"r",ra,rt,"n",na,nt)

# print(na,nt)
print(na+nt)

Measured memory_bytes: 9040
#include <bits/stdc++.h>
#include <unistd.h>
#include <sys/time.h>
#include <stdlib.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> T;
typedef pair<long double , ll> Ps;
typedef pair<ll, bool> Pb;

const ll INF = 1e18;
const ll fact_table = 3200008;
long double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
priority_queue <P> bag;
//big priority queue
priority_queue <ll, vector<ll>, greater<ll> > pqls;
priority_queue <P, vector<P>, greater<P> > pqps;
//small priority queue
//top pop

ll dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
ll dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
char dir[] = "DRUL";
//↓,→,↑,←

/*
#define endl "\n"
#ifdef ENJAPMA
#undef endl
#endif
*/
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)();
#define pc(x) cout << x << ",";
#define rep(i, n) for (ll i = 0; i < (n); i ++)

const ll mod = 998244353ll;
// const ll mod = 1000000007ll;

ll mypow(ll a, ll b, ll mod) {ll x = 1; while (b) {while (!(b & 1)) {(a *= a) %= mod; b >>= 1;}(x *= a) %= mod; b--;} return x;}
void YES(bool cond) { if (cond) { p("YES");} else { p("NO");} return;}
void Yes(bool cond) { if (cond) { p("Yes");} else { p("No");} return;}
void line() { p("--------------------"); return;}

/*
ll fact[fact_table + 5],rfact[fact_table + 5];

void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = mypow(fact[fact_table],mod - 2, mod);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/

bool multicase = false;

ll n, m, k, num, a, b, c, d, e, h, q, ans, sum;

typedef vector<ll> vec;
typedef vector<vector<ll>> mat;

string s, t;

void solve() {
    cin >> n;
    vec v;
    while (true) {
        if (1 <= n && n <= 26) {
            v.pb(n);
            break;
        } else {
            ll a = n % 26;
            if (a == 0) a = 26;
            v.pb(a);
            n = (n - a) / 26;
        }
    }
    reverse(v.begin(), v.end());
    for (auto e : v) {
        pu((char)('a' - 1 + e));
    }
    el;
    return;
}

int main() {
    // init();
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll q, testcase = 1;
    if (multicase) {
        cin >> q;
    } else {
        q = 1;
    }
    while (q--) {
        // pu("Case ");pu("#");pu(testcase);pu(": ");
        solve();
        testcase++;
    }
    // solve();
    return 0;
}



Measured memory_bytes: 3644
#include <iostream>
#include <string>

#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int ans, N;

int dfs(string s) {
  if (stol(s) > N) return 0;
  
  int ret = 0;

  bool tflag = false, fflag = false, sflag = false;
  REP(i, 0, s.size()) {
    if (s[i] == '3') tflag = true;
    else if (s[i] == '5') fflag = true;
    else sflag = true;
  }
  if (tflag && fflag && sflag) ret++;
  
  ret += dfs(s + '3');
  ret += dfs(s + '5');
  ret += dfs(s + '7');
  
  return ret;
}

int main(void) {
    scanf("%d", &N);

    ans += dfs("3");
    ans += dfs("5");
    ans += dfs("7");
    
    printf("%d\n", ans);

	return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back
const ll mod = 1000000007;

void sayNo() {
	cout << "No" << endl;
}

void sayYes() {
	cout << "Yes" << endl;
}


int main() {
	 int N, K;
	 cin >> N >> K;

	 if (K % 2 == 1) {
		 cout << 0 << endl;
		 return 0;
	 }

	 ll dp[N+1][N+1][K+1];
	 for (int j = 0; j <= N; j++) {
		 for (int k = 0; k <= K; k++) {
			 dp[1][j][k] = 0;
		 }
	 }
	 dp[1][0][0] = 1;
	 dp[1][1][2] = 1;


	 for (int i = 2; i <= N; i++) {
		 for (int j = 0; j <= i; j++) {
			 for (int k = 0; k <= K; k += 2) {
				 dp[i][j][k] = 0;
				 if (k - 2 * j >= 0) {
					 dp[i][j][k] += dp[i - 1][j][k - 2 * j] * (2 * j + 1);
					 dp[i][j][k] %= mod;

					 dp[i][j][k] += dp[i - 1][j + 1][k - 2 * j] * (j + 1) * (j + 1);
					 dp[i][j][k] %= mod;

					 if (j > 0) {
						 dp[i][j][k] += dp[i - 1][j - 1][k - 2 * j];
						 dp[i][j][k] %= mod;
					 }
				 }
				 // cout << "(" << i << ", " << j << ", " << k << ") : " << dp[i][j][k] << endl;
			 }
		 }
	 }

	 cout << dp[N][0][K] << endl;

	 return 0;
}

Measured memory_bytes: 50048
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
typedef long long int ll;
void solve(ll a ,ll b)
{
    ll a1=a,b1=b,t;
    while(b1!=0){//cout<<a1<<" ! "<<b1<<endl;
        t=b1;
        b1=a1%b1;
        a1=t;

    }
    cout<<a1<<" "<<a*b/a1<<endl;
}
int main()
{
    ll a,b;
    while(cin>>a>>b)
    {
        if(a<b)swap(a,b);
        solve(a,b);
    }
    return 0;
}



Measured memory_bytes: 3076
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
#define x first
#define y second
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
using namespace std;

const int INF = 1e9 + 7;

int main() {
	INIT
	int n, p;
	long long ans = 0;
	string s;
	cin >> n >> p >> s;
	if (p == 2 || p == 5) {
		rep (i, 0, n) {
			if ((s[i] - '0') % p == 0) {
				ans += i + 1;
			}
		}
	} else {
		int t = 0, e = 1;
		map<int, int> A;
		A[0] = 1;
		per(i, 0, n) {
			t = (t + (s[i] - '0') * e) % p;
			ans += A[t];
			++A[t];
			e = 10 * e % p;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 916
//#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy 2333333
#define bql 2147483647
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if ((a+b)%2!=0)
	{
		cout<<"IMPOSSIBLE\n";
		return 0;
	}
	else
	   cout<<(a+b)/2<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==b)
        printf("%d",a*2);
    else if(a==b-1 || b==a-1)
        printf("%d",a+b);
    else
    {
 
 
        if(a>b)
        printf("%d",(a*2)-1);
        else
         printf("%d",(b*2)-1);
 
        }
}

Measured memory_bytes: 128
A,B,K=map(int,input().split())

small=[n for n in range(A,min(A+K,B+1))]

large=[n for n in range(max(A+K,B-K+1),B+1)]

ans=small+large
ans.sort()
ans_str=list(map(str,ans))

print(' '.join(ans_str))


Measured memory_bytes: 3060
# D

from collections import deque

N = int(input())
G = dict()
for i in range(N):
    G[i+1] = []
    
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
    
# dist form 1
dist_1 = [N]*(N+1)
dist_1[1] = 0

# BFS
que = deque([1])
while len(que) > 0:
    a = que.popleft()
    for b in G[a]:
        if dist_1[b] > dist_1[a] + 1:
            dist_1[b] = dist_1[a] + 1
            que.append(b)
            
# dist form N
dist_N = [N]*(N+1)
dist_N[N] = 0

# BFS
que = deque([N])
while len(que) > 0:
    a = que.popleft()
    for b in G[a]:
        if dist_N[b] > dist_N[a] + 1:
            dist_N[b] = dist_N[a] + 1
            que.append(b)
            

# count
count_Fennec = 0
for i in range(N):
    if dist_1[i+1] <= dist_N[i+1]:
        count_Fennec += 1

if count_Fennec > N - count_Fennec:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 37920
#include <bits/stdc++.h>
#define pii pair<int,int> 
#define fi first
#define pb push_back
#define si second
#define int long long 
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  mod 1e18
#define double long double
#define all(o) o.begin(),o.end()
using namespace std;

int32_t main()
{
	fast
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a;

	
}


Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
#include<numeric>
#include <unordered_map>

using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, t, a, ans;
	int mina = INT32_MAX;
	int maxp = -1;
	cin >> n >> t;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a < mina) {
			mina = a;
		}
		else if(mina + maxp == a){
			ans++;
		}
		else if (mina + maxp < a) {
			ans = 1;
			maxp = a - mina;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {

var inputs = chunk.toString().trim().split('\n').map(Number);
for (var i = 0; i < inputs .length; i++) {
        if (inputs [i] === 0) {
            break;
        }
        console.log('Case ' + (i + 1) + ': ' + inputs[i]);
}


});

Measured memory_bytes: 20628
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

type Job struct {
	a, b int
}

type Jobs []Job

func (a Jobs) Len() int           { return len(a) }
func (a Jobs) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a Jobs) Less(i, j int) bool { return a[i].a < a[j].a }

type Heap struct {
	size  int
	elems [100000]int
}

type MyHeap interface {
	Size() int
	Push(int)
	Pop() int
}

func (heap *Heap) Size() int {
	return heap.size
}

func (heap *Heap) Push(x int) {
	i := heap.size

	for i > 0 {
		// 親ノードの番号
		p := (i - 1) / 2

		// 逆転していないなら抜ける
		if heap.elems[p] >= x {
			break
		}

		// 親ノードの数字を下ろして、自分は上に
		heap.elems[i] = heap.elems[p]
		i = p
	}

	heap.elems[i] = x
	heap.size++
}

func (heap *Heap) Pop() int {
	// 最小値
	ret := heap.elems[0]
	heap.size--
	// rootに持ってくる値
	x := heap.elems[heap.size]

	// rootから下ろしていく
	i := 0
	for i*2+1 < heap.size {
		// 子同士を比較
		a, b := i*2+1, i*2+2
		if b < heap.size && heap.elems[b] > heap.elems[a] {
			a = b
		}
		if heap.elems[a] <= x {
			break
		}

		// 子の数字を持ち上げる
		heap.elems[i] = heap.elems[a]
		i = a
	}

	heap.elems[i] = x

	return ret
}

func (heap *Heap) Top() int {
	return heap.elems[0]
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	jobs := make(Jobs, n)
	for i := 0; i < n; i++ {
		a, b := nextInt(), nextInt()
		jobs[i] = Job{a, b}
	}
	sort.Sort(jobs)

	ans := 0
	pq := new(Heap)
	for day, id := m-1, 0; day >= 0; day-- {
		for id < n && day+jobs[id].a <= m {
			pq.Push(jobs[id].b)
			id++
		}
		if pq.size > 0 {
			ans += pq.Pop()
		}
	}

	puts(ans)
}


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

int main() {
    ll N, X; cin >> N >> X;
    vector<ll> L;
    for(int i = 0; i < N; i++){
        ll tmp; cin >> tmp;
        L.push_back(tmp);
    } 

    ll ans = 1;
    ll cur = 0;
    for(auto i:L){
        cur += i;
        if(cur > X) break;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cfloat>
#include<algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	float* p = new float[n];
	float* q = new float[n + 1];
	float sum, mini;
	for (int i = 0;i < n;i++) {
		cin >> p[i];
	}
	for (int i = 0;i <= n;i++) {
		cin >> q[i];
	}
	float** cost = new float* [n];
	float** coefficient = new float* [n];
	for (int i = 0;i < n;i++) {
		cost[i] = new float[n - i];
		coefficient[i] = new float[n - i];
	}
	for (int i = 0;i < n ;i++) {
		for (int j = 0;j < n - i;j++) {
			sum = 0;
			for (int k = i;k <= i + j;k++) {
				sum += p[k] + q[k];
			}
			sum += q[i + j + 1];
			coefficient[i][j] = sum;
		}
		cost[i][0] = p[i]+2*q[i]+2*q[i+1];
	}
	for (int j = 1;j <n;j++) {
		for (int i = 0;i < n - j;i++) {
			mini = p[i] + cost[i + 1][j - 1] + coefficient[i + 1][j - 1]+2*q[i];
			for (int k = 1;k < j;k++) {
				mini = min(mini, p[i + k] + cost[i][k - 1] + coefficient[i][k - 1] + cost[i + k + 1][j - k - 1] + coefficient[i + k + 1][j - k - 1]);
			}
			cost[i][j] = min(mini, p[i + j] + cost[i][j - 1] + coefficient[i][j - 1] + 2 * q[i + j + 1]);
		}
	}
	cout << cost[0][n-1] << endl;
}


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

typedef long long int ll;
void solved(){
	ll x;cin>>x;
	ll ans = 0;
	while(x >= 500){
		ans += 1000;
		x-=500;
	}
	while(x >= 5){
		ans += 5;
		x-=5;
	}
	cout<<ans<<endl;	
}
int main(){
	solved();
	return 0;
} 

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;

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

  ll N,M; cin >> N >> M;
  vector<ll> x(N); vector<ll> y(M);
  
  for(ll i = 0; i < N; i++){ cin >> x[i];}
  for(ll j = 0; j < M; j++){ cin >> y[j];}
  
  ll ansx = 0LL; ll ansy = 0LL;
  
  for(ll i = 0; i < N; i++){ ansx += (-N+2*i+1)*x[i]; ansx %= MOD;}
  for(ll j = 0; j < M; j++){ ansy += (-M+2*j+1)*y[j]; ansy %= MOD;}
  
  ll ans = (ansx*ansy) % MOD;
  cout << ans << endl; return 0;}
   
  
  


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0, i_l = (int)n; i < i_l; i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)
 
int main() {
    int x;
    cin >> x;
    string s = (x < 1200) ? "ABC" : "ARC";
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
*A, = map(int, input().split())
A.sort()
p = 10**9+7
F, I = [1], [1]
for i in range(1, n+1):
    F.append((F[-1]*i) % p)
    I.append((I[-1]*pow(i, p-2, p)) % p)
s = 0
for i in range(k-1, n):
    s += (A[i]-A[n-(i+1)])*F[i]*I[k-1]*I[i-(k-1)]
    s %= p
print(s)

Measured memory_bytes: 15948
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define ceil(n, m) ((n / m) + ( n % m ? 1 : 0))
#define fast_IO  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file_in freopen("input.txt","r",stdin);
#define file_out freopen("output.txt","w",stdout);
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);

int main(){
    //fast_IO;

    int n,l;
    cin >> n >> l;
    vector<string>v(n);
    for(auto &i:v) cin >> i;
    sort(all(v));
    for(auto &i:v) cout<<i;

    return 0;
}


Measured memory_bytes: 3648
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    if(s==t){
        cout<<"Yes"<<endl;
        return 0;
    }
    string tmp=s;
    while(1){
        tmp=tmp.substr(tmp.length()-1,tmp.length())+tmp.substr(0,tmp.length()-1);
        if(tmp==t){
            cout<<"Yes"<<endl;
            return 0;
        }
        if(s==tmp){
            cout<<"No"<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int[] IntSides = new int[4];
            for (int i = 0; i < 4; i++)
            {
                IntSides[i] = int.Parse(input[i]);
            }
            if (IntSides[0]* IntSides[1]>= IntSides[2] * IntSides[3])
            {
                Console.WriteLine(IntSides[0] * IntSides[1]);
            }
            else
            {
                Console.WriteLine(IntSides[2] * IntSides[3]);
            }

        }  
    }
}

Measured memory_bytes: 11092
#include<stdio.h>

int main(void)
{
	int i,n,k,q,s;
	
	scanf("%d%d%d",&n,&k,&q);
	
	int a[n+1];
	
	for(i=1;i<=n;i++)
		a[i]=k-q;
	
	for(i=0;i<q;i++){
		scanf("%d",&s);
		a[s]++;
		}
	
	for(i=1;i<=n;i++){
		if(a[i]>0)
			printf("Yes\n");
		else
			printf("No\n");
	}
	return 0;
}
	

Measured memory_bytes: 896
/*****TEMPLATE*****/
      

#include <algorithm>
#include <array>
#include <bitset>
#include <cctype> 
#include <chrono>
#include <climits>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cstring>
#include <cstdio>
#include <stdio.h>
//INCLUDES
using namespace std;

#define lld long long int
#define ulld unsigned long long int
#define mod 1000000007
#define pb push_back
#define umap unordered_map
#define mp make_pair
#define fi first
#define se second 
#define rep(n) for(int i=0;i<n;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//DEFINES

lld gcd(lld a,lld b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){lld r=a%b; a=b; b=r;} return a;}
lld bs(lld arr[], lld l, lld r, lld x) { if (r >= l) {  lld mid = l + (r - l) / 2;  if (arr[mid] == x)  return mid; if (arr[mid] > x)  return bs(arr, l, mid - 1, x);  return bs(arr, mid + 1, r, x);  }  return -1; }
lld mypower(lld x, lld n){	if (n == 0)	return 1;	if (n & 1) 	return (((x * mypower(x, n / 2))%mod) * (mypower(x, n / 2)%mod)%mod);return (((mypower(x, n / 2))%mod) * (mypower(x, n / 2)%mod))%mod;}
lld modinv(lld a) { lld g = gcd(a, mod); if (g != 1) return -1;else{  return mypower(a, mod-2)%mod; } } 

lld dp[1000001]={};
lld vis[1000001]={};

void dfs(vector <vector <lld>> &adj,lld src)
{
    vis[src]=1;
    for (int i = 0; i < adj[src].size(); i++) {
        if(!vis[adj[src][i]])
        {
            dfs(adj,adj[src][i]);
            vis[adj[src][i]]=1;
            dp[src]=max(dp[adj[src][i]]+1,dp[src]);
        }
        else
        {
            dp[src]=max(dp[adj[src][i]]+1,dp[src]);
        }
    }
}

//FUNCTIONS
void solve()
{
    lld n,m;
    cin>>n>>m;
    vector <vector <lld>> adj(n+1);
    umap <lld,lld> mp;
    for (int i = 0; i < m; i++) {
        lld x,y;
        cin>>x>>y;
        adj[x].pb(y);
        mp[y]=1;
    }
    lld src=1;
    lld ans=-1;
    
    while(src<=n)
    {
        if(mp[src]==0)
        {
            
            vis[src]=1;
            
            dfs(adj,src);
            ans=max(dp[src],ans);
            
        }
        src++;
    }
    
    cout<<ans<<"\n";
    
    
    return;
}
int main() 
{
    fast
    solve();
    return 0;
}



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

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

    static class Task
    {
        public void solve(int testNumber, Scanner in, PrintWriter out)
        {
            int T = 1;
            while (T-- > 0)
            {
                solveOne(in, out);
            }
        }

        private void solveOne(Scanner in, PrintWriter out)
        {
            int N = in.nextInt();
            int M[][] = CPUtils.readIntMatrix(N, 2, in);

            for (int i = 0; i < N - 2; i++)
            {
                if (M[i][0] == M[i][1] && M[i + 1][0] == M[i + 1][1] && M[i + 2][0] == M[i + 2][1])
                {
                    out.println("Yes");
                    return;
                }
            }
            out.println("No");
        }

    }

    static class CPUtils
    {
        public static int[] readIntArray(int size, Scanner in)
        {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
            {
                array[i] = in.nextInt();
            }
            return array;
        }

        public static int[][] readIntMatrix(int rows, int columns, Scanner in)
        {
            int[][] matrix = new int[rows][columns];
            for (int i = 0; i < rows; i++)
            {
                matrix[i] = CPUtils.readIntArray(columns, in);
            }
            return matrix;
        }

    }
}



Measured memory_bytes: 27288
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, a[MAXX], b[MAXX], c[MAXX];
vector<ll> adj[MAXX];
vector<pair<int, int> > v;
bool used[MAXX];
multiset<int> ms;

signed main()
{
	FAST;
	ll   r;
	ll m;
	cin >> n >> m;
	for(ll i = 0; i < n; i++){
		cin >> a[i];
		ms.insert(a[i]);
	}
	for(ll i = 0; i < m; i++){
		cin >> b[i] >> c[i];
		v.push_back({c[i] , b[i]});
	}
	sort(v.begin() , v.end());
	reverse(v.begin() , v.end());
	ll ans = 0;
	for(ll i = 0; i < v.size(); i++){
		ll x = v[i].first, y = v[i].second;
		while(*(ms.begin()) < x && y){
		ms.erase(ms.begin());
		ms.insert(x);
		y --;
	}
	}
	
	while(n){
		ans += *(ms.begin());
		ms.erase(ms.begin());
		n--;
	}
		
	cout << ans;
}

Measured memory_bytes: 10876
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;


int main(void){
	int m1, d1; cin >> m1 >> d1;
	int m2, d2; cin >> m2 >> d2;
	if(m2 == m1+1 && d2 == 1) cout << 1 << endl;
	else cout << 0 << endl;
	return 0;
}

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

using namespace std;

signed main()
{
    long long i = 0, j = 0, k = 0, ans = 0;
    long long n, s[200];
    cin >> n;
    for (i=0; i < n;i++)
        cin >> s[i];

    sort(s, s + n);
    for (i = n-1; i >=0;i--){
        ans += s[i];
    }
    if (ans % 10 != 0){
        cout << ans << endl;
        return 0;
    }

    for (i = 0; i < n - 1; i++) {
        ans -= s[i];
        if (ans % 10 != 0){
             cout << ans << endl;
             return 0;
        }
        else
            ans += s[i];
    }

    cout << 0 << endl;

    return 0;
}  


Measured memory_bytes: 256