akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000001
#define VMAX 10000

int n;
int A[MAX];
int partition(int *,int,int);


int main(){
  int i, j=0,p,r;
  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&A[i]);
  
  j=partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i==j)printf(" [%d]",A[i]);
    else if(i==0)printf("%d",A[i]);
    else printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

int partition(int A[],int p,int r){
  int x=A[r],temp;
  int  i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  
  return i+1;
}



Measured memory_bytes: 2108
N = int(input())
ans = [0] * 10050

for x in range(1, 105):
    for y in range(1, 105):
        for z in range(1, 105):

            f = x**2 + y**2 + z**2 + x*y + y*z + z*x

            if f < 10050:
                ans[f-1] = ans[f-1] + 1 


for i in range(N):
    print(ans[i])

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

int main() {
 
  int N;
  cin >> N;
  
  int t, c, C;
  t = N, c = 0, C = 0;
  
  //10でNを割って商と余りを使ってf(N)を判定していくよ。
  
  while (t > 0) {
  
    c = t % 10;
    t /= 10;
    C += c;
    
    if (t == 0) { 
      break;
    }
  }
       //cout << t << " " << C + 1 << endl;
      if (N % C == 0){
        cout << "Yes" << endl;
      }
      else {
        cout << "No" << endl;
      }        
}


Measured memory_bytes: 256
#include<iostream>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int n, cnt[1000009], a[200009], ans;
int main()
{
    IO
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0; i<n; i++)
    {
        if(a[i]!=a[i+1])
        {
            int good=1;
            for(int j=1; j*j<=a[i]; j++)
                if(a[i]%j==0 && (cnt[j] || cnt[a[i]/j]))
                {
                    good=0;
                    break;
                }
            ans+=good;
        }
        cnt[a[i]]++;
    }
    cout<<ans;
}


Measured memory_bytes: 8220
#include<bits/stdc++.h>
using namespace std;
int a[2005][2005];
void solve(int l,int r,int dep){
	if(l==r) return;
	int mid=(l+r)>>1;
	for(int i=l;i<=mid;++i)
		for(int j=mid+1;j<=r;++j)
			a[i][j]=dep;
	solve(l,mid,dep+1);
	solve(mid+1,r,dep+1);
}
signed main(){
	int n;
	cin>>n;
	solve(1,n,1);
	for(int i=1;i<=n;++i,puts(""))
		for(int j=i+1;j<=n;++j,putchar(' '))
			cout<<a[i][j];
	return 0;
}

Measured memory_bytes: 6072
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
int main (){
    int n,k;
    cin >> n >>k;
    vector<int> l(n);
    for (int i = 0; i < n; i++){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    int lt=0;
    for (int i = 0; i < k; i++)
    {
        lt+=l[n-i-1];
    }
    cout << lt << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (1E9+7)
#define PI 3.1415926535897932384

std::ostream &operator<<(std::ostream &out, const vector<int> &tgt)
{
	string s;
	for (int i = 0; i<tgt.size(); i++) {
		s += (to_string(tgt[i]) + ((i != tgt.size() - 1) ? " " : ""));
	}
	out << s;
	return out;
}

int main() {
	string s;
	cin >> s;
	rep(i, s.size()) {
		cout << s[i];
		if (i == 3)cout << " ";
	}
	cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int price1 = sc.nextInt();
		int allYouDoPrice1 = sc.nextInt();
		int price2 = sc.nextInt();
		int allYouDoPrice2 = sc.nextInt();

		int total = 0;
		if (price1 < allYouDoPrice1) {
			total += price1;
		} else {
			total += allYouDoPrice1;
		}

		if (price2 < allYouDoPrice2) {
			total += price2;
		} else {
			total += allYouDoPrice2;
		}

		System.out.println(total);
	}
}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
DbgTimer D_t;
  #define TSTART() D_t.start()
  #define TSTOP() D_t.stop()
#else
  #define DUMP(i) 
  #define TSTART()
  #define TSTOP()  
#endif

#define GETTYPE(i) 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const int EPS = 1e-9;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y,z;
  while(cin >> x >> y >> z){
    TSTART();

    int ans = 0;
    while(x - y - z * 2 >= 0){
      ans++;
      x -= y + z;
    }
    cout << ans << endl;
    TSTOP();
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

#define REP(i, n) for(int i = 0;i < n;i++)

using namespace std;

const int INF = 100000000;

int main(){
  vector<int> task(3);
  cin >> task[0] >> task[1] >> task[2];
  vector<int> order{1,2,3};

  int min = 1000;
  do {
    int cost = 0;
    for (int i = 1; i < 3; i++) {
      cost += abs(task[order[i] - 1] - task[order[i-1] - 1]);
    }
    if (cost < min) {
      min = cost;
    }
  } while (next_permutation(order.begin(),order.end()));

  cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
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; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
/*next_combination*/
#define it vector<int>::iterator
bool next_combination(it first1,it last1,it first2,it last2){
    if((first1==last1)||(first2==last2))return false;
    it m1=last1,m2=last2;
    m2--;
    while(--m1!=first1&&!(*m1<*m2));
    bool result=(m1==first1)&&!(*first1<*m2);
    if(!result){
        while(first2!=m2&&!(*m1<*first2))first2++;
        first1=m1;
        iter_swap(first1,first2);
        first1++;first2++;
    }
    if((first1!=last1)&&(first2!=last2)){
        m1=last1;m2=first2;
        while((m1!=first1)&&(m2!=last2))iter_swap(--m1,m2++);
        reverse(first1,m1);
        reverse(first1,last1);
        reverse(m2,last2);
        reverse(first2,last2);
    }
    return !result;
}
bool next_combination(it first,it middle,it last){
    return next_combination (first , middle , middle , last );
}

int main(){
    int n,m;
    //  while(cin>>n>>m,n+m){
    cin>>n>>m;
    double ans=0;
    vector<vector<double>>v(n,vector<double>(3,0));
    rep(i,n){
        rep(j,3){
            cin>>v[i][j];
        }
    }
    vector<int>u(n);rep(i,n)u[i]=i;
    do{
        double temp=0;
        for(int i=0;i<m;i++){
            for(int j=i+1;j<m;j++){
                rep(k,3){
                    temp+=(v[u[i]][k]-v[u[j]][k])*(v[u[i]][k]-v[u[j]][k]);
                }
            }
        }
        //cout<<temp<<endl;
        cmax(ans,temp);
    }while (next_combination(u.begin(),u.begin()+m, u.end()));
    printf("%.10f\n",ans);
    // }
}

Measured memory_bytes: 3264
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <string>
#include <vector>
#include <limits>
#include <queue>
#include <cmath>
#include <map>
#include <set>

using namespace std;

typedef long long ll;

const ll INF = numeric_limits<ll>::max();

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

    vector<ll> weights(N);
    vector<ll> costs(N);
    ll costs_sum = 0;

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

    vector<vector<ll>> dp(costs_sum + 1, vector<ll>(N, INF));

    for(int i = 0; i < N; ++i)
        dp[0][i] = 0;

    dp[costs[0]][0] = weights[0];

    // dp[cost][i] --- minimum weight take cost using first i items

    for(ll cost = 1; cost < costs_sum + 1; ++cost) {
        for(int i = 0; i < N; ++i) {
            if(i - 1 >= 0)
                dp[cost][i] = dp[cost][i - 1];

            ll wo_cur = cost - costs[i];
            if(wo_cur < 0 || i - 1 < 0 || dp[wo_cur][i - 1] == INF)
                continue;

            dp[cost][i] = min(dp[cost][i],  dp[wo_cur][i - 1] + weights[i]);
        }
    }

    for(ll cost = costs_sum; cost >= 0; --cost) {
        ll val = *min_element(dp[cost].begin(), dp[cost].end());
        if(val <= W) {
            cout << cost << endl;
            break;
        }
    }

    return 0;
}


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

#define vary(type,name,size,init) vector< type> name(size,init)
#define rep(i,n) for(int i = 0; i < (int)(n);++i)
using ll = long long;

int main(){
  ll n,m,a;
  cin >> n >> m;
  vary(ll,t,m,0);
  vary(ll,s,n,0);
  rep(i,m) cin >> t[i];
  rep(i,m){
    rep(j,n){
      cin >> a;
      if(a == t[i])
        s[j]++;
      else
        s[t[i]-1]++;
    }
  }
  rep(i,n) cout << s[i] << endl;
  return 0;
}

Measured memory_bytes: 3112
//   PIGMEISTER™   //

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD (ll)1000000007
//#define MOD (ll)998244353
#define MAX 100005

int main()
{
    jaldi;
    
    string s;
    cin >> s;
    if (s == "ABC") s[1] = 'R';
    else s[1] = 'B';
    cout << s;
    
    return 0;
}


Measured memory_bytes: 3604
import copy
n=int(input())
a=list(map(int,input().split()))
ans=0
b=copy.copy(a)
a.sort()
cnt=1
num=[0]*n
for i in range(n-1):
	if a[i]==a[i+1]:
		cnt+=1
	else:
		num[a[i]-1]=cnt
		ans+=cnt*(cnt-1)//2
		cnt=1
ans+=cnt*(cnt-1)//2
num[a[-1]-1]+=cnt
for i in range(n):
	x=num[b[i]-1]
	if x<=1:
		print(ans)
	else:
		e=ans-x*(x-1)//2+(x-1)*(x-2)//2
		print(e)


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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

int a[200009];

int main() {
   int n, k;
   cin >> n >> k;

   for (int i = 0; i < n; i++ ){
      int x;
      cin >> x;
      a[x]++;
   }

   sort(a, a + 200001, greater<int>());

   int sum = 0;
   for (int i = 0; i < k; i++) {
      sum += a[i];
   }
   cout << n - sum << endl;

   return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	998244353

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

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

	if (s.length() <= k)
		printf("%s", s.c_str());
	else
		printf("%s...", s.substr(0, k).c_str());


	return 0;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define cans cout << ans << endl
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
typedef long long ll;


int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int ans = 0;
    int active = 0;
    rep(i,n){
        if(active >= h[i]){
            active = h[i];
        }
        else{
            ans += h[i]-active;
            active = h[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

works_rev = []
for loop in range(N):
    a, b = list(map(int, input().split()))
    works_rev.append((b, a))

works_rev.sort()
t = 0
for b, a in works_rev:
    t += a
    if t > b:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 29492
#include<bits/stdc++.h>
using namespace std;
//using p=pair<int,int>;
typedef long long ll;

 int main(){

 int n;
 cin>>n;

 for(int i=0;i<20;i++)
 {
    if(n < (1<<(i+1)) ){
        cout<<(1<<i)<<endl;
         break ;
      }
 }

 return 0;
 }


Measured memory_bytes: 256
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (Int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (Int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (Int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (Int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int Ceil(Int a, Int b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return Floor(a, b) + 1;
    }
}

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

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

Int digits(Int n) {
    return (Int)to_string(n).size();
}

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

    string n;
    cin >> n;

    Int a = 0, ro = n.size();
    for (Int i = 0; i < ro; i++) {
        a += (Int)(n[i] - '0');
    }

    if (a % 9 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define Rep(i,n) for(ll i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



int main(){

 	ll n, a, b;
 	cin >> n >> a >> b;
 	V<ll> x(n);
 	rep(i,n) cin >> x[i];

 	V<ll> dist(n-1);
 	rep(i,n) {
 		dist[i] = x[i+1] - x[i];
 		dist[i] *= a;
 	}

 	sort(all(dist));
 	int idx = 0;
 	ll ans = 0;
 	while(dist[idx] < b && idx < n-1) {
 		ans += dist[idx];
 		idx++;
 	}

 	ans += 1LL * (n-1 - idx) * b;
 	cout << ans << endl;
}

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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
	string s;
	cin>>s;
	int n=s.size();
	if(s[n-1]=='s'){
		cout<<(s+"es")<<endl;
	}
	else
		cout<<(s+"s")<<endl;	
	return;
}

int main()
{
	boost();
	
	int tc=1;
	//cin>>tc;
	while(tc--)
		solve();
	return 0;
}

Measured memory_bytes: 3664
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

a = int(input())
b = int(input())

for i in range(1,4):
    if i not in (a,b):
        print(i)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define N (2009)
#define MOD (1000000007)
using namespace std;

int n,k,ans,f[N][N],s[N];

int main()
{
	cin>>n>>k;
	f[0][n+1]=1; s[n+1]=1;
	for (int i=n; i>=1; --i) s[i]=s[i+1]+f[0][i];
	for (int i=1; i<=k-1; ++i)
	{
		for (int j=1; j<=n-i+1; ++j) f[i][j]=s[j];
		s[n+1]=f[i][n+1];
		for (int j=n; j>=1; --j) s[j]=(s[j+1]+f[i][j])%MOD;
	}
	for (int i=2; i<=n+1; ++i) (ans+=f[k-1][i])%=MOD;
	for (int i=1; i<=n-k-1; ++i) (ans*=2)%=MOD; 
	cout<<ans<<endl;
}

Measured memory_bytes: 15360
import sys
X=input()
n=len(X)
if n%2==0:
    print("No")
    sys.exit()
ans="No"
def check(s): 
    return s == s[::-1] 
ans="No"
if check(X):
    if check(X[0:int((n-1)/2)]):
        if check(X[int(((n+3)/2)-1):]):
            ans="Yes"
print(ans)

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*
 */

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

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

  if(a < b) rep(i, 0, b) cout << a;
  else rep(i, 0, a) cout << b;
  cout << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
typedef long long ll;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
 
const int N = 1e5;
ll A[2*N+5];
ll A_cnt[2*N+5];
 
int main(){

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

    int n;
    cin >> n;
    rep(i, n){
        cin >> A[i];
        A_cnt[A[i]]++;
    }
 
    ll sum = 0;
    rep(i, n+1){
        ll ai_cnt = A_cnt[i];
        sum += ( (ai_cnt * (ai_cnt-1)) / 2 );
    }
 
    rep(i, n){
        ll ai_cnt = A_cnt[A[i]];
        ll sum_i = sum - ( (ai_cnt * (ai_cnt-1)) / 2 ) + ( ((ai_cnt-1) * (ai_cnt-2)) / 2 );
        cout << sum_i << endl;
    }
 
    return 0;
}

Measured memory_bytes: 4736
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=10004;

int H,W,N;
int a[MAX_N];
int ans[101][101];

int main(){
  cin >> H >> W ;
  cin >> N ;
  rep(i,N)  cin >> a[i] ;
  int x=0,y=0;
  int now=0;
  rep(i,H*W){
    a[now]--;
    //cout << "now : " << now  << " (x,y)=" << x << "," << y << endl;
    ans[y][x]=now+1;
    if(y%2==0)  x++;
    else x--;
    if(x>=W){x--; y++;}
    if(x<0){x++; y++;}
    if(a[now]==0) now++;
  }
  rep(i,H){
    rep(j,W-1) cout << ans[i][j] << " " ;
    cout << ans[i][W-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 384
n=int(input())
t,a=list(map(int,input().split()))
h=list(map(int,input().split()))
tmp=0
s=10000
num=10000
for i in range(n):
    t_average=t-h[i]*0.006
    tmp=abs(a-t_average)
    if tmp<=s:
        s=tmp
        num=i+1
        tmp=0
print(num)

Measured memory_bytes: 3064
#![allow(unused_imports)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

//
// Macro debug!
//

#[cfg(debug_assertions)]
include!{"./procon/debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

//
// Macro input!
//

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//
// IteratorExt
//

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}





fn main() {
    input! {
        n: usize,
        xs: [i64; n],
    }
    let mut xs = xs;
    xs.sort();
    let upper = xs.pop().unwrap();
    let lower = xs.remove(0);

    let mut ps = vec![upper];
    let mut ns = vec![lower];

    for x in xs {
        if 0 <= x {
            ps.push(x);
        } else {
            ns.push(x);
        }
    }

    let ans = ps.iter().fold(0, |a, x| a + *x) - ns.iter().fold(0, |a, x| a + *x);
    println!("{}", ans);

    loop {
        if ps.len() + ns.len() == 1 {
            break;
        }

        if ps.len() <= ns.len() {
            // Consume negative.
            let x = ps.pop().unwrap();
            let y = ns.pop().unwrap();
            println!("{} {}", x, y);
            ps.push(x - y);
        } else {
            // Consume positive.
            let x = ns.pop().unwrap();
            let y = ps.pop().unwrap();
            println!("{} {}", x, y);
            ns.push(x - y);
        }
    }
}


Measured memory_bytes: 9980
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rounding
{
    class Program
    {
        /// <summary>
        ///   The main entry point for the application
        /// </summary>
        [STAThread]
        public static void Main(string[] args)
        {
            // var a = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            var x = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            var a = int.Parse(str[1]);
            // Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            // Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
            if(x < a) {
                Console.Write(0);
            }  else {
                Console.Write(10);
            }
        }
    }
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int a = ri(), b = ri();
	std::string as, bs;
	for (int i = 0; i < b; i++) as += std::to_string(a);
	for (int i = 0; i < a; i++) bs += std::to_string(b);
	std::cout << std::min(as, bs) << std::endl;
	return 0;
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;

int dy[4]={1, 0, -1, 0};
int dx[4]={0, 1, 0, -1};

int32_t main(){
    int n, m;
    cin >> n >> m;
    vector<int> v[n];
    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        v[a].pb(b);
        v[b].pb(a);
    }

    queue<int> q;
    REP(i, v[0].size()){
        q.push(v[0][i]);
    }

    while(!q.empty()){
        int u=q.front();
        q.pop();

        REP(i, v[u].size()){
            if(v[u][i]==n-1){
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 13544
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll r;
  cin >> r;
  
  if (r < 1200)
    cout << "ABC" << endl;
  else if (r < 2800)
    cout << "ARC" << endl;
  else
    cout << "AGC" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; i++)
const ll N = 1e3 + 200;
const ll INF = 0x3f3f3f;
const ll Mode = 1e9 + 7;
int main(){
	ll n;
	vector<ll> vct(n);
	
	ll a,b;
	cin>>a>>b;
	if((a+b) % 2 == 0)
	cout<<(a+b)/2<<endl;
	else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	
	return 0;
}



Measured memory_bytes: 256
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    bool ok;
    if(w - v >= 0){
        ok = false;
    } else {
        if((double)abs(a - b) / abs(w - v) > (double)t){
            ok = false;
        } else {
            ok = true;
        }
    }

    if(ok){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


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


int main() {
    string s;
    cin >> s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<=s.size()-i+1;j++){
            string t=s.substr(i,j);
            bool flg=true;
            for(int k=0;k<t.size();k++){
                if(t[k]!='A'&&t[k]!='C'&&t[k]!='G'&&t[k]!='T'){
                    flg=false;
                }
            }
            if(flg){
                int num=t.size();
                ans=max(ans,num);
            }
        }
    }
    cout<<ans<<endl;

}

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

long long INF = 1000000000000000000;

int main() {
	int N;
	long long MUL = 1;
	cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) {
		if (A[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 0; i < N; i++) {
		if (MUL > INF / A[i]) {
			cout << -1 << endl;
			return 0;
		}
		MUL *= A[i];
	}
	if (MUL > INF) cout << -1 << endl;
	else cout << MUL << endl;
}

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

int main() {
  int n;
  cin >> n;
  
  vector<string> s(10);
  s.at(0) = "pon";
  s.at(1) = "pon";
  s.at(2) = "hon";
  s.at(3) = "bon";
  s.at(4) = "hon";
  s.at(5) = "hon";
  s.at(6) = "pon";
  s.at(7) = "hon";
  s.at(8) = "pon";
  s.at(9) = "hon";
  
  cout << s.at(n%10) << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n - 1); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
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 dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = (1LL << 60);
int n, m;

struct Edge {
  int from, to;
  ll cost;
};

vector<Edge> v;
ll dist[2200];
bool negative[2200];

void bellman_ford(int start){
  rep(i, n) dist[i] = INF;
  dist[start] = 0;
  for (int i = 0; i < n-1; i++){
    for (int j = 0; j < v.size(); j++){
      Edge e = v[j];
      if(dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost){
        dist[e.to] = dist[e.from] + e.cost;
      }
    }
  }
  return;
}

void negative_loop(){
  rep(i, n) negative[i] = false;
  rep(i, n){
    for (int j = 0; j < v.size(); j++){
      Edge e = v[j];
      if(dist[e.to] != INF && dist[e.to] > dist[e.from] + e.cost){
        dist[e.to] = dist[e.from] + e.cost;
        negative[e.to] = true;
      }
      if(negative[e.from])negative[e.to] = true;
    }
  }
}

int main() {
  cin >> n >> m;
  rep(i, m){
    int a, b;
    ll c;
    cin >> a >> b >> c;
    a--, b--;
    v.push_back((Edge{a, b, -c}));
  }
  bellman_ford(0);
  ll ans = -dist[n-1];
  negative_loop();
  if(negative[n-1]){
    cout << "inf" << endl;
  }else{
    cout << ans << endl;
  }
}

Measured memory_bytes: 3708
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, Z, W;
        cin >> N >> Z >> W;

        vector<Int> A(N + 2);
//        A[0] = Z;
//        A[1] = W;
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }

        // dp[2][][N] : プレイヤー, 持っているカード, トップ
        // 先行 -> 最大化、 後攻 -> 最小化
        vector<vector<vector<Int>>> dp(2, vector<vector<Int>>(N + 2, vector<Int>(N + 2, -1)));;

        // 最後のカードはどちらかのプレイヤーが使用する。
        //



        // 山札のてっぺんのカードがlということにする
        // maximize
        auto dfsX = [&](auto self, auto other, int p, int q) -> Int {

            if (q == N - 1) {
                if (p == -1) {
                    return abs(A[N - 1] - W);
                }
                return abs(A[N - 1] - A[p]);
            }

            if (p != -1 && dp[0][p][q] != -1) return dp[0][p][q];

            Int ret = self(self, other, p, q + 1);
            chmax(ret, other(other, self, q, q + 1));

            if (p == -1) return ret;
            return dp[0][p][q] = ret;
        };

        // minimize
        auto dfsY = [&](auto self, auto other, int p, int q) -> Int {
            if (q == N - 1) {
                if (p == -1) {
                    exit(-1);
                    return abs(A[N - 1] - W);
                }
                return abs(A[N - 1] - A[p]);
            }

            if (p != -1 && dp[1][p][q] != -1) return dp[1][p][q];

            Int ret = self(self, other, p, q + 1);
            chmin(ret, other(other, self, q, q + 1));

            if (p == -1) return ret;
            return dp[1][p][q] = ret;
        };


        Int ans = dfsX(dfsX, dfsY, -1, 0);
        cout << ans << endl;


    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 94720
S = input()
Q = int(input())

jun = 1
front = []
back = []

for _ in range(Q):
    inp = input().split()
    if len(inp) == 1:
        jun = 1 - jun
    else:
        _, F, C = inp
        if jun and F == "1":
            front.append(C)
        elif jun and F == "2":
            back.append(C)
        elif not jun and F == "1":
            back.append(C)
        else:
            front.append(C)

front = front[::-1]
ans = "".join(front) + S + "".join(back)
if not jun:
    ans = ans[::-1]

print(ans)


Measured memory_bytes: 6144
#include <stdio.h>

	int N,L;
	int a[100000];
	int i,j,ans;


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

	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	ans = N;
	for(i=0;i<N-1;i++){
		if(a[i]+a[i+1]>=L){
			ans = i;
		}
	}

	if(ans == N){
		printf("Impossible\n");
	}else{
		printf("Possible\n");
		for(i=0;i<ans;i++){
			printf("%d\n",i+1);
		}
		for(i=N-2;i>=ans;i--){
			printf("%d\n",i+1);
		}
	}
	return 0;

}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;

int main()
{
    string s,t,tmp;
    cin>>s>>t;
    for(int i=0;i<s.size();i++){
        if(s==t){
            cout<<"Yes";
            return 0;
        }
        tmp=s[s.size()-1];
        s.erase(s.size()-1);
        s=tmp+s;
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

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

		int n = stdIn.nextInt();
		int q = stdIn.nextInt();
        String [] a = new String[n];
        int [] b = new int[n];
        String [] aa = new String[n];
        int [] bb = new int[n];

        for(int i = 0; i < n; i++){
        	a[i] = stdIn.next();
        	b[i] = stdIn.nextInt();
        }
        stdIn.close();

    	int index =0;
    	int basictime=0;
        int ansIndex=0;
        while(true) {
        	if(b[index]==0) {
        		index++;
            	if(index==n){
            		//初期値へ
            		index=0;
            	}
        		continue;
        	}
        	int remaining =b[index]-q;
        	if(remaining >0){
        		b[index] = remaining;
        		basictime+= q;
        	} else {
        		b[index] = 0;
        		aa[ansIndex]=a[index];
        		bb[ansIndex]=q + basictime + remaining;
        		ansIndex++;
        		basictime+= q + remaining;
        		//全チェックし、全てMapにあれば終了
        		if(ansIndex==n){
        			break;
        		}
        	}
        	index++;
        	if(index==n){
        		//初期値へ
        		index=0;
        	}
        }
        for(int i = 0; i < ansIndex; i++){
        	System.out.println(aa[i] + " " + bb[i]);
        }
    }
}



Measured memory_bytes: 76508
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

long long int gcd(long long int a, long long int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main(void){
    long long int n;
    vector<long long int> a;

    cin >> n;

    for(int i = 0; i < n; i++){
        int _a;
        cin >> _a;
        a.push_back(_a);
    }

    sort(a.begin(), a.end());

    int flag = 1;
    while(flag){
        flag = 0;
        for(int i = 1; i < n; i++){
           if(a[i] % a[0] != 0){
                a[i] %= a[0];
                flag = 1;
            }
        }
        sort(a.begin(), a.end());
    }

    cout << a[0] << endl;

    return 0;
}

Measured memory_bytes: 1400
import sys
N, Y = map(int, input().split())
Y = Y//1000
x = 0
while Y-N-9*x >= 0:
    if (Y-N-9*x)%4 == 0 and (Y-N-9*x)//4 >=0 and x+(Y-N-9*x)//4 <= N:
        print(x, (Y-N-9*x)//4, N-(Y-N-9*x)//4-x)
        sys.exit()
    x += 1
print(-1, -1, -1)

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long Int;
typedef pair<int, int> P;
Int h, w, k;
string field[1100000];
vector<vector<Int>> dist;

Int dx[] = {0, 1, 0, -1};
Int dy[] = {1, 0, -1, 0};

void bfs(int sx, int sy)
{
    queue<P> q;
    dist[sx][sy] = 0;
    q.push(P(sx, sy));
    while (!q.empty()) {
        P from = q.front();
        q.pop();
        int fx = from.first, fy = from.second;
        for (int d = 0; d < 4; d++) {
            for (int j = 1; j <= k; j++) {
                int tx = fx + dx[d] * j;
                int ty = fy + dy[d] * j;
                if (tx < 0 || tx >= h || ty < 0 || ty >= w)
                    break;
                if (field[tx][ty] == '@')
                    break;
                if (dist[tx][ty] != -1 && dist[tx][ty] <= dist[fx][fy])
                    break;
                if (dist[tx][ty] != -1)
                    continue;
                dist[tx][ty] = dist[fx][fy] + 1;
                q.push(P(tx, ty));
            }
        }
    }
}

int main()
{
    Int sx, sy, gx, gy;
    cin >> h >> w >> k;
    dist = vector<vector<Int>>(h, vector<Int>(w, -1));
    cin >> sx >> sy >> gx >> gy;
    sx--, sy--, gx--, gy--;
    for (int i = 0; i < h; i++) {
        cin >> field[i];
    }

    bfs(sx, sy);
    cout << dist[gx][gy] << endl;
  return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    vector<lint> a(n), b(n);
    set<lint> st;
    rep(i, n){
        cin >> a[i];
        st.insert(a[i]);
    }
    rep(i, n){
        cin >> b[i];
        st.insert(b[i]);
    }

    SORT(a);
    SORT(b);

    lint ans = 1LL, pc = 0LL, den = 0LL;
    for(auto x : st){
        auto it1 = lower_bound(a.begin(), a.end() - 1, x);
        auto it2 = lower_bound(b.begin(), b.end() - 1, x);
        if(*it1 == x){
            if(den == 0LL){
                ++pc;
            }else{
                ans *= den;
                ans %= MOD;
                --den;
            }
        }else if(*it2 == x){
            if(pc == 0LL){
                ++den;
            }else{
                ans *= pc;
                ans %= MOD;
                --pc;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11264
mod=10**9+7

table=[[0 for i in range(401)] for j in range(401)]
for i in range(401):
    S=0
    for j in range(1,401):
        S+=pow(j,i,mod)
        S%=mod
        table[i][j]=S

N,C=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))


dp=[[0 for i in range(C+1)] for j in range(N)]

for i in range(C+1):
    dp[0][i]=table[i][B[0]]-table[i][A[0]-1]
    dp[0][i]%=mod

for i in range(1,N):
    for j in range(C+1):
        dp[i][j]=sum(dp[i-1][j-k]*(table[k][B[i]]-table[k][A[i]-1]) for k in range(j+1))
        dp[i][j]%=mod

print(dp[N-1][C])

Measured memory_bytes: 61404
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n;
    cin >> n;
    map<string, int> m;
    int count = 0;
    for (int i = 0; i < n; i++)
    {
        string a;
        cin >> a;
        if (m[a] == 0)
        {
            count++;
            m[a]++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 19180
s = list(str(input()))
k = int(input())

s_pre = s[0]
cnt = 1
s2 = []
for x in s[1:]:
    if s_pre == x:
        cnt += 1
    else:
        s2 += [cnt]
        cnt = 1
        s_pre = x
s2 += [cnt]

def div2(x):
    return x//2

if len(s2) == 1:
    print((s2[0]*k)//2)

elif s[0] == s[-1]:
    print(s2[0]//2 + s2[-1]//2 + (s2[0]+s2[-1])//2*(k-1) + sum(map(div2, s2[1:-1]))*k)

else:
    print(sum(map(div2, s2))*k)


Measured memory_bytes: 38256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    int N; cin >> N;
    
    if (N == 1) {
        cout << "Hello World" << endl;
    } else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new A().doIt();
//		new B().doIt();
//		new C().doIt();
//		new D().doIt();
	}
	class A{
		void doIt() {
			int N = sc.nextInt();
			int sum = 0;
			for(int i = 1;i <= N;i++) {
				sum = sum + i;
			}
			System.out.println(sum);
		}
	}
	class B{
	}
	class C{
	}
	class D{
	}
}


Measured memory_bytes: 21844
l,r = map(int,raw_input().split())

if r-l >= 2019:
	best = 0
else:
	lm = l%2019
	rm = r%2019
	if r > l:
		a = range(lm,rm+1)
		best = 2019
		for i in xrange(len(a)-1):
			for j in xrange(i+1,len(a)):
				temp = (a[i]*a[j])%2019
				if temp < best:
					best = temp
	else:
		best = 0
print best

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
int main() {
  int W,a,b;
  cin >> W >> a >> b;
  int check = (max(a,b) - min(a,b)) - W;
  int ans = 0;
  if (check < 0) {
    ans = 0;
  }
  else {
    ans = check;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int l=0, r= s.size()-1;
	int cnt =0;
	while(l<r){
		while(s[l] == 'R' && l <r) 
			l++;
		while(s[r] == 'W' && l <r)
			r--;
		if(s[r] == 'R' && s[l] == 'W'){
			cnt++;
			r--, l++;
		}
	}
	cout <<cnt << endl;
	return 0;
}

Measured memory_bytes: 3704