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

#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

using namespace std;

//------------------------------------------------------------------------------
ll power(ll a,ll n)
{
          ll result=1;
          while(n>0)
          {
               if(n&1)
                    result=result*a;
               a=a*a;
               n=n>>1;
          }
          return result;
}
ll lcm(ll a,ll b)
{
          return ((a*b)/__gcd(a,b));
}
bool ispow2(ll n)
{
          return (ceil(log2(n))==floor(log2(n)));
}
bool isprime(ll n)
{
          if(n==1)
               return false;
          else if(n==2)
               return true;
          else
          {
               for(ll i=2;i*i<=n;++i)
               {
                    if(n%i==0)
                         return false;
               }
               return true;
          }
}

ll ncr(ll n,ll r)
{
    if(r > n - r)
          r = n - r;
    ll ans = 1;
    ll i;

    for(i = 1; i <= r; i++)
     {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
void sieve(int n)
{
    // Create a boolean array "prime[0..n]" and initialize
    // all entries it as true. A value in prime[i] will
    // finally be false if i is Not a prime, else true.
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
     prime[1]=false;
     prime[0]=false;
    for (int p=2; p*p<=n; p++)
    {
        // If prime[p] is not changed, then it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p greater than or
            // equal to the square of it
            // numbers which are multiple of p and are
            // less than p^2 are already been marked.
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }

    // Print all prime numbers
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout<<p<<" ";
}
//------------------------------------------------------------------------------


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

          int t=1;
          //cin>>t;
          while(t--)
          {
                    string s;
                    cin>>s;
                    cout<<s;
                    if(s[s.size()-1]=='s')
                         cout<<"es";
                    else
                         cout<<"s";
          }
          return 0;
}


Measured memory_bytes: 3512
#pragma GCC optimize "03"
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int n, a[N];
int dp[N];

bool rec(int k){
	if(dp[k] != -1)	
		return dp[k];
	if(k == 0)
		return 0;
	for(int i = 1; i <= n; i++){
		if(a[i] <= k && !rec(k - a[i]))
			return (dp[k] = 1);
	}
	return (dp[k] = 0);
}
 
signed main() {
	IOS;
	#ifdef LOCAL
		freopen("input.txt","r", stdin);
		freopen("output.txt","w",stdout);
	#endif
	int k;
	cin >> n >> k;
	for(int i = 1; i < N; i++)
		dp[i] = -1;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	if(rec(k))
		cout << "First";
	else
		cout << "Second";
	return 0;
}

Measured memory_bytes: 3456
#include<cstdio>
#include<iostream>
#include<ctype.h>
#include<string>
using namespace std;
int main(){
	string S;
	cin >> S;
	bool good = true;
	for(int i = 0; i <= 2; i++){
		if(S[i] == S[i + 1]){
			good = false;
			break;
		}
	}
	if(good){
		cout << "Good" << endl;
	}
	else{
		cout << "Bad" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------


int main(int argc,char** argv){ fastio; myio;
  int n;
  cin>>n;
  vi c(n-1),s(n-1),f(n-1);
  rep(i,n-1){ 
    cin>>c[i]>>s[i]>>f[i];
  }
  rep(i,n){
    int x=0;
    int now=i;
    while(now<n-1){
      x = c[now] + (x>=s[now]? dup(x,f[now])*f[now]:s[now]);
      now++;
    }
    cout<<x<<endl;
  }
}

Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(_,v.size())cout<<" "<<v[_];cout<<endl;
#define show2d(v) rep(_,v.size()){rep(__,v[_].size())cout<<" "<<v[_][__];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
// typedef tuple<int,int,int> tp;
// typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 1e18+10 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};//RDLU
signed main(){
	int n;
	cin>>n;
	rep(i,10000)if(i*(i+1)==n*2){
		int t=i;
		cout<<"Yes"<<endl;
		cout<<t+1<<endl;
		vvi in(t+1);
		int w=0;
		rep(j,t+1)rep(k,j){
			in[j].pb(w);
			in[k].pb(w);
			w++;
		}
		rep(i,t+1){
			cout<<t;
			rep(j,t)cout<<" "<<in[i][j]+1;cout<<endl;
		}
		return 0;
	}
	cout<<"No"<<endl;
}








Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define REP(i, init, n) for(int i = (int)(init); i < (int)(n); i++)

int main() {
    int N;
    cin>>N;
    int h_cur = 0;
    int count = 0;
    int countMax = 0;
    REP(i, 0, N){
        int h;
        cin >> h;
        if(h_cur >= h){
            count++;
            countMax = max(countMax, count);
        }else{
            count = 0;
        }
        h_cur = h;
    }
    cout << countMax << endl;
}

Measured memory_bytes: 256
/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws IOException
	{
		// your code goes here
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		long b = scan.nextLong();
		long c = scan.nextLong();
		long d = scan.nextLong();
		long m1 = a * c;
		long m2 = a * d;
		m1 = Math.max(m1, m2);
	    m2 = b * c;
		long m3 = b * d;
		m2 = Math.max(m2, m3);
		System.out.println(Math.max(m2, m1));
	}
}


Measured memory_bytes: 35608
program ccc

implicit none
integer :: n, i, j
integer(8) :: co, res1 = 0, res2 = 0
integer,dimension(26) :: alp = [2,3,5,7,11,13,17,19,&
&23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101]
integer(8),allocatable,dimension(:) :: bet
character(10),allocatable,dimension(:) :: s

read*, n
allocate(s(n))
allocate(bet(n))
bet = 1

read*, s

do i=1, n
 do j=1,10
 bet(i)=bet(i)*(alp(ichar(s(i)(j:j))-96))
 end do
end do

call heapsort(n,bet)

co=bet(1)
do i=2,n
 if(co==bet(i)) then
 res1=res1+1
 else
 co=bet(i)
 res2=res2+res1*(res1+1)/2
 res1=0
 end if
end do

res2=res2+res1*(res1+1)/2

write(*,'(i0)') res2

end program


subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer(8),intent(inout) :: array(1:n)
 
  integer ::i,k,j,l
  integer(8) :: t
 
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort

Measured memory_bytes: 2560
#include<cstdio>
int N, C;
int s[100000], t[100000], c[100000];
int sm[200002];
int tt[200002];
int main(){
    scanf("%d %d", &N, &C);
    for (int i = 0; i < N ; i++){
        scanf("%d %d %d", &s[i], &t[i], &c[i]);
    }
    for (int i = 1; i <= C; i++){
    for (int j = 0; j < 200002; j++) tt[j] = 0;
    for (int j = 0; j < N ; j++) if (c[j] == i) tt[s[j] * 2 - 1]++ , tt[t[j] * 2]--;
    for (int j = 1; j < 200002; j++) tt[j] += tt[j - 1];
    for (int j = 0; j < 200002; j++) if (tt[j] > 0) sm[j]++;
    }
    int mx = 0;
    for (int j = 0; j < 200002; j++) if (mx < sm[j]) mx = sm[j];
    printf("%d\n", mx);
}

Measured memory_bytes: 3072
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true){
            int H = scanner.nextInt();
            int W = scanner.nextInt();
            if(H == 0 && W == 0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    if(i==0 || j == 0 || i==H-1 || j == W-1){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
        }
        scanner.close();
    }
}


Measured memory_bytes: 37164
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static string s;

        static void Main(string[] args)
        {
            //[summary]C - Coloring Colorfully
            s = Console.ReadLine();
            //var tiles = GetFinishedTiles();
            int changed = 0;

            for(int i = 0; i < s.Length; i++)
            {
                if (i % 2 == 0)
                {
                    if (s[i] == '1')
                    {
                        changed++;
                    }
                }
                else
                {
                    if (s[i] == '0')
                    {
                        changed++;
                    }
                }
            }

            int remainder = s.Length - changed;

            if (remainder > changed)
            {
                Console.WriteLine(changed);
            }
            else
            {
                Console.WriteLine(remainder);
            }            
        }

        static string GetFinishedTiles()
        {
            string tiles = "";

            for(int i = 0; i < s.Length; i++)
            {
                if (i % 2 == 0)
                {
                    tiles += "0";
                }
                else
                {
                    tiles += "1";
                }
            }

            return tiles;
        }
    }
}

Measured memory_bytes: 11604
#include<bits/stdc++.h>
using namespace std;
int n,m,k;
int main(){
	cin>>n>>m>>k;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=m;j++)
			if(i*m+j*n-i*j*2==k)
				{cout<<"Yes"<<endl;return 0;}
	cout<<"No"<<endl;			
}

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

int main() {
  IN(int, N);
  vector<int> L(N);
  int count = 0;
  REP(i, N) {
    cin >> L.at(i);
  }
  for (int i = 0; i < N - 2; ++i) {
    for (int j = i + 1; j < N - 1; ++j) {
      for (int k = j + 1; k < N; ++k) {
        int li = L.at(i), lj = L.at(j), lk = L.at(k);
        if (li == lj || lj == lk || lk == li) continue;
        if (li >= lj + lk) continue;
        if (lj >= li + lk) continue;
        if (lk >= li + lj) continue;
        count++;
      }
    }
  }
  cout << count << endl;

  return 0;
}


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

using namespace std;

int main() {
    vector<bool> map(1000000100, false);
    int n; cin >> n;
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        unsigned long a; cin >> a;
        if (map[a]) --cnt;
        else        ++cnt;
        map[a] = !map[a];
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 122368
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  cout<<max(0,a-2*b)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int[] H = new int[N];
        
        for (int i = 0; i < N; i++) {
            
            H[i] = sc.nextInt();
        }
        
        int max = H[0];
        int canSee = 1;

        for (int i = 1; i < N; i++) {

            if (H[i] >= max) {

                canSee++;
                max = H[i];
            }
        }
        
        System.out.println(canSee);
        
        sc.close();
    }

}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner sc  = new Scanner(System.in);

        double r = sc.nextDouble();
        double pi = Math.PI;
        double area = pi * r * r;
        double length =  2 * pi * r;
        System.out.printf("%f %f", area, length);
        sc.close();
        }
}


Measured memory_bytes: 28228
"use strict"

function Main(input) {
  input = input.split(' ');
  let A = parseInt(input.shift());
  let B = parseInt(input.shift());
  let T = parseInt(input.shift());
  console.log(Math.floor(T/A) * B)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import io

nim = int(input())
 
mike = list(map(int,input().split()))
 
counter = 0

for i in range(nim):
    t = mike[i:i+3]
    if len(t) == 3:
        if max(t) > t[1] and min(t) < t[1]:
            counter += 1
            
            
print(counter)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
using namespace std;
int main() {
    string n;
    cin >> n;
    int res = 0;
    for (int i = 0; i < n.length(); i++) {
        res += (int)(n[i] - '0');
    }
    cout << ((res % 9 == 0) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3736
import collections
import numpy as np

n = int(input())
l = input().split()
v = [ int(s) for s in l ]

#n = 4
npv = np.array( v, dtype=np.int32)
#npv = np.array( [3,1,3,2], dtype=np.int32)
npv_dic = {}
npv_dic['even'] = npv[0::2]
npv_dic['odd']  = npv[1::2]

#print('n = ', n)
#print('npv = ', npv)
#print('npv_dic[\'even\'] = ', npv_dic['even'])
#print('npv_dic[\'odd\']  = ', npv_dic['odd'])

dict0 = collections.Counter(npv_dic['even'])
dict1 = collections.Counter(npv_dic['odd'])

list0 = list(dict0.items())
list1 = list(dict1.items())

list0.sort(key= lambda x:x[1], reverse=True)
list1.sort(key= lambda x:x[1], reverse=True)

#print(list0[0] ,list1[0])
#print(list0[1] ,list1[1])

if list0[0][0] == list1[0][0]:
    if (list0[0][1] == list1[0][1]) and \
        (list0.__len__() > 1) and (list0.__len__() > 1):
        if list0[1][1] > list1[1][1]:
            del list0[0]
        else:
            del list1[0]
    elif list0[0][1] > list1[0][1]:
        del list1[0]
    else:
        del list0[0]
#print(list0[0] ,list1[0])
#print(list0[1] ,list1[1])

if list0.__len__() != 0:
    change0 = n//2 - list0[0][1]
else:
    change0 = n//2
change1 = n//2 - list1[0][1]
#print('change:', change0, change1)

print(change0 + change1)


Measured memory_bytes: 39764
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while(n-- > 0){
        string s1, s2;
        cin >> s1 >> s2;
        int i = s1.size() - 1;
        int j = s2.size() - 1;
        if(i >= 80 || j >= 80){
            cout << "overflow" << endl;
            continue;
        }

        int k = max(i, j) + 1;
        string s3(k+1, '0');
        while(k >= 0){
            int a = s3[k] - '0';
            if(i >= 0)
                a += s1[i] - '0';
            if(j >= 0)
                a += s2[j] - '0';
            if(a > 9){
                ++ s3[k-1];
                a -= 10;
            }
            s3[k] = a + '0';

            -- i;
            -- j;
            -- k;
        }

        if(s3[0] == '0')
            cout << s3.substr(1) << endl;
        else if(s3.size() > 80)
            cout << "overflow" << endl;
        else
            cout << s3 << endl;
    }
}

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

int main() {
  string S, T, T_, ans;
  int len;
  cin >> S >> T;
  
  ans = "No";
  len = S.size();
  for(int i=0; i<len; i++) {
    T_ = T.substr(i, len-i) + T.substr(0, i);
    if(S == T_) {
      ans = "Yes";
      break;
    }
  }
  
  cout << ans << endl;
  return 0;
}

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

typedef struct process {
	string name;
	int time;
}P;

void enqueue(vector<P>& total, int& tail, P& t, int N);
P dequeue(vector<P>& total, int& head, int N);


int main(void) {

	int N, Q;
	cin >> N >> Q;

	vector<P> total(N + 1);
	for (int i = 0; i < N; i++)
	{
		cin >> total.at(i).name >> total.at(i).time;
	}

	int head = 0;
	int tail = N;

	int totaltime = 0;
	while (head != tail) {
		P t = dequeue(total, head, (N+1));
		if (t.time <= Q)
		{
			totaltime += t.time;
			cout << t.name << " " << totaltime << endl;
		}
		else if (t.time > Q) {
			t.time -= Q;
			enqueue(total, tail, t, (N+1));
			totaltime += Q;
		}
	}

	return 0;
}

void enqueue(vector<P>& total, int& tail, P& t, int N) {
	total.at(tail) = t;
	tail = (tail + 1) % N;
	return ;
}

P dequeue(vector<P>& total, int& head, int N) {
	P deq = total.at(head);
	head = (head + 1) % N;
	return deq;
}


Measured memory_bytes: 6044
#include<stdio.h>

int selectionSort(int A[],int N){
  int i, j, t, sw=0, minj;
  for(i=0;i<N-1;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj])minj=j;
    }t=A[i];
    A[i]=A[minj];
    A[minj]=t;
    if(i != minj)sw++;
  }
  return sw;
}

int main(){

  int A[100];
  int N,i,sw;

  scanf("%d",&N);
  for(i=0;i<N;i++)scanf("%d",&A[i]);

  sw=selectionSort(A,N);

  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",sw);

  return 0;
}



Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
signed main(){
    int n,k; cin >> n >> k;
    vector<int>v(n);
    for(auto & e : v) cin >> e;
    auto dp = vectors(n,n,k,-INF);
    if(k == 1 or n == 1){
        cout << max({v.front(),v.back(),0LL}) << endl;
        return 0;
    }
    dp[1][n - 1][k -  1] = v.front();
    dp[0][n - 2][k -  1] = v.back();
    if(v.front() < 0 and k >= 2){
        dp[1][n - 1][k - 2] = 0LL;
    } else if(v.back() < 0 and k >= 2){
        dp[0][n - 2][k - 2] = 0LL;
    }
    auto valid = [&](int l,int r){ return (l <= r and 0 <= l and  r <= n-1);};
    for(int l = 0; l < n; ++l){
        for(int r = n - 1; r >= 0; --r){
            for(int cst = 1; cst < k; ++cst){
                if( dp[l][r][cst] == -INF) continue;
                int now = dp[l][r][cst];
                if( valid(l + 1,r) )
                    cmax(dp[l + 1][r][cst - 1],now + v[l]);
                if( valid(l,r - 1) )
                    cmax(dp[l][r - 1][cst - 1],now + v[r]);
                if(v[l] < 0 and  valid(l + 1,r) and cst >= 2)
                    cmax(dp[l + 1][r][cst - 2],now);
                if(v[r] < 0 and valid(l,r - 1) and cst >=2)
                    cmax(dp[l][r - 1][cst - 2],now);
            }
        }
    }
    int ans = 0;
    for(int l = 0; l < n; ++l){
        for(int r = 0; r < n; ++r){
            for(int cst = 0; cst < k; ++cst){
                cmax(ans,dp[l][r][cst]);
                if(l == r){
                    cmax(ans,dp[l][r][cst] + (cst != 0 and v[l] > 0 ? v[l] : 0));
                }
            }
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 2304
import java.util.*;

 class Main
 {
   public static void main(String args[])
   { 
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    
    for(int i = 1; i <= n; i ++)
    {
      if(i % 3 == 0)
      {
        System.out.printf(" %d",i);
      }
      else 
      {
        int x = i;
        
        do
        {
          if(x % 10 == 3)
          {
            System.out.printf(" %d",i);
            
            break;
          }
          x /= 10;
        }while (x != 0);
      }
    }
    System.out.println();
   }
 }
    


Measured memory_bytes: 38264
#include<bits/stdc++.h>
using namespace std;
const int INF=1e8;


struct edge{ int to,cap,rev; };
vector<edge> G[1000];
bool used[1000];

void add_edge(int from,int to,int cap){
  G[from].push_back((edge){to,cap,(int)G[to].size()});
  G[to].push_back((edge){from,0,(int)G[from].size()-1});
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to]&&e.cap>0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
        e.cap-=d;
        G[e.to][e.rev].cap+=d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s,int t){
  int flow=0;
  while(1){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)break;
    flow+=f;
  }
  return flow;
}




int main(){
  int N,M,si,ti;
  int G[200][200];
  int cost[200][200];
  int g[200][200];
  cin>>N>>M>>si>>ti;
  si--;
  ti--;

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      G[i][j]=(i==j?0:INF);
      g[i][j]=-1;
    }
  }
  
  for(int i=0;i<M;i++){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a--,b--;
    
    G[a][b]=c;
    cost[a][b]=c;
    g[a][b]=d;
  }
  
  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)
        G[i][j]=min(G[i][j],G[i][k]+G[k][j]);

  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
      if(g[i][j]==-1)continue;
      if( G[si][i]+cost[i][j]+G[j][ti] != G[si][ti] )continue;
      add_edge(i,j,g[i][j]);
    }
  }

  cout<< max_flow(si,ti) <<endl;
  return 0;
}



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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    long long n, l;
    cin >> n >> l;

    long long tgt = l * n + n * (n - 1) / 2;
    long long best = 10000000000;
    long long out = -1;

    for(int i = 1; i <= n; ++i){
        long long tot = tgt - (l + i - 1);
        if(abs(tgt - tot) < best){
            best = abs(tgt - tot);
            out = tot;
        }
    }
    cout << out;

    return 0;
}


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

def dfs(s):
    if int(s) > N:
        return 0
    if s.count("7") > 0 and s.count("5") > 0 and s.count("3") > 0:
        ret = 1
    else:
        ret = 0
    for c in "753":
        ret += dfs(s + c)
    return ret

print(dfs("0"))    

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define io ios_base::sync_with_stdio(0);cin.tie(0);
#define mod 1000000009
#define pi 2*acos(0)
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
using namespace std;


int main()
{

	io;
	
	ll a, b, c, d;
	cin >> a >> b >> c >> d;

	ll p1, p2, p3, p4;
	p1 = a * c; p2 = a * d; p3 = b * c; p4 = b * d;
	cout << max(p1, max(p2, max(p3, p4)));
}



Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;cin>>n;
	vector<int> a(n),w(1 << n,0);REP(i,n)cin>>a[i];
	int q;cin>>q;
	REP(bit,1 << n){
		REP(i,n){
			if(bit & (1 << i)){
				w[bit] += a[i];
			}
		}
	}
	REP(i,q){
		int m;cin>>m;
		bool found = false;
		REP(bit,1<<n){
			if(w[bit]==m){found = true;break;}
		}
		if(found)cout << "yes" << endl;
		else cout << "no" << endl;
	}
  return 0;
}

Measured memory_bytes: 6912
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,a[2001];
    cin>>n;
    int i,j,k,z=0;
    for(i=1; i<=n; i++)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(i=1; i<=n-2; i++)
        for(j=i+1; j<=n-1; j++)
            for(k=j+1; k<=n; k++)
                if(a[i]+a[j]>a[k])
                    z++;
    cout<<z<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAXN 300000
using namespace std;
int w,h,n;
struct point
{
	int x,y;
}p[MAXN+5];
bool operator < (const point &a,const point &b)
{
	return a.x<b.x;
}
struct node
{
	int l,r;
	int w,tag;
}tree[4*MAXN];
void PushUp(int i)
{
	if(tree[i].l==tree[i].r)
		return;
	tree[i].w=max(tree[i*2].w,tree[i*2+1].w);
}
void PushDown(int i)
{
	if(tree[i].l==tree[i].r)
		return;
	if(tree[i].tag)
	{
		tree[i*2].w+=tree[i].tag,tree[i*2].tag+=tree[i].tag;
		tree[i*2+1].w+=tree[i].tag,tree[i*2+1].tag+=tree[i].tag;
		tree[i].tag=0;
	}
}
void Build(int i,int l,int r)
{
	tree[i].l=l;
	tree[i].r=r;
	tree[i].w=0;
	tree[i].tag=0;
	if(l==r)
		return;
	int mid=(l+r)/2;
	Build(i*2,l,mid);
	Build(i*2+1,mid+1,r);
}
void modify(int i,int l,int r,int val)
{
	if(r<tree[i].l||tree[i].r<l)
		return;
	if(l<=tree[i].l&&tree[i].r<=r)
	{
		tree[i].w+=val;
		tree[i].tag+=val;
		return;
	}
	PushDown(i);
	modify(i*2,l,r,val);
	modify(i*2+1,l,r,val);
	PushUp(i);
}
int ans=0;
int top[2],st[2][MAXN+5];
void solve()
{
	int i;
	sort(p+2,p+1+n);
	top[0]=top[1]=0;
	st[0][0]=st[1][0]=1;
	Build(1,1,n);
	modify(1,1,n,h<<1);
	for(i=2;i<=n;i++)
	{
		modify(1,1,i-1,(p[i].x-p[i-1].x)<<1);
		ans=max(ans,tree[1].w);
		if(p[i].y>=(h>>1))
		{
			modify(1,st[0][top[0]],i-1,(p[i].y-h)<<1);
			while(top[0]&&p[st[0][top[0]]].y>=p[i].y)
			{
				modify(1,st[0][top[0]-1],st[0][top[0]]-1,(p[i].y-p[st[0][top[0]]].y)<<1);
				top[0]--;
			}
			st[0][++top[0]]=i;
		}
		else
		{
			modify(1,st[1][top[1]],i-1,-p[i].y<<1);
			while(top[1]&&p[st[1][top[1]]].y<=p[i].y)
			{
				modify(1,st[1][top[1]-1],st[1][top[1]]-1,(p[st[1][top[1]]].y-p[i].y)<<1);
				top[1]--;
			}
			st[1][++top[1]]=i;
		}
	}
	memset(tree,0,sizeof(tree));
}
int main()
{
	scanf("%d %d %d",&w,&h,&n);
	n++;
	int i;
	for(i=2;i<=n;i++)
		scanf("%d %d",&p[i].x,&p[i].y);
	p[++n]=(point){w,h};
	solve();
	swap(w,h);
	for(int i=1;i<=n;i++)
		swap(p[i].x,p[i].y);
	solve();
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 22144
import sys,collections,math,random;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

r,D,x = Is()
for i in range(10):
    n = r*x - D
    print(n)
    x = n

Measured memory_bytes: 4584
'use strict';

function main(arg) {
    arg = arg.split("\n");
    arg = arg[0];
    
    const indexA = arg.indexOf("A");
    const indexC = arg.indexOf("C");
    
    if(arg.split("").filter(n=>isLowerCase(n)).length !== arg.length - 2 ) {
        console.log("WA");
        return;
    }
    
    if(indexA === 0 && indexC >= 2 && indexC <= arg.length - 2) {
        console.log("AC");
    } else {
        console.log("WA");
    }
}

function isLowerCase(str){
    return str.match(/^[a-z]+$/) ? true: false;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
N, K = map(int, input().split())
X    = list(map(int, input().split()))

X_pos = [x for x in X if x >= 0]
X_neg = [x for x in X if x <  0]

X_neg.reverse()

l_pos = len(X_pos)
l_neg = len(X_neg)

R = []

if l_neg == 0:
    R.append(X_pos[K-1])
elif l_pos == 0:
    R.append(-1 * X_neg[K-1])
else:
    for k in range(K):
        if k < l_pos and K-k-2 < l_neg:
            R.append(2 * X_pos[k] - X_neg[K-k-2])
        elif k >= l_pos:
            break
    for k in range(K):
        if k < l_neg and K-k-2 < l_pos:
            R.append(-2 * X_neg[k] + X_pos[K-k-2])
        elif k >= l_neg:
            break

print(min(R))

Measured memory_bytes: 14564
import java.util.Scanner;

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

        for (int i = n; i < 1000; i++) {
            int tmp = i;
            int a = tmp % 10;
            tmp /= 10;
            int b = tmp % 10;
            tmp /= 10;
            int c = tmp % 10;

            if (a == b && b == c) {
                System.out.println(i);
                return;
            }
        }
    }
}

Measured memory_bytes: 23124
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		String t = scan.next();
		
		char[] list1 = s.toCharArray();
		Arrays.sort(list1);
		s = String.valueOf(list1);
		
		char[] list2 = t.toCharArray();
		Arrays.sort(list2);
		t = String.valueOf(list2);
		
		t = new StringBuilder(t).reverse().toString();

		if (s.compareTo(t) < 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <queue>
#include <stdio.h>
using namespace std;
int f=0;
int seedis(int x,int *arr,long long *dis)
{
    if(arr[x]==0) return 0;
    else return seedis(arr[x],arr,dis) + dis[x];
}
int seef(int l,int *arr,long long *dis)
{
    if(arr[l]==0) return l;
    int a1=arr[l];
    int a2=seef(arr[l],arr,dis);
    arr[l]=a2;
    dis[l]=dis[l]+dis[a1];
    return a2;
}
void hebing(int l,int r,int d,int *arr,long long *dis)
{
    int lf=seef(l,arr,dis);
    int rf=seef(r,arr,dis);
    if(rf==lf)
    {
        if(seedis(r,arr,dis)-seedis(l,arr,dis)!=d)
            f=1;
        return;
    }
    arr[rf]=lf;
    dis[rf]=seedis(l,arr,dis)+d-seedis(r,arr,dis);
}
int main()
{
    int n,m;
    int arr[100500];
    long long dis[100500];
    cin>>n>>m;
    int l,r,d;
    for(int i=0;i<m;i++)
    {
        scanf("%d%d%d",&l,&r,&d);
        hebing(l,r,d,arr,dis);
        if(f==1) break;
    }
    if(f) cout<<"No";
    else cout<<"Yes";
    return 0;
}


Measured memory_bytes: 1536
x, y = gets.split.map(&:to_i)
a = [1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
puts a.include?(x) == a.include?(y) && b.include?(x) == b.include?(y) && c.include?(x) == c.include?(y) ? "Yes" : "No"

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_4_D
{
    public class Program

    {

        public class LoadCapacityComparer : IComparer<int>
        {
            private int[] items;
            private int k;

            public LoadCapacityComparer(int k, int[] items)
            {
                this.k = k;
                this.items = items;
            }

            public int Compare(int x, int y)
            {
                int sum =0;
                int TruckCount = 1;
                for (int i = 0 ; i < items.Count() ; i++)
                {
                    if (sum + items[i] <= x)
                    {
                        sum += items[i];
                    }
                    else
                    {
                        TruckCount++;
                        if (TruckCount > k) return -1;
                        sum = items[i];                      
                    }
                }
                return 1;   
            }
        }

        public static void Main(string[] args)
        {
            int[] line = ReadIntAr();
            int n = line[0];
            int k = line[1];

            int[] items = new int[n];
            for (int i = 0 ; i < n ; i++) items[i] = ReadInt();

            int itemMax = items.Max();
            int itemSum = items.Sum();

            LoadCapacityComparer lcc = new LoadCapacityComparer(k,items);
            int index = BinarySearch(itemMax,itemSum,lcc);

            Console.WriteLine(~index);

        }

        //●二分探索
        public static int BinarySearch(int left, int right, IComparer<int> comparer)
        {

            int lo = left;
            int hi = right;
            while (lo <= hi)
            {
                int i = GetMedian(lo, hi);
                int c = comparer.Compare(i,0);//yはダミーとして0固定
                if (c == 0) return i;
                if (c < 0) lo = i + 1;
                else hi = i - 1;
            }
            return ~lo;
        }
        private static int GetMedian(int low, int hi) { return low + ((hi - low) >> 1); }

        static string ReadSt() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Console.ReadLine()); }
        static long ReadLong() { return long.Parse(Console.ReadLine()); }
        static double ReadDouble() { return double.Parse(Console.ReadLine()); }
        static string[] ReadStAr(char sep = ' ') { return Console.ReadLine().Split(sep); }
        static int[] ReadIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => int.Parse(e)); }
        static long[] ReadLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => long.Parse(e)); }
        static double[] ReadDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Split(sep), e => double.Parse(e)); }

    }


}



Measured memory_bytes: 18340
#include <iostream>
#include <math.h>
#include <queue>
using namespace std;

typedef long long ll;
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define memset(v, h) memset((v), h, sizeof(v))
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll m[20][20];

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

struct node
{
    public: ll x;
    public: ll y;

    node(ll xx, ll yy)
    {
        x = xx;
        y = yy;
    }
};

int main(){
    ll h;
    cin >> h;

    ll p[h];
    rep(i,h) cin >> p[i];

    ll s = -1;
    ll m = 0;
    rep(i, h)
    {
        if(i == 0)
        {
            m++;
            s = p[i];
            continue;
        }

        if(s >= p[i])
        {
            m++;
            s = p[i];
        }
    }
    
    cout << m << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <cstring>
 
long long kazu[1002001];//1001^2
long long n,m,Max = 0,data[1001];
 
int main(){
    while(std::cin>>n>>m, n * m){
        if(n==0&&m==0)break;
 
        memset(kazu, 0, sizeof(kazu));
        memset(data, 0, sizeof(data));
 
        for(int i=0;i<n;i++){
            std::cin >> data[i+1];
        }
        for(int c=0;c<n+1;c++){
            for(int d=0;d<n+1;d++){
                kazu[c*n+d]=data[c]+data[d];
            }
        }
        std::sort(kazu,kazu+(n+1)*(n+1));
 
        long long* ptr;
        for(int i = 0; i < (n + 1) * (n + 1);++i){
            if(kazu[i] < m){
                ptr = std::upper_bound(kazu, kazu + (n + 1) * (n + 1), m - kazu[i]) - 1;
                Max = std::max(Max, *ptr + kazu[i]);
            }
        }
 
 
        std::cout << Max << std::endl;
        Max = 0;
    }

    return 0;
}

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

int n;
int main()
{
	scanf("%d",&n);
	int j = n;
	while((j & 1) == 0) j >>= 1;
	if(j == 1) {
		printf("No\n");
		return 0;
	} else {
		printf("Yes\n");
		printf("%d %d\n", 1, n+2);
		printf("%d %d\n", n+2, 3);
		printf("%d %d\n", 3, n+1);
		printf("%d %d\n", n+1, 2);
		printf("%d %d\n", 2, n+3);
		for(int i = 4;i < n;i += 2) {
			printf("%d %d\n", n+1, i);
			printf("%d %d\n", n+1, i+1);
			printf("%d %d\n", i, n+i+1);
			printf("%d %d\n", i+1, n+i);
		}
		if(n % 2 == 0) {
			for(int j = 2;j < n;++j) if((n^j^1)>=2 && (n^j^1)<n) {
				int a = n^j^1;
				printf("%d %d\n", n, a);
				printf("%d %d\n", 2*n, j);
				break;
			}
		}
	}
}


Measured memory_bytes: 2816
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(201)]
b = sorted(list(set(a) - set(p)))
min_v = 1000
min_id = 0
for i in range(len(b)):
  if abs(x - b[i]) < min_v:
    min_v = abs(x - b[i])
    min_id = i
print(b[min_id])

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
int x,n,stu[205][5],num[205][5],sum[205];
int main(){

    cin >> n;
    for(int i=0;i<n;i++){
       for(int j=0;j<3;j++){
            cin >> x;
            stu[i][j]=x;
            num[x][j]++;
       }
    }

    for(int i=0;i<3;i++){
        for(int j=0;j<n;j++){
            if(num[stu[j][i]][i]==1)sum[j]+=stu[j][i];
        }
    }




    for(int i=0;i<n;i++)cout << sum[i] << endl;


return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n,t,a,b,dp[3005],dp2[3005],ans;
int main(){
	scanf("%d%d", &n, &t);
	rep(i,n){
		scanf("%d%d", &a, &b);
		for(int j=t-1-a; j >= 0; j--){
			dp2[j+a] = max({dp2[j+a],dp2[j]+b,dp[j+a]+b});
			dp[j+a] = max(dp[j+a],dp[j]+b);
		}
		for(int j=a-1; j>=0; j--) dp2[j] = max(dp2[j],dp[j]+b);
	}
	rep(i,t) ans = max(ans, dp2[i]);
	printf("%d\n", ans);
}

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

using namespace std;

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


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define R(i,n) for(int i=0;i<n;++i)
int n,a,b,y[]={1000,100,10,1};
map<char,int> x;
string s,t="mcxi";
main(){
  x['m']=1000,x['c']=100,x['x']=10,x['i']=1;
  cin>>n;
  R(i,n){
    a=0;
    R(j,2){
      cin>>s;
      R(k,s.size())
        t.find(s[k])!=string::npos?a+=x[s[k]]:a+=(s[k]-'0')*x[s[++k]];
    }
    R(j,4){
      b=1;
      while(a/y[j])a-=y[j],++b;
      --b>1&&printf("%d%c",b,t[j]);
      --b||printf("%c",t[j]);
    }cout<<'\n';;
  }
}

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int a, b;
    cin >> a >> b;
    cout << (((b - a) * (b - a - 1)) / 2) - a << endl;
}


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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 20000005;
bool isPrime[MAXN];
vector<int> pr;
vector<pair<int,int>> ans;
void sieve()
{
    memset(isPrime, 1, sizeof isPrime);
    isPrime[0] = isPrime[1] = 0;

    for (int i = 2; i * i <= MAXN; i += 1 + (i & 1))
    {
        if (isPrime[i])
        {

            for (int j = i * i; j < MAXN; j += i)
                isPrime[j] = 0;
        }
    }
    for(int i=0; i<MAXN; i++)
    {
        if(isPrime[i])
        {
            if(!pr.empty())
            {
                if(i-pr.back()==2)
                {
                    ans.push_back({pr.back(),i});
                }
            }
            pr.push_back(i);

        }
    }
}

ld power(ld x, ll y)
{
    ll temp;
    if (y == 0)
        return 1;
    temp = power(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
        return x * temp * temp;
}

void debug_out()
{
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main()
{
     int n,k;
     cin>>n>>k;
     int arr[n];
     for(int i=0;i<n;i++)
        cin>>arr[i];
     sort(arr,arr+n);
     int sum=0;
     for(int i=0;i<k;i++)
        sum+=arr[i];
     cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int A[1000005];
int a,n;
int main(int argc, char** argv) {
	cin>>n;
	for(int i=1;i<=n;i++) 
	{
		cin>>a;
		A[a]=i;
	}
	for(int i=1;i<=n;i++) 
	{
		cout<<A[i]<<" ";
	}
	return 0;
}

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

#define FOR( i, m, n )	for( int (i) = (m); (i) < (n); i++ )
#define REP( i, n )		FOR( i, 0, n )
#define ALL( x )		(x).begin(), (x).end()

int main() {
	int a, b, c; cin >> a >> b >> c;

	if( ( a > c && b < c ) || ( a < c && b > c ) ) cout << "Yes" << endl;
	else										   cout << "No" << endl;
}

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

int main() {
  int k;cin>>k;
  string s; cin>>s;
  if(s.size()<=k) cout<<s<<endl;
  else{
    string ans;
    ans=s.substr(0,k);
    cout <<ans<<"..."<<endl;
  }
}


Measured memory_bytes: 3600
from fractions import Fraction
import sys
input = sys.stdin.readline

INF = float('inf')

N,A,B = list(map(int,input().split()))
data = [list(map(int, input().split())) for _ in range(N)]

P = []
M = []
Z = []
for a,b,c in data:
  if Fraction(a,b) == Fraction(A,B):
    Z.append(c)
  elif Fraction(a,b) > Fraction(A,B):
    P.append((a*2520-b*2520*A//B,c))
  else:
    M.append((-a*2520+b*2520*A//B,c))
    
dpP = [INF for i in range(1000000)]
dpP[0] = 0
for v,c in P:
  for i in range(1000000)[::-1]:
    if i>=v:
      dpP[i] = min(dpP[i],dpP[i-v]+c)

dpM = [INF for i in range(1000000)]
dpM[0] = 0
for v,c in M:
  for i in range(1000000)[::-1]:
    if i>=v:
      dpM[i] = min(dpM[i],dpM[i-v]+c)
      
ans = INF
if Z:
  ans = min(Z)
for i in range(1,1000000):
  ans = min(ans,dpP[i]+dpM[i])

if ans == INF:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 220588
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int maxDiff = -1;
        int targetId = 0;
        int[] array = new int[5];
        for(int i = 0; i < 5; i++) {
            int num = sc.nextInt();
            int target = num / 10 * 10 + 10;
            array[i] = num;
            int diff = target - num;
            if(diff == 10) diff = 0;
            if(diff >= maxDiff) {
                maxDiff = diff;
                targetId = i;
            }
        }
        int ans = 0;
        for(int i = 0; i < 5; i++) {
            if(targetId != i) {
                if(array[i] % 10 == 0) {
                    ans += array[i];
                } else {
                    int num = array[i] / 10 * 10 + 10;
                    ans += num;
                }
            } else {
                ans += array[i];
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23124