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

#define ll long long int

using namespace std;

int main() {
    ll d;
    cin >> d;
    vector<ll> C(26);
    for (auto & c : C) cin >> c;
    vector<vector<ll>> S(d, vector<ll>(26));

    for (ll i = 0; i < d; ++i) {
        for (ll j = 0; j < 26; ++j) {
            cin >> S[i][j];
        }
    }

    vector<ll> last(26, 0);

    ll res = 0;
    for (ll i = 0; i < d; ++i) {
        ll p = -1;
        ll m = -1e9;
        for (ll j = 0; j < 26; ++j) {
            if (j == 0 || m < S[i][j]) {
                m = S[i][j] + (last[j]+1) * C[j];
                p = j;
            }
        }
        cout << p + 1 << endl;
        res += S[i][p];
        ll minus = 0;
        for (ll j = 0; j < 26; ++j) {
            if (j == p) {
                last[p] = 0;
            } else {
                ++last[j];
                minus += C[j] * last[j];
            }
        }
        res -= minus;
    }
    cerr << res << endl;
}


Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=55;
int n,m,ans,q,A[N],a[N],b[N],c[N],d[N];
int getans()
{
    int ans=0;
    for(int i=1;i<=q;i++)
        if(A[b[i]]-A[a[i]]==c[i])
        ans+=d[i];
    return ans;
}
void dfs(int pos,int v)
{
    A[pos]=v;
    if(pos==n) {ans=max(ans,getans());return;}
    for(int i=0;;i++)
        if(v+i<=m) dfs(pos+1,v+i);
        else break;
}
int main()
{
    scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=q;i++)
        scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
    dfs(0,1);
    printf("%d\n",ans);
}


Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin>>S;
    if(S=="abc"||S=="acb"||S=="bac"||S=="bca"||S=="cab"||S=="cba"){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }}

Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;

int main(void) {
	int n;
	cin >> n;
	ll sum = 0;
	vector<ll>s(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	int q;
	cin >> q;
	vector<ll>t(q);
	for (int i = 0; i < q; i++) {
		cin >> t[i];
	}

	for (int i = 0; i < q; i++) {
		if (binary_search(s.begin(), s.end(), t[i])) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 3832
###test
n=int(input())
A=list(map(int,input().split( )))
B=list(map(int,input().split( )))
count=0
flag=True
while flag:
    flag=False
    for i in range(-1,n-1):
        tonari=B[i-1]+B[i+1]
        tmp=(B[i]-A[i])//tonari
        if tmp>0:
            B[i]-=tonari*tmp
            count+=tmp
            flag=True
if A==B:
    print(count)
else:
    print(-1)


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

using namespace std;

int main() {

	int ans;

	string s;

	cin >> s;

	if (s[0] == '1') {
		ans++;
	}
	if (s[1] == '1')ans++;
	if (s[2] == '1')ans++;
	cout << ans;
}
	

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

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

// -------------------------------------------------------

const long long MAX_V = 1010101;

struct edge {
  long long to, cost;
};

using Pll = pair<long long, long long>;

long long V;
vector<edge> Graph[MAX_V];
long long dist[MAX_V];

void dijkstra(long long s) {
  priority_queue<Pll, vector<Pll>, greater<Pll>> que;

  fill(dist + 1, dist + 1 + V, INF);

  dist[s] = 0;
  que.push(Pll(0, s));

  while (!que.empty()) {
    auto elem = que.top();
    que.pop();

    auto cv = elem.second;

    if (elem.first > dist[cv]) {
      continue;
    }

    for (auto e : Graph[cv]) {
      if (dist[e.to] > dist[cv] + e.cost) {
        dist[e.to] = dist[cv] + e.cost;
        que.push(Pll(dist[e.to], e.to));
      }
    }
  }
}

ll N;
ll Q, K;

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

  rep(i, 1, N) {
    ll a, b, c;
    cin >> a >> b >> c;
    Graph[a].push_back(edge{b, c});
    Graph[b].push_back(edge{a, c});
  }

  cin >> Q >> K;
  dijkstra(K);
  vector<ll> ans;
  rep(i, 0, Q) {
    ll x, y;
    cin >> x >> y;
    ans.push_back(dist[x] + dist[y]);
  }

  for (auto e : ans) {
    cout << e << "\n";
  }
}


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

typedef long long lint;
typedef long double louble;
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}
template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return b<a?a:b;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 1000007 , mo = 998244353;

inline lint powa(lint a,lint t)
{
	lint b=1;
	while(t){if(t&1)b=b*a%mo;a=a*a%mo,t>>=1;}
	return b;
}

inline lint inva(lint a)
{
	return powa(a,mo-2);
}

lint jc[_],rjc[_];

inline void init(int n=_-1)
{
	jc[0]=jc[1]=rjc[0]=1;
	for(int i=2;i<=n;i++)jc[i]=jc[i-1]*i%mo;
	rjc[n]=inva(jc[n]);
	for(int i=n-1;i>=1;i--)rjc[i]=rjc[i+1]*(1ll+i)%mo;
}

inline lint C(int n,int m)
{
	if(n<m || n<0 || m<0)return 0;
	return jc[n]*rjc[m]%mo*rjc[n-m]%mo;
}

inline lint crx(int n,int m)
{
	return C(n+m,m);
}

int n,m;

int main()
{
	n=ty(),m=ty();
	if(n<m)swap(n,m);

	init(n+m);
	
	lint ans=0;
	for(int i=1;i<=m;i++)ans=(ans+crx(i,i)*crx(n-i,m-i)%mo)%mo;
	ans=(ans*inva(crx(n,m))%mo*inva(2)%mo+n)%mo;
	printf("%lld\n",ans);

	return 0;
}

Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
//int dp[104][100005];
long long dp[100005];
int main()
{
  long long n,we,i,j;
  cin>>n>>we;
  long long w[n+1],v[n+1];
  for(i=1;i<=n;i++)
  {
    cin>>w[i]>>v[i];
  }
  //2d dp
 /*for(i=1;i<=n;i++)
  {
    for(j=we;j>=w[i];j--)
    {
      dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
    }
  }
  cout<<dp[n][we];*/
  //1d dp
  for(int i=1;i<=n;i++){
		for(int j=we;j>=w[i];j--){
			dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
		}
	}
	
	cout<<dp[we];
	
	

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  lint N,P;
  cin>>N>>P;
  map<lint,lint> m;
  FOR(i,2,1000*1000+1){
    while(P%i==0){
      m[i]+=1;
      P/=i;
    }
    if(P==1)break;
  }
  if(P!=1)m[P]+=1;
  lint ans=1;
  for(auto& e:m){
    // cerr<<e.first<<" "<<e.second<<endl;
    while(e.second>=N){
      ans*=e.first;
      e.second-=N;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

int main(){
  int n,a[100],alice,bob;
  alice =0;
  bob =0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a + n,greater<int>());
  int i = 0;
  bool alicec = true;
  while(i<n){
    if(alicec){
      alice += a[i];
      alicec = false;
    }
    else{
      bob += a[i];
      alicec = true;
    }
    i++;
  }
  cout << alice -bob << endl;
  return 0;
}

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

int N, M;
int a[1050], b[1050], c[1050][20];

void input() {
    cin >> N >> M;
    for(int i = 1; i <= M; ++i) {
        cin >> a[i] >> b[i];
        for(int j = 1; j <= b[i]; ++j) cin >> c[i][j];
    }
}

void solve() {
    input();
    const int INF = 1e9;
    vector<int> dp(5000, INF);
    dp[0] = 0;
    for(int item = 1; item <= M; ++item) {
        int now = 0;
        for(int j = 1; j <= b[item]; ++j) {
            now |= (1 << (c[item][j] - 1));
        }
        for(int bits = 0; bits < (1<<N); ++bits) {
            dp[bits | now] = min(dp[bits | now], dp[bits] + a[item]);
        }
    }
    if(dp[(1<<N) - 1] == INF) dp[(1<<N) - 1] = -1;
    cout << dp[(1<<N)-1] << endl;
    return ;
}

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD1 998244353
#define MOD2 1000000007

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;

int power(ll a,ll b,ll m)
{
ll ans=1;
while(b>0){if(b&1){ans*=a;ans%=m;}a*=a;a%=m;b>>=1;}
return ans;
}


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

    int n,k;
    cin>>n>>k;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }

    int dp[n] = {0};
    for(int i=1;i<k&&i<n;i++)
    {
        dp[i] = abs(h[i]-h[0]);
        for(int j=i;j>=0;j--)
        {
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }

    for(int i=k;i<n;i++)
    {
        dp[i] = dp[i-k]+abs(h[i]-h[i-k]);
        for(int j=i;j>=i-k;j--)
        {
            dp[i] = min(dp[i], dp[j] + abs(h[i]-h[j]));
        }
    }

    cout<<dp[n-1]<<endl;

}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    int N, K;		
    cin >> N >> K;
    int A[N];
    long long num1, num2;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }      

    num1 = 1;
    num2 = 1;
    for(int i = 0; i < N - K; i++) {
        if(A[i] < A[i + K]) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
        
    }
}

Measured memory_bytes: 4420
#include<vector>
#include<queue>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string.h>
#define pb push_back
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vi;



vector<int> edg[300050];
bool vis[300050];
int dist[300050];

void bfs(int start) {
	memset(vis, 0, sizeof(vis));
	memset(dist, -1, sizeof(dist));
	queue<int> q;
	q.push(start);
	dist[start] = 0;
	vis[start] = true;
	while (!q.empty()) {
		int cur = q.front();
		q.pop();
		rep(i, 0, edg[cur].size()) {
			int nxt = edg[cur][i];
			if (!vis[nxt]) {
				vis[nxt] = true;
				dist[nxt] = dist[cur] + 1;
				q.push(nxt);
			}
		}
	}
}

int main(){
	ll N, X, Y;
	cin >> N >> X >> Y;
	rep(i, 0, N - 1)
	{
		edg[i + 1].pb(i);
		edg[i].pb(i + 1);
		
	}
	edg[X-1].pb(Y-1);
	edg[Y-1].pb(X-1);
	vi K(2005);
	rep(i, 0, N)
	{
		bfs(i);
		rep(j, 0, N)
		{
			if (i == j) continue;
			K[dist[j]]++;
		}
	}
	rep(i, 1, N) cout << K[i]/2 << endl;
}

Measured memory_bytes: 8960
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final char[] chars = scanner.next().toCharArray();
        Arrays.sort(chars);
        if (chars[0] == chars[1] &&chars[2] == chars[3] &&chars[1] != chars[2]) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

struct Card {
	char suit;
	int num;
};

void swapc(Card& c1, Card& c2);

int main() {
	Card c1[36], c2[36];
	int i, j, n, mini, tmpn;
	char tmpc, dum;
	bool flag;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin.get(dum);
		cin.get(c1[i].suit);
		cin >> c1[i].num;
	}
	for (i = 0; i < n; i++)c2[i] = c1[i];

	for (i = 0; i < n; i++) {
		for (j = n - 1; j > i; j--) {
			if (c1[j].num < c1[j - 1].num)swap(c1[j], c1[j - 1]);
		}
	}
	
	for (i = 0; i < n; i++) {
		mini = i;
		for (j = i + 1; j < n; j++) {
			if (c2[j].num < c2[mini].num)mini = j;
		}
		swap(c2[i], c2[mini]);
	}

	for (i = 0; i < n; i++) {
		if (c1[i].suit != c2[i].suit || c1[i].num != c2[i].num)break;
	}
	if (i == n)flag = true;
	else flag = false;

	for (i = 0; i < n; i++) {
		cout << c1[i].suit << c1[i].num;
		if (i != n - 1)cout << " ";
	}
	cout << endl << "Stable" << endl;

	for (i = 0; i < n; i++) {
		cout << c2[i].suit << c2[i].num;
		if (i != n - 1)cout << " ";
	}
	cout << endl;
	if (flag == true)cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	
	return 0;
}

Measured memory_bytes: 1164
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    IN(string, S);
    ll ans = 0;
    REP1(k, N - 1)
    {
        set<char> s1, s2;
        REP(i, k)
        {
            s1.insert(S[i]);
        }
        REP(i, N - k)
        {
            s2.insert(S[k + i]);
        }
        ll x = 0;
        FOR(c, s1)
        {
            if (s2.find(c) != s2.end())
            {
                ++x;
            }
        }
        CH(max, ans, x);
    }
    OUT(ans);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] NMX = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            long[] A = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            int cnt = 0;
            int cnt2 = 0;
            //スタートからX
            for(long j = 0; j < NMX[2]; j++)
            {
                for(int z = 0; z < NMX[1]; z++)
                {
                    if (j == A[z])
                    {
                        cnt++;
                    }
                }
            }
            //Xからゴール
            for(long p = NMX[2]; p <= NMX[0]; p++)
            {
                for (int z = 0; z < NMX[1]; z++)
                {
                    if (p == A[z])
                    {
                        cnt2++;
                    }
                }
            }
            Console.WriteLine(Math.Min(cnt, cnt2));
        }
    }
}
// 文字列の入力
//string s = Console.ReadLine();

// 整数の入力
//long n = long.Parse(Console.ReadLine());

// 文字列配列の入力
//string[] inputStrArray = Console.ReadLine().Split(' ');

// 整数配列の入力
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();


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

int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  for (int i=0; i<n; i++) cin >> t[i];
  int m;
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  for (int i=0; i<m; i++) cin >> p[i] >> x[i];

  for (int i=0; i<m; i++) {
    int sum = 0;
    for (int j=0; j<n; j++) {
      if (j+1 == p[i]) sum += x[i];
      else sum += t[j];
    }
    cout << sum << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    string ans;

    //行き（1回目）
    ans += string(tx - sx, 'R');
    ans += string(ty - sy, 'U');

    //帰り（1回目）
    ans += string(tx - sx, 'L');
    ans += string(ty - sy, 'D');

    //行き（2回目）
    ans += string(1, 'D');
    ans += string(tx - sx + 1, 'R');
    ans += string(ty - sy + 1, 'U');
    ans += string(1, 'L');

    //帰り（2回目）
    ans += string(1, 'U');
    ans += string(tx - sx + 1, 'L');
    ans += string(ty - sy + 1, 'D');
    ans += string(1, 'R');

    cout << ans << endl;

    return 0;
}

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

int main() {
  ll n; cin>>n;
  vector<ll> a(n),l,r;
  for(int i=0; i<n; i++) cin>>a[i];
  if(a.size()%2==0) {
  	for(int i=0; i<n; i++) {
    	if(i%2==0) r.push_back(a[i]);
    	else l.push_back(a[i]);
  	}
  }
  else {
  	for(int i=0; i<n; i++) {
    	if(i%2==0) l.push_back(a[i]);
    	else r.push_back(a[i]);
  	}
  }
  reverse(l.begin(),l.end());
  for(int i=0; i<l.size(); i++) cout<<l[i]<<" ";
  for(int i=0; i<r.size(); i++) cout<<r[i]<<" ";
}

Measured memory_bytes: 5484
import random as rng
import itertools as it
import collections as col
import heapq as hq
import sys
import copy as cp
sys.setrecursionlimit(10**9)


def dump_impl(*objects):
    print(*objects, file=sys.stderr)


def dump_dummy(*objects):
    pass


dump = dump_impl if "DEBUG" in sys.argv else dump_dummy

S = input()
print(S.count('1'))


Measured memory_bytes: 6120
#include <bits/stdc++.h>
using namespace std;
int A,B,K;
int main(){
    cin>>A>>B>>K;
    if(A+K-1>=B-K+1){
        for(int i=A;i<=B;i++)
            cout<<i<<"\n";
    }else{
        for(int i=A;i<A+K;i++)
            cout<<i<<"\n";
        for(int i=B-K+1;i<=B;i++)
            cout<<i<<"\n";
    }    
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int main(void){
    int n,k;
    cin >> n >> k;
    int candle[n];
    for(int i=0; i<n; i++){
        cin >> candle[i];
    }
    int base=n;
    for(int i=0; i<n; i++){
        if(candle[i]>=0){
            base=i;
            break;
        }
    }
    int sum[n+1]={0},rev[n+1]={0};
    //sumは1.revも1から
    int summax=0,revmax=0;
    for(int i=0; i+base<n; i++){
        sum[i+1]=candle[i+base];
        summax=i+1;
    }
    for(int i=0; base-(i+1)>=0; i++){
        rev[i+1]=candle[base-(i+1)];
        revmax=i+1;
    }
    long long int ans=100000000000000000,temp;
    for(int i=0; i<=k; i++){
        temp=min(sum[i]*2+rev[k-i]*(-1),sum[i]+rev[k-i]*(-2));
        if(i>summax||k-i>revmax)continue;
        ans=min(ans,temp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
// Ala be zekrellah tatmaenolgholoob ...
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 1e6+9;
const ll mod = 1e9+7;

ll x[maxn];

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> x[i];
	ll res = 1e18;
	int num = 0;
	for (int i = 0; i < n; i++) {
		if (x[i] >= 0)
			num++;
		if (num == k)
			res = x[i];
	}
	num = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (x[i] < 0)
			num++;
		if (num == k)
			res = -x[i];	
	}
	for (int i = 0; i < n; i++) {
		if (x[i] < 0)
			if (i + k - 1 < n)
				res = min(res, -x[i] + abs(x[i + k - 1] - x[i]));
		if (x[i] >= 0)
			if (i - k + 1 >= 0)
				res = min(res, x[i] + abs(x[i] - x[i - k + 1]));
	}
	cout << res << "\n";
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        sc.close();

        int ans = 0;

        for (int i = 0; i < 2; i++) {
            if (a > b) {
                ans += a;
                a--;
            } else {
                ans += b;
                b--;
            }
        }

        System.out.println(ans);
    }

}

Measured memory_bytes: 21844
from collections import Counter
N = int(input())
A = list(map(int,input().split()))

divide = []
for i in range(N):
    a = A[i]
    tmp = []
    d = 2
    while d*d <= a:
        while a%d == 0:
            tmp.append(d)
            a //= d
        d += 1
    if a != 1:
        tmp.append(a)
    divide.append(Counter(tmp))

lcm = Counter([])
for count in divide:
    for k,v in count.items():
        if k not in lcm:
            lcm[k] = v
        else:
            lcm[k] = max(lcm[k],v)

mod = 10**9 +7
LCM = 1
for k,v in lcm.items():
    LCM *= pow(k,v,mod)
    LCM %= mod

ans = 0
for a in A:
    ans += LCM*pow(a,mod-2,mod)
    ans %= mod
print(ans)

Measured memory_bytes: 79536
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});
process.stdin.on('end', function() {
    main(g_input.split(/\r?\n/));
});

function main(inputs) {
  //`input` に入力が改行で区切られた配列として入ってくるので頑張って
  var rgb = inputs[0].split(" ");
  if((parseInt(rgb[1])*10 + parseInt(rgb[2])) % 4 == 0){
    console.log("YES");
  }else{
    console.log("NO");
  }
}


Measured memory_bytes: 7500
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define loop(i, n) rep(i, 0, n)
using namespace std;
using ll = long long;
template<class T, class Compare=less<T>> class SlideMinimum {
    deque<int> deq; vector<T> a; Compare cmp; int L, R;
public:
    SlideMinimum(const vector<T> &a): a(a), cmp(Compare()), L(0), R(0) {}
    inline void inc_L() { if(deq.front() == L++) deq.pop_front(); }
    inline void inc_R() { while(!deq.empty() && !cmp(a[deq.back()], a[R])) deq.pop_back(); deq.push_back(R++); }
    inline void slide_L(const int l) { assert(L<=l); while(L<l)inc_L(); }
    inline void slide_R(const int r) { assert(R<=r); while(R<r)inc_R(); }
    inline void slide(const int l, const int r) { if(R<=l){deq.clear(); L=R=l; } slide_R(r); slide_L(l); }
    inline void clear() { deq.clear(); L=R=0; }
    inline int getIndex() const { return deq.front(); }
};
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    loop(i, n) cin >> p[i];
    //cnt_sorted=（k-1個以上ソート済みである区間の数）
    int cnt_sorted=0,cnt=0;
    loop(i,n-1){
        if(p[i]<p[i+1])++cnt;
        else cnt=0;
        if(cnt==k-1)++cnt_sorted;
    }
    SlideMinimum<int> slide_min(p);
    SlideMinimum<int,greater<int>> slide_max(p);
    int ans=1+min(0,1-cnt_sorted);
    loop(i,n-k){
        //      [i,i+k)と[i+1,i+k+1)をソートしたときに配列が等しい
        // <==> [i,i+k+1)の最小値がp[i],最大値がp[i+k]
        slide_min.slide(i,i+k+1);
        slide_max.slide(i,i+k+1);
        if(slide_min.getIndex()!=i || slide_max.getIndex()!=i+k)++ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3456
// BEGINNING WITH THE NAME OF ALMIGHTY GOD ALLAH
// AUTHOR:: MOHAMMAD FAISAL
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a<=b)
  {
    for(int i=1;i<=b;i++)
      cout<<a;
  }
  else
  {
    for(int i=1;i<=a;i++)
      cout<<b;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,k = inpl()
v = inpl()
m = min(n,k)
ans = 0
for a in range(m+1):
    for b in range(m+1):
        if a+b > m:
            continue
        q = deque(v)
        tmp = []
        for i in range(a):
            tmp.append(q.popleft())
        for j in range(b):
            tmp.append(q.pop())
        if k - (a + b) > 0:
            tmp.sort()
            for i in range(k-(a+b)):
                if not tmp:
                    break
                if tmp[0] < 0:
                    tmp.pop(0)
                else:
                    break
        ans = max(ans, sum(tmp))
print(ans)
        

            

Measured memory_bytes: 42732
#include<bits/stdc++.h>
using namespace std;
int main(){
    const int mod=1000000007;
    string l;
    cin>>l;
    int n=l.size();
    long long dp[n][2]={};
    dp[0][0]=1;
    dp[0][1]=2;
    for(int i=1;i<n;i++){
        dp[i][0]+=dp[i-1][0]*3%mod;
        if(l[i]=='0')dp[i][1]+=dp[i-1][1]%mod;
        else{
            dp[i][0]+=dp[i-1][1]%mod;
            dp[i][1]+=dp[i-1][1]*2%mod;
        }
    }
    cout<<(dp[n-1][0]+dp[n-1][1])%mod<<endl;
    return 0;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

string ans = "CODEFESTIVAL2016";

int main() {
    string s;
    cin >> s;
    li res = 0;
    rep(i, sz(s)) {
        if (s[i] != ans[i])res++;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define drep(i,r,l) for(int i=r;i>=l;--i)
using namespace std;
const int sz=1e6+7;
const int mod=1e9+7;
int n,h,d;
int ans;
int f[sz<<1];
int fac[sz],sum[sz];
void init(){
	fac[1]=sum[1]=1;
	rep(i,2,sz-1){
		fac[i]=1ll*i*fac[i-1]%mod;
		sum[i]=(sum[i-1]+fac[i])%mod;
	}
}
int main(){
	init();
	scanf("%d%d%d",&n,&h,&d);
	f[1]=fac[n],f[d+1]=mod-fac[n];
	rep(i,1,h){
		ans=(ans+f[i])%mod;
		f[i+1]=(f[i+1]+1ll*ans*sum[n]%mod)%mod;
		f[i+d+1]=(f[i+d+1]-1ll*ans*sum[n]%mod+mod)%mod; 
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 15872
S=input()

Slist=list(S)

flag=True

for i, c in enumerate(S):
  if i%2==0 and c!='h':
    flag=False
    break
  if i%2==1 and c!='i':
    flag=False
    break
if flag and len(S)%2==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9108
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <deque>
#include <cmath>
#include <complex>
#include <cassert>
#include <cstring>
#include <functional>
#include <bitset>
#include <climits>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  (1LL << 60)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define cmn(x,y) x=min(x,y)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    segtree(vector<T>& v){
        sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n);
        rep(i,sz){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    void update(int k, T a)
    {
    	node[k+=n] = make_pair(a, k);
    	while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
    	}
    }
    pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1)
    {
        pair<T, int> res1 = make_pair(inf, -1);
        pair<T, int> res2 = make_pair(inf, -1);
        a += n, b += n;
        while(a != b){
            if(a % 2) cmn(res1, node[a++]);
            if(b % 2) cmn(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
    void print()
    {
        rep(i,sz){
            pair<T, int> p;
            p = query(i,i+1);
            cout << "st[" << i << "]: " << p.first << " " << p.second << endl;
        }
    }
};


int n;
ll d;
ll saiki(segtree<ll>& sg, int a,int b){
    //cerr << a << " " << b << endl;
    if(b==a+1)return 0;
    auto p = sg.query(a,b);
    ll s = p.first;
    ll ans = 0;
    int ind = p.second;
    if(ind-1>=a){
        ll xx = sg.query(ind-1,ind).first;
        ans += s+d+xx;
        sg.update(ind-1,min(xx,s+d));
        ans += saiki(sg,a,ind);
    }
    if(ind+1<b){
        ll xx = sg.query(ind+1,ind+2).first;
        ans += s+d+xx;
        sg.update(ind+1,min(xx,s+d));
        ans += saiki(sg,ind+1,b);
    }
    return ans;
}


int main(){
    cin >> n >> d;
    vector<ll>v(n+1);
    rep(i,n)cin >> v[i];
    segtree<ll> sg(v);
    ll ans = saiki(sg,0,n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 34944
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main(){
  string s, t;
  cin >> s >> t;
  s += s;
  s += s;
  string ans = "No";

  //cout << s << endl;

  for(int i = 0; i < 2*t.size(); i++){
    int j = 0;
    int cnt = 0;
    while(t[j] == s[i+j]){
      cnt += 1;
      j++;
      if(cnt == t.size()) {
        ans = "Yes";
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

#define rep(i,a,n) for (int i = a;i<=n;++i)
#define per(i,a,n) for (int i = n;i>=a;--i)
#define all(x) (x).begin(), (x).end()     
#define SZ(x) ((int)x.size())

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

mt19937 mrand(random_device{}());
ll rnd(ll a, ll b) { return a + mrand() % (b - a + 1); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
      ios::sync_with_stdio(false); cin.tie(0);
#ifdef arrias
      freopen("a.txt", "r", stdin);
#endif
      int n, m;
      cin >> n >> m;
      cout << n * (n - 1) / 2 + m * (m - 1) / 2;
      return 0;
}

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

// why am I so weak

int x, y, z;
int a[100055], b[100055], c[100055];

int group[100055];

typedef pair<int, int> P;

#define ft first
#define sd second

int main() {
	cin >> x >> y >> z;

	int n = x + y + z;
	long long res = 0;

	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", &a[i], &b[i], &c[i]);
		res += a[i];
	}

	vector<int> vec(n);

	for (int i = 0; i < n; i++) {
		vec[i] = i;
	}

	sort(vec.begin(), vec.end(), [&] (int u, int v) {
		return (b[u] - a[u]) > (b[v] - a[v]);
	});

	for (int i = 0; i < y; i++) {
		res += b[vec[i]] - a[vec[i]];
		group[vec[i]] = 1;
	}

	priority_queue<P> A, B, T;

	for (int i = 0; i < n; i++) {
		if (group[i] == 0) {
			A.push(P(c[i] - a[i], i));
			T.push(P(b[i] - a[i], i));
		} else {
			B.push(P(c[i] - b[i], i));
		}
	}

	for (int i = 0; i < z; i++) {
		while (!A.empty() && group[A.top().sd] != 0) A.pop();
		while (!T.empty() && group[T.top().sd] != 0) T.pop();

		while (!B.empty() && group[B.top().sd] != 1) B.pop();

		if (A.empty() || (!B.empty() && !T.empty() && A.top().ft < B.top().ft + T.top().ft)) {
			res += T.top().ft + B.top().ft;

			group[T.top().sd] = 1;
			group[B.top().sd] = 2;

			B.push(P(c[T.top().sd] - b[T.top().sd], T.top().sd));
		} else {
			res += A.top().ft;
			group[A.top().sd] = 2;
		}
	}

	printf("%lld\n", res);
	
	return 0;
}


Measured memory_bytes: 4200
//#include "stdafx.h"
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int a,b,ans,q;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

	cin>>a>>b;
	q=abs(a-b);
	ans=16-(a+b);
	if(q>ans/2)
		cout<<":(\n";
	else
		cout<<"Yay!\n";
	
	
	return 0;
}



Measured memory_bytes: 3640
H,W = map(int,input().split())
grid = [[0] for _ in range(H)]
for i in range(H):
    grid[i] = input()
dp = [[float('inf')]*W for _ in range(H)]
if grid[0][0] == '.':
    dp[0][0] = 0
else:
    dp[0][0] = 1
for y in range(H):
    for x in range(W):
        if x > 0:
            if grid[y][x-1] == '.' and grid[y][x] == '#':
                dp[y][x] = min(dp[y][x],dp[y][x-1]+1)
            else:
                dp[y][x] = min(dp[y][x],dp[y][x-1])
        if y > 0:
            if grid[y-1][x] == '.' and grid[y][x] == '#':
                dp[y][x] = min(dp[y][x],dp[y-1][x]+1)
            else:
                dp[y][x] = min(dp[y][x],dp[y-1][x])
print(dp[-1][-1])

Measured memory_bytes: 74404
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

string S, T;
int ind = -1;

int main()
{
	cin >> S >> T;

	for(int i = 0; i < S.size(); i++) {
		bool canDo = 1;

		for(int  j = 0; j < T.size(); j++) {
			if(i + j >= S.size()) {
				canDo = 0;
				break;
			}

			if(S[i + j] == '?' || (S[i + j] == T[j])) {
				continue;
			} else {
				canDo = 0;
				break;
			}
		}

		if(canDo) {
			ind = i;
		}
	}

	if(ind == -1) {
		cout << "UNRESTORABLE";
		return 0;
	}

	for(int i = 0; i < T.size(); i++) {
		S[i + ind] = T[i];
	}

	for(int i = 0; i < S.size(); i++) {
		if(S[i] == '?') {
			S[i] = 'a';
		}
	}

	cout << S;


	return 0;
}
/*
	Powered by Buggy Plugin
*/

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

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

int main()
{
    int a,b,c,d;
    cin >> a;
    b = a%1000;
    c = b%100;
    d = c%10;
    a /= 1000;
    b /= 100;
    c /= 10;
    rep(i,2)
    {
        if(i==1) a *= -1;
        rep(j,2)
        {
            if(j==1) b *= -1;
            rep(k,2)
            {
                if(k==1) c *= -1;
                rep(l,2)
                {
                    if(l==1) d *= -1;
                    if(a+b+c+d==7)
                    {
                        cout << a;
                        if(b>=0) cout << "+" << b;
                        else cout << b;
                        if(c>=0) cout << "+" << c;
                        else cout << c;
                        if(d>=0) cout << "+" << d;
                        else cout << d;
                        cout << "=7" << endl;
                        return 0;
                    }
                }
                d *= -1;
            }
            c *= -1;
        }
        b *= -1;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  long long ll=k;
  for(int i=0;i<n-1;i++)
  {
    ll*=(k-1);
  }
  cout<<ll<<endl;
  return 0;
}

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

using namespace std;

int N, T, A;
int H[100002];
float ans = 10000000;
int ans_i = 0;

int main(){

    cin >> N;
    cin >> T >> A;

    for(int i = 0; i < N; i++){
        cin >> H[i];
    }

    for(int i = 0; i < N; i++){
        float tmp = abs(A - (T - H[i] * 0.006));
        if(ans > tmp){
            ans_i = i+1;
            ans = tmp;
        }
    }

    cout << ans_i << endl;
    return 0;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
p = 1000000007
frac = [1]

for i in range(N):
  frac.append(frac[i]*(i+1)%p)

def comb(n, k, mod):
    a=frac[n]
    b=frac[k]
    c=frac[n-k]
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod
  
ans = 0  
for i in range(N- K +1):
  ans += ((A[N-1-i] - A[i])*comb(N-1-i, K-1, p))
  ans = ans % p
print(ans)

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

int cnt[55], n, m;

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    ++cnt[x];
    ++cnt[y];
  }
  for(int i = 0; i < n; ++i) cout << cnt[i + 1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n, q, query, b, e;
    cin >> n;
    vector<int> vec(n);
    for (int i = 0; i < n; i++)
        cin >> vec[i];
    cin >> q;
    while (q--) {
        cin >> query;
        if (query == 0) {
            cin >> b >> e;
            int min=vec[b];
            for (int i = b; i < e; i++) {
                if (vec[i] < min)
                    min = vec[i];
            }
            cout << min << endl;
        }
        if (query == 1) {
            cin >> b >> e;
            int max = vec[b];
            for (int i = b; i < e; i++) {
                if (vec[i] >max)
                    max = vec[i];
            }
            cout << max << endl;
        }
    }
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
int main(){
    #define int long long
    const int mod=1000000007;
    int n,m;
    cin>>n>>m;
    int X[n],Y[m];
    for(int i=0;i<n;i++)cin>>X[i];
    for(int i=0;i<m;i++)cin>>Y[i];
    n--;
    m--;
    int x[n],y[m];
    for(int i=1;i<=n;i++)x[i-1]=X[i]-X[i-1];
    for(int i=1;i<=m;i++)y[i-1]=Y[i]-Y[i-1];
    int sx=0,sy=0;
    for(int i=0;i<n;i++){
        sx+=(((i+1)*(n-i))%mod)*x[i];
        sx%=mod;
    }
    for(int i=0;i<m;i++){
        sy+=(((i+1)*(m-i))%mod)*y[i];
        sy%=mod;
    }
    cout<<(sx*sy)%mod<<endl;
    return 0;
}


Measured memory_bytes: 6680
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(ll i=0;i<n;++i)
#define FOR(i,j,n) for(ll i=j;i<n;++i)
#define MOD (1e9 + 7)

int main(void){
    string S;
    cin >> S;
    if(S=="ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val (N, X) = readLine()!!.split(" ").map { it.toInt() }
    val x = readLine()!!.split(" ").map { it.toInt() - X }
    var buffer = x[0]
    for (i in 1 until N) {
        buffer = gcd(buffer, x[i])
    }
    println(Math.abs(buffer))
}

fun gcd(a: Int, b: Int): Int {
    if (b == 0) return a
    return gcd(b, a % b)
}

Measured memory_bytes: 50860
#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > v[100005];
long long tree[400005];
void update(int node,int st,int en,int l,int r,long long val)
{
	if (en<l || st>r || r<l)
	return;
	if (l<=st && en<=r)
	{
		tree[node]=min(tree[node],val);
		return;
	}
	int mid=(st+en)/2;
	update(2*node,st,mid,l,r,val);
	update(2*node+1,mid+1,en,l,r,val);
}
long long query(int node,int st,int en,int idx)
{
	long long ans=tree[node];
	if (st!=en)
	{
		int mid=(st+en)/2;
		if (st<=idx && idx<=mid)
		ans=min(ans,query(2*node,st,mid,idx));
		else
		ans=min(ans,query(2*node+1,mid+1,en,idx));
	}
	return ans;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	while (m--)
	{
		int l,r,c;
		scanf("%d%d%d",&l,&r,&c);
		v[l].push_back({r,c});
	}
	for (int i=1;i<=4*n;i++)
	tree[i]=1e18;
	update(1,1,n,1,1,0);
	for (int i=1;i<=n;i++)
	{
		long long cur=query(1,1,n,i);
		for (auto p:v[i])
		update(1,1,n,i,p.first,cur+p.second);
	}
	long long ans=query(1,1,n,n);
	if (ans==1e18)
	ans=-1;
	printf("%lld",ans);
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    int N, M; cin >> N >> M;
    vector<ll> X(N), Y(N), Z(N); for(int i = 0; i < N; i++) cin >> X[i] >> Y[i] >> Z[i];
    ll Max = 0;
    for(int f1 = 0; f1 < 2; f1++){
        for(int f2 = 0; f2 < 2; f2++){
            for(int f3 = 0; f3 < 2; f3++){
                vector<ll> ABS(N);
                for(int i = 0; i < N; i++){
                    ll temp=0;
                    if(f1) temp += X[i]*(-1);
                    else temp += X[i];
                    if(f2) temp += Y[i]*(-1);
                    else temp += Y[i];
                    if(f3) temp += Z[i]*(-1);
                    else temp += Z[i];
                    ABS[i] = temp;
                }
                sort(ABS.rbegin(), ABS.rend());
                ll tempMax = 0;
                for(int i = 0; i < M; i++) tempMax += ABS[i];
                Max = max(Max, tempMax);
            }
        }
    }
    cout << Max << endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define met(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
int Next[10000];
void getNext(char str2[])
{
	int len = strlen(str2), k = -1, i = 0;
	Next[0] = -1;	
	while (i < len)
	{
		while (k != -1 && str2[i] != str2[k]) k = Next[k];
		Next[++i] = ++k;
	}
}
char str[10000];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	cin>>str;
	int len=strlen(str);
	int ans=0;
	for(int i=0;i<len;i++) 
	{
		getNext(str+i);		
		for(int j=i;j<=len;j++)
		{
			ans=max(ans,min(Next[j-i],(j-i)/2));
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
long long  m, x;
int n;
long long a[100000];
long long c1, c2, c3;
int main() {
	m = 1000000000;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
		if (a[i] == 0) {
			printf("0\n");
			return 0;
		}
	}
	x = 1;
	for (int i = 0; i < n; i++) {
		c1 = (x / m) * (a[i] / m);
		c2 = (x / m) * (a[i] % m) + (x % m) * (a[i] / m);
		c3 = (x % m) * (a[i] % m);
		c2 += c3 / m;
		c3 %= m;
		c1 += c2 / m;
		c2 %= m;
		if (c1 && (c2 || c3)) {
			printf("-1\n");
			return 0;
		}
		x *= a[i];
	}
	printf("%lld\n", x);
}

Measured memory_bytes: 2504
#include <stdio.h>
#include <stdlib.h>

int main() {
  int w, n, i;
  scanf("%d", &w);
  scanf("%d", &n);

  int *lots = (int *)malloc(sizeof(int) * w);
  for (i = 0; i < w; ++i) {
    lots[i] = i + 1;
  }
  for (i = 0; i < n; ++i) {
    int a, b;
    scanf("%d,%d", &a, &b);
    int tmp = lots[a - 1];
    lots[a - 1] = lots[b - 1];
    lots[b - 1] = tmp;
  }
  for (i = 0; i < w; ++i) {
    printf("%d\n", lots[i]);
  }
  free(lots);

  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<pair<int, int>> A(N);
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    A[i] = make_pair(a, i);
  }
  sort(A.begin(), A.end());
  for(int i=0; i<N; i++){
    cout << A[i].second+1 << " ";
  }
  return 0;
}

Measured memory_bytes: 1664
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if a <= b:
    total_a = a + v * t
    total_b = b + w * t
    if total_a >= total_b:
        print('YES')
    else:
        print('NO')
else:
    total_a = a - v * t
    total_b = b - w * t
    if total_a <= total_b:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9196
import scala.io.StdIn
import scala.annotation.tailrec

object Main{
  def main(args: Array[String]){
    StdIn.readLine()
    val line = StdIn.readLine().split(" ").toList.map(_.toInt)

    val res = sSort(List(), line, 0)
    println(res._1.mkString(" ") + "\n" + res._2)
  }

  @tailrec
  def sSort(sorted: List[Int], unsorted: List[Int], n: Int):(List[Int], Int)={
    if(unsorted.sorted == unsorted) ((sorted ::: unsorted), n)
    else if(unsorted.indexWhere(_ == unsorted.min) == 0) sSort(sorted :+ unsorted.head, unsorted.tail, n)
    else {
      val pos = unsorted.indexWhere(_ == unsorted.min)
      val swapped = unsorted.updated(0, unsorted(pos)).updated(pos, unsorted.head)

      sSort(sorted :+ unsorted.min, swapped.tail, n+1)
    }
  }
}

Measured memory_bytes: 45360