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

using namespace std;

namespace mp = boost::multiprecision;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

signed main()
{
  int N;
  int H, W;
  cin >> N;
  cin >> H >> W;
  cout << (N-H+1) * (N-W+1) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct  node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node *Node;

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL) x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL) x = x->right;
  return x;
}

Node treeSearch(Node x,int k){
  while(x != NIL && k != x->key){
    if(k < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  return x;
}

Node treeSuccessor(Node x){
  Node y;

  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;

  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }

  return y;
}

void treeDelete(Node x){
  Node y,z;

  if(x->left == NIL || x->right == NIL){
    y = x;
  }
  else{
    y = treeSuccessor(x);
  }

  if(y->left != NIL){
    z = y->left;
  }
  else{
    z = y->right;
  }

  if(z != NIL) z->parent = y->parent;

  if(y->parent == NIL){
    root = z;
  }
  else if(y == y->parent->left){
    y->parent->left = z;
  }
  else{
    y->parent->right = z;
  }

  if(y != x){
    x->key = y->key;
  }

  free(y);
}

void insert(int k){
  Node x = root;
  Node y = NIL;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;

    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key){
    y->left = z;
  }
  else{
    y->right = z;
  }
}

void inorder(Node x){
  if(x == NIL) return;
  inorder(x->left);
  printf(" %d",x->key);
  inorder(x->right);
}

void preorder(Node x){
  if(x == NIL) return;
  printf(" %d",x->key);
  preorder(x->left);
  preorder(x->right);
}

int main(){
  int n,i,x;
  char com[20];
  Node t,minn,maxn;

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%s",com);

    if(com[0] == 'f'){
      scanf("%d",&x);
      
      Node t = treeSearch(root,x);

      if(com[5] == 'i'){
	Node maxn = treeMinimum(t);
	printf("%d\n",minn->key);
      }
      else if(com[5] == 'a'){
	Node maxn = treeMaximum(t);
	printf("%d\n",maxn->key);
      }
      else{
	if(t != NIL){
	  printf("yes\n");
	}
	else{
	  printf("no\n");
	}
      }
    }
    else if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
    else if(com[0] == 'd'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }

  return 0;
}



Measured memory_bytes: 20448
#include <stdio.h>
using namespace std;
int main(void){
    // Your code here!
int S,h,m,s;
scanf("%d",&S);
h=S/3600;
S=S%3600;
m=S/60;
s=S%60;
printf("%d:%d:%d\n",h,m,s);
    
}




Measured memory_bytes: 2680
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;

#define inf 1e9 + 7

/* 
typedef struct Node {
  int id;
  int score;
  Node *right;
  Node *left;
};
*/

vector<vector<int>> grid(5010, vector<int>(5, 0));
vector<int> ma(5, 0);

void check(int start , int end){
  // endは含まれない

  for(int i = end - 1; i >= start; i--){
    bool vanish = true;
    for(int j = 0; j < 5; j++){
      if(grid[i][j] != 1){
        vanish = false;
        break;
      }
    }
    if(vanish){
      //cout << "消す " << i << "行目" << endl;
      // 消す
      for(int j = 0; j < 5; j++){
        grid[i][j] = inf;
        // 最大値更新

        if(ma[j] == i + 1){

          // 下の1まで下がる
          for(int k = i - 1; k >= 0; k--){
            if(grid[k][j] == 1){
              ma[j] = k + 1;
              break;
            }
            if(k == 0) ma[j] = 0; 
          }

        }

      }

    }
  }
}

int main(){

  while(1){
    int n;
    cin >> n;
    if(n == 0) break;

    // 初期化
    for(int i = 0; i < 5010; i++){
      for(int j = 0; j < 5; j++){
        grid[i][j] = 0;
      }
    }
    for(int j = 0; j < 5; j++) ma[j] = 0;

    vector<int> d(n), p(n), q(n);
    for(int i = 0; i < n; i++) cin >> d[i] >> p[i] >> q[i];

    for(int i = 0; i < n; i++){
      if(d[i] == 1){ // 横
        int ster = 0;
        for(int j = q[i] - 1; j < q[i] - 1 + p[i]; j++){
          ster = max(ster,ma[j]);
        }
        // sterのとこにおく
        while(grid[ster][q[i] - 1] == inf){
          ster++;
        }
        for(int j = q[i] - 1; j < q[i] - 1 + p[i]; j++){
          grid[ster][j] = 1;
          ma[j] = ster + 1;
        }
        check(ster, ster + 1);
      }
      else{ // 縦
        int ster = ma[q[i] - 1];
        while(grid[ster][q[i] - 1] == inf) ster++;
        int cnt = 0;
        for(int j = 0; j < p[i]; j++){
          if(grid[ster+j+cnt][q[i] - 1] == inf){
            cnt++;
            j--;
            continue;
          }
          grid[ster + cnt + j][q[i] - 1] = 1;
        }
        ma[q[i] - 1] = ster + p[i] + cnt;
        check(ma[q[i] - 1] - p[i] - ster - cnt, ma[q[i] - 1] + cnt);
      }
    }

    int ans = 0;
    for(int i = 5010 - 1; i >= 0; i--){
      for(int j = 0; j < 5; j++){
        //cout << grid[i][j] << " ";
        if(grid[i][j] == 1) ans++;
      }
      //cout << endl;
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;
 
// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define debug(stuff) cout << #stuff << ": " << stuff <<endl
#define debugc(stuff) cout << #stuff << ": "; for(auto x: stuff) cout << x << " "; cout << endl;
// 
 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define all(v) v.begin(), v.end() 
 
#define print(stuff) cout << stuff << endl
#define printc(stuff) for(auto x: stuff) cout << x << " "; cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return 
 
 
#define ll long long
#define ld long double
#define fi first
#define endl '\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
 
#define vl vector<ll> 
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll> 
#define pq priority_queue<ll>
 
// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;
 
#define inf (long long int) 1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5+5
#define N (1ll<<10)

void solve(){
    ll n;
    cin>>n;
    set<string> s;
    loop(i,0,n){
        string t;
        cin>>t;
        // trace(t);
        s.insert(t);
    }
    print(s.size());
}
 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        start_routine();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
        
    #ifndef ONLINE_JUDGE
        end_routine();
    #endif
}


Measured memory_bytes: 19104
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using static AtCoder.Program;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC134().SolveA(new ConsoleInput(Console.In, ' '));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }

    }
  class ABC134
    {
        public void SolveA(ConsoleInput cin)
        {
            var r = cin.ReadInt;
            WriteLine(3 * Pow(r, 2));
            ReadLine();
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+10;
int a[maxn],n,r[maxn],c[maxn],f[maxn],d[maxn];
ll k;
bool vis[maxn];
int ask()
{
    int l=1,cost=0;
    while(1)
    {
        cost+=c[l];
        l=r[l];
        if(l==n)
            return cost+1;
        l++;
        if(l==n+1)
            l=1,cost++;
    }
    return cost+1;
}
bool is[maxn];
void print(int i)
{
    stack<int>P,Q;
    for( ;i<=n;i++)
    {
        if(!is[a[i]])
        {
            P.push(a[i]);
            is[a[i]]=1;
        }
        else
        {
            while(1)
            {
                int v=P.top();
                is[v]=0;
                P.pop();
                if(v==a[i])
                    break;
            }
        }
    }
    while(!P.empty())
    {
        Q.push(P.top());
        P.pop();
    }
    while(!Q.empty())
    {
        printf("%d ",Q.top());
        Q.pop();
    }
}
void work(int K)
{
    int l=1,cost=0;
    while(1)
    {
        if(cost+c[l]>=k)
        {
            print(l);
            return;
        }
        cost+=c[l];
        l=r[l];
        l++;
        if(l==n+1)
        {
            if(cost+1>=k)
            {
                printf("\n");
                return;
            }
            l=1,cost++;
        }
    }
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(vis[a[i]]==0)
        {
            vis[a[i]]=1;
            f[a[i]]=i;
        }
    }
    for(int i=n;i>=1;i--)
    {
        if(d[a[i]])
        {
            r[i]=d[a[i]];
        }
        else
        {
            r[i]=f[a[i]];
            c[i]=1;
        }
        d[a[i]]=i;
    }
    int mod=ask();
    k%=mod;
    //if(k==0)
        //printf("\n");
    //else
    {
        work(k);
    }
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N;
  vector<int> T(N);
  for (int i = 0; i < N; i++) {cin >> T.at(i);}
  cin >> M;
  for (int i = 0; i < M; i++) {
    vector<int> t(N);
    for (int j = 0; j < N; j++) {t.at(j) = T.at(j);}
    int P, X, Y = 0;
    cin >> P >> X;
    t.at(P - 1) = X;
    for (int j = 0; j < N; j++) {Y += t.at(j);}
    cout << Y << endl;
  }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()


using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool upd_min (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool upd_max (T &a, T b) {return a < b ? (a = b, true) : false; }


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    int k;
    cin >> k >> s;
    int n = (int)s.length();
    if (n <= k) {
        cout << s << '\n';
    }
    else {
        cout << s.substr(0, k) << "...\n";
    }
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

    vector<P> v;
    rep(i, n) {
        int x, l;
        cin >> x >> l;
        v.push_back({x+l, x-l});
    }

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

    int INF = 1001001001;
    int ans = 0, t = -INF;
    rep(i, n) {
        if(t <= v[i].second) {
            ans++;
            t = v[i].first;
        }
    } 

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

Measured memory_bytes: 1400
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int D; cin >> D;
  vector<LL> c(26); cin >> c;
  vector<LL> last(26, 0);
  vector<vector<LL>> s(D, vector<LL>(26, 0));
  for (int i = 0; i < D; ++i) cin >> s[i];
  vector<int> t(D); cin >> t;

  LL sum = accumulate(c.begin(), c.end(), 0LL);
  LL v = 0;
  for (int d = 1; d <= D; ++d) {
    int i = d - 1;
    int j = t[i] - 1;
    last[j] = d;
    v += s[i][j];
    for (int k = 0; k < 26; ++k) {
      v -= c[k] * (d - last[k]);
    }
    cout << v << endl;
  }
}


Measured memory_bytes: 3724
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    long N = sc.nextInt();
    long K = sc.nextInt();
    long ans = 0;
    if(K == 0) ans = N * N;
    else{
      for(int b=1; b<=N; b++){
        if(b <= K) continue;
        ans += N / b * (b-K);
        long tmp = N % b - K + 1;
        if(tmp > 0) ans += tmp;
      }
    }
    out.println(ans);
  }

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

Measured memory_bytes: 21332
#include <stdio.h>
#include <string.h>

typedef struct dice {

	int num[6];

}dice;

void mov(struct dice *d, char c[], int len);

int main(void) {

	dice dice1;
	int i = 0;
	char c[101];
	int len;

	for(i = 0; i < 6; i++)
		dice1.num[i] = 0;

	for (i = 0; i < 6; i++)
		scanf("%d", &dice1.num[i]);

	scanf("%s", c);

	len = strlen(c);

	mov(&dice1, c, len);

	printf("%d\n", dice1.num[0]);

	return 0;
}

void mov(struct dice *d, char c[], int len) {
	int tmp = 0;
	int i = 0;

	for (i = 0; i < len; i++) {
		if ('E' == c[i]) {
			tmp = (*d).num[0];
			(*d).num[0] = (*d).num[3];
			(*d).num[3] = (*d).num[5];
			(*d).num[5] = (*d).num[2];
			(*d).num[2] = tmp;
		}
		else if ('N' == c[i]) {
			tmp = (*d).num[0];
			(*d).num[0] = (*d).num[1];
			(*d).num[1] = (*d).num[5];
			(*d).num[5] = (*d).num[4];
			(*d).num[4] = tmp;
		}
		else if ('S' == c[i]) {
			tmp = (*d).num[0];
			(*d).num[0] = (*d).num[4];
			(*d).num[4] = (*d).num[5];
			(*d).num[5] = (*d).num[1];
			(*d).num[1] = tmp;
		}
		else if ('W' == c[i]) {
			tmp = (*d).num[0];
			(*d).num[0] = (*d).num[2];
			(*d).num[2] = (*d).num[5];
			(*d).num[5] = (*d).num[3];
			(*d).num[3] = tmp;
		}
	}
}

Measured memory_bytes: 596
# coding: utf-8
inputs = STDIN.gets.chomp.split(' ').map(&:to_i)

# inputs[0] = H
# inputs[1] = W

cell = Array.new
inputs[0].times do |i|
  cell[i] = STDIN.gets.chomp.split('')
end

c1 = Array.new
# 行の削除
cell.each do |c|
  c1 << c if c.include?('#')
end

# 列
del_idx = []
inputs[1].times do |w|
  flag = true
  c1.length.times do |h|
    flag =false if c1[h][w] == '#'
  end
  del_idx << w if flag
end

del_idx.each do |i|
  c1.each do |c|
    c.delete_at i
  end
  del_idx.map!{|n| n -= 1}
end

c1.each do |c|
  puts c.join('')
end

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

int p[200010], sz[200010];

int find(int x) {
    return x == p[x] ? x : p[x] = find(p[x]);
}

void merge(int x, int y) {
    int px = find(x), py = find(y);
    if(px == py) {
        return ;
    }
    p[px] = py;
    sz[py] += sz[px];
}

void MAIN() {
    int n;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++ i) {
        p[i] = i;
        sz[i] = 1;
    }
    std::vector<int> idx(n + 1), arr(n + 1);
    for(int i = 0; i < n; ++ i) {
        scanf("%d", &arr[i + 1]);
        idx[arr[i + 1]] = i + 1;
    }
    long long ans = 0;
    for(int i = n; i > 0; -- i) {
        int l = 1, r = 1;
        if(idx[i] > 1 && arr[idx[i] - 1] > i) {
            l += sz[find(arr[idx[i] - 1])];
            merge(arr[idx[i] - 1], i);
        }
        if(idx[i] < n && arr[idx[i] + 1] > i) {
            r += sz[find(arr[idx[i] + 1])];
            merge(i, arr[idx[i] + 1]);
        }
        ans += l * 1ll * r * 1ll * i;
    }
    printf("%lld\n", ans);
}

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


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <cmath>
#include <cstdio>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()

using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

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

	priority_queue<int> q;

	rep(i, 5){
		int x;
		cin >> x;
		q.push(x);
	}
	rep(i, n-5){
		int x;
		cin >> x;
		if(q.top() > x){
			q.push(x);
			q.pop();
		}
	}

	vector<int> a;
	while(!q.empty()){
		a.push_back(q.top());
		q.pop();
	}

	vector<int> b;
	char buf[20];
	rep(i, a.size()){
		rep(j, a.size()){
			if(i == j) continue;
			sprintf(buf, "%d%d", a[i], a[j]);
			b.push_back(atoi(buf));
		}
	}
	sort(all(b));
	cout << b[2] << endl;


    return 0;
}

Measured memory_bytes: 1264
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int num_query;
	ll command,x;

	scanf("%d",&num_query);

	ll p = 1,q = 0;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%lld %lld",&command,&x);

		switch(command){
		case 1:

			p *= x;
			q *= x;
			break;

		case 2:

			q += x;

			break;
		case 3:

			q -= x;

			break;
		}
	}

	printf("%lld %lld\n",-q,p);

	return 0;
}



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

int main(){
   int N,count;
   string S;
   cin>>N>>S;
   count=0;
  
   for(int i=0;i<N-2;i++){
      if(S.at(i)=='A'&&S.at(i+1)=='B'&&S.at(i+2)=='C'){
         count++;
       }
   }
   cout<<count<<endl;
}


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

using ld = long double;
const ld eps = 1e-10, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;
class Line {
public:
	Point a, b;
};
ld dot(Point a, Point b) {
	return real(conj(a) * b);
}

ld cross(Point a, Point b) {
	return imag(conj(a) * b);
}

int ccw(Point a, Point b, Point c) {
	b -= a, c -= a;
	if (cross(b, c) > eps) return 1;	// a,b,c counter-clockwise
	if (cross(b, c) < -eps) return -1;	// a,b,c clockwise
	if (dot(b, c) < 0) return 2;		// c,a,b on a line
	if (norm(b) < norm(c)) return -2;	// a,b,c on a line
	return 0;							// a,c,b on a line
}

bool isis_ll(Line l, Line m) {
	return abs(cross(l.b - l.a, m.b - m.a)) > eps;
}

bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}

bool isis_lp(Line l, Point p) {
	return abs(cross(l.b - p, l.a - p)) < eps;
}

bool isis_sp(Line s, Point p) {
	return abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps;
}

Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

Point is_ll(Line s, Line t) {
	Point sv = s.b - s.a, tv = t.b - t.a;
	assert(cross(sv, tv) != 0);
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

bool isis_ss(Line s, Line t) {
	if (isis_ll(s, t)) return isis_ls(s, t) && isis_ls(t, s);
	return isis_sp(s, t.a) || isis_sp(s, t.b) || isis_sp(t, s.a);
}

int main()
{
	int T;
	cin >> T;
	while (T--) {
		ld xa, ya, xb, yb;
		cin >> xa >> ya >> xb >> yb;
		Point a(xa, ya), b(xb, yb);
		Line ab = { a, b };
		int n;
		cin >> n;
		vector<pair<ld, int>> ll;
		for (int i = 0; i < n; i++) {
			ld xs, ys, xt, yt;
			cin >> xs >> ys >> xt >> yt;
			Point s(xs, ys), t(xt, yt);
			Line st = { s, t };
			int o, l;
			cin >> o >> l;
			if (!isis_ss(ab, st)) continue;
			ll.emplace_back(abs(is_ll(ab, st) - a), o ^ l);
		}
		sort(ll.begin(), ll.end());
		int res = 0;
		for (int i = 1; i < (int)ll.size(); i++) {
			if (ll[i - 1].second != ll[i].second) res++;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3220
let n, k = stdin.ReadLine().Split() |> fun [| n; k|] -> int n, int64 k

// 配列のインデックス表記を使って辞書を作る
let a = stdin.ReadLine().Split() |> Array.map int |> Array.append [|0|] 

let move (max:int64) =
    let rec move (i, count, mementoIntCount:Map<int,int64 >) = 
        if count >= max then i, count,mementoIntCount
        elif Map.containsKey a.[i] mementoIntCount then // 計算量を節約するために、再び同じ場所を通ったときに経路を省略する
            let length = count - (Map.find a.[i] mementoIntCount) + 1L 
            let count = ((max - count - 1L) / length) * length + count 
            move (a.[i], count + 1L, mementoIntCount )             
        else move (a.[i], count + 1L, Map.add a.[i] (count+1L) mementoIntCount )
    move (1, 0L, Map [1,0L])

move k |>fun (x, _, _) -> string x  |> stdout.WriteLine

Measured memory_bytes: 68316
import sys
def side(p1,p2):
  global D
  y1,x1=p1
  dy=p2[0]-y1
  dx=p2[1]-x1
  for p3 in D[::-1]:
    if p1==p3 or p2==p3:pass
    elif (p3[1]-x1)*dy-dx*(p3[0]-y1)<0:return 0
  else:return 1

while 1:
  n=input()
  if n==0:break
  D=sorted([list(input()) for i in range(n)])
  p=p1=D[0]
  D1=D[:]
  while True:
    for p2 in D1:
      if p1!=p2 and side(p1,p2):break
    p1=p2
    D1.remove(p2)
    if p2==p:break
  print len(D1)

Measured memory_bytes: 4276
#include <iostream>
#include <string>
#include <vector>
#include <unordered_set>

using namespace std;

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

	vector<string> arr(n);
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}


	unordered_set<string> us;
	us.insert(arr[0]);

	for (int i = 1; i < n; i++)
	{
		int len = arr[i - 1].length();
		if (arr[i][0] == arr[i - 1][len - 1] && us.find(arr[i]) == us.end())
		{
			us.insert(arr[i]);
			continue;
		}
		else
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,a,M;
  int ten=1;
  cin>>N;
  for(int i=0;i<9;i++){
    a=N/ten;
    M+=(a%10);
    ten*=10;
  }
  if((N%M)==0){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}
    




Measured memory_bytes: 256
s = gets.chomp.chars
n = gets.chomp.to_i
revc = 0
revd = false
n.times do
  q = gets.chomp
  case q[0]
  when "1"
    revc += 1
    revd = !revd
  when "2"
    is_unshift = (q[2] == "1" && !revd) || (q[2] != "1" && revd)
    if is_unshift
      s.unshift q[-1]
    else
      s.push q[-1]
    end
  end
end

puts revd ? s.reverse.join : s.join

Measured memory_bytes: 30204
#include <bits/stdc++.h>
#include <vector>
 
using namespace std;
const double PI=3.14159265358979323846;
 
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {

	int n, m;

	cin >> n >> m;

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

	int a, b;
	bool black[n] = {false};
	for (int i = 0; i < m; i++) {
		cin >> a >> b;

		if (h[a - 1] > h[b - 1]) black[b - 1] = true;
		if (h[a - 1] < h[b - 1]) black[a - 1] = true;
		if (h[a - 1] == h[b - 1]) {
			black[b - 1] = true;
			black[a - 1] = true;
		}


		/*
		if (h[a - 1] != -1 && h[b - 1] != -1) {

			if (h[a - 1] > h[b - 1]) h[b - 1] = -1;
			if (h[a - 1] < h[b - 1]) h[a - 1] = -1;


		}*/
	}


	int cut = 0;
	for (int i = 0; i < n; i++) {
		//cout << black[i] << endl;
		if (!black[i]) cut++;
	}

	cout << cut << endl;
}



Measured memory_bytes: 4040
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,q) for(int i = 0; (q) > i; i++)
int main(){
  int n;cin>>n;
  vector<int> notten;
  vector<int> yesten;
  int sm = 0;
  rep(i,n){
    int tmp;cin>>tmp;
    sm += tmp;
    if(tmp % 10 == 0)yesten.push_back(tmp);
    else notten.push_back(tmp);
  }
  if(notten.size() == 0){
    cout << 0 << endl;
  }else{
    if(sm % 10 != 0){
      cout << sm << endl;
    }else{
      sort(notten.begin(),notten.end());
      cout << sm - notten[0] << endl;
    }
    
  }

}

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

ll repeatSquare(int n, int p, int mod){
    if(p==0) return 1;
    else if(p%2==0){
        ll t = repeatSquare(n, p/2, mod);
        return t*t%mod;
    }
    return n*repeatSquare(n, p-1, mod)%mod;
}

int main(){
    int H, W, A, B;
    cin >> H >> W >> A >> B;
    ll mod = 1e9+7;
    vector<ll> mul(H+W-2+1), div(H+W-2+1);
    mul[0] = 1;
    for(int i=1; i<=H+W-2; i++){
        mul[i] = (mul[i-1]*i)%mod;
    }

    for(int i=0; i<=H+W-2; i++){
        div[i] = repeatSquare(mul[i], mod-2, mod);
    }

    ll ans = 0;
    for(int b=B; b<W; b++){
        ll tmp = 1;
        tmp = (tmp*mul[H+b-A-1])%mod;
        tmp = (tmp*div[b])%mod;
        tmp = (tmp*div[H-A-1])%mod;
        tmp = (tmp*mul[W-2-b+A])%mod;
        tmp = (tmp*div[A-1])%mod;
        tmp = (tmp*div[W-1-b])%mod;
        ans = (ans + tmp)%mod;
    }
    cout << ans << endl;
}


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

using namespace std;

vector<int> S;

bool binarySearch(int n, int key)
{
	int left = 0;
	int right = n;
	int mid;

	while (left < right)
	{
		mid = (left + right) / 2;

		if (S[mid] == key)
			return true;
		else if (S[mid] < key)
			left = mid + 1;
		else
			right = mid;
	}

	return false;
}

int main()
{
	int N, Q, t;
	int sum = 0;
	cin >> N;

	S.resize(N);
	for (int i = 0; i < N; i++)
		cin >> S[i];

	cin >> Q;
	for (int i = 0; i < Q; i++)
	{
		cin >> t;
		if (binarySearch(N, t))
			sum++;
	}

	cout << sum << endl;

	return 0;
}

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

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

    long long *a = new long long[n + 1];
    std::map<int, int> congruence;
    a[0] = 0;
    congruence[0]++;
    for (int i = 1; i <= n; i++)
    {
        scanf("%lld", a + i);
        a[i] = (a[i] + a[i - 1]) % m;
        congruence[a[i]]++;
    }

    long long sum{};
    for (auto &e : congruence)
    {
        sum += (long long)e.second * (e.second - 1) / 2;
    }
    printf("%lld\n", sum);

    delete[] a;

	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;

int D, G, minc=1e9;
int scoring[19][2];

int cnt(int patern ) {

    int c = 0, sum = 0;
    
    for ( int i = 0; i < D; i++ ) {
        if ((1<<i & patern) > 0) {
            c += scoring[i][0];
            sum += scoring[i][1] + ((i+1)*100)*scoring[i][0];
        }
    }

    int idx = D;
    while ( sum < G && idx > 0 ) {
        idx--;
        if ((1<<idx & patern) > 0) continue;
        int c2 = min( scoring[idx][0]-1, (int)ceil((G-sum)/100/(idx+1)) );
        sum += c2*((idx+1)*100);
        c += c2;
    }
    if (sum<G) return 1e9;
    else return c;
}

int main(){
    
    memset( scoring, 0, sizeof(scoring));
    
    cin >> D >> G;
    
    int n, b;
    for ( int i = 0; i < D; i++) {
        cin >> n >> b;
        scoring[i][0] = n;
        scoring[i][1] = b;
    }
    
    for ( int i = 0; i < 1<<D; i++ ){
        minc = min(minc,cnt(i));
    }
    cout << minc << endl;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict, deque


def main():
    input = sys.stdin.readline
    d = defaultdict(list)
    N = int(input())
    ans = [0] * N
    for _ in range(N-1):
        a, b = map(int, input().split())
        d[a-1].append(b-1)
        d[b-1].append(a-1)

    C = list(map(int, input().split()))
    C = sorted(C, key=lambda x: -x)
    score = sum(C[1:])

    ans[0] = C[0]
    cnt = 1
    visited = set([0])
    q = deque()
    q.extend(d[0])
    while len(q) > 0:
        a = q.popleft()

        if a in visited:
            continue

        ans[a] = C[cnt]
        visited.add(a)
        cnt += 1

        q.extend(d[a])

    print(score)
    print(*ans, sep=' ')


if __name__ == '__main__':
    main()


Measured memory_bytes: 7636
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String s = sc.next();
		StringBuilder newS = new StringBuilder();
		newS.append(s.substring(0, k-1));
		newS.append(s.substring(k - 1, k).toLowerCase());
		newS.append(s.substring(k));
		
		System.out.println(newS);
	}	
}

Measured memory_bytes: 22484
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int n = get<int>();
    int a = get<int>();
    int b = get<int>();

    cout << min(n * a, b) << endl;
    return 0;
}

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

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

    multiset<long long int> num;
    for(int i=0; i<n; i++){
        long long int a;
        cin >> a;
        num.insert(a);
    }

    long long int ans = 0;
    while(num.empty() == false){
        long long int x = *prev(num.end());
        num.erase(num.find(x));

        long long int y = 1;
        while(y <= x) y *= 2;
        //cout << x << " " << y << endl;

        if(num.empty() == false
        && num.find(y - x) != num.end()){
            ans += 1;
            num.erase(num.find(y - x));
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12976
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

K = int(input())
N = 50

tmp1 = N - 1 + (K // N)
tmp2 = K % 50

ans = [0] * N
for i in range(N - tmp2):
    ans[i] = tmp1 - tmp2
for j in range(i + 1, N):
    ans[j] = tmp1 + N - tmp2 + 1

print (N)
print (*ans, sep = ' ')


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
  int a, b, h;
  cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>
#include <map>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(nullptr);
#define fix(n) fixed << setprecision(n)
#define ALL(v) v.begin(),v.end()

#define PI 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    FAST_IO
    ll n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];

    map<string,ll> count;
    ll max_count = 0;

    rep(i,n){
        count[s[i]]++;
        if(count[s[i]] > max_count){
            max_count = count[s[i]];
        }
    }

    vector<string> ans;
    for(auto &i : count){
        if(i.second == max_count){
            ans.push_back(i.first);
        }
    }

    sort(ALL(ans));

    rep(i,ans.size()){
        cout << ans[i] << endl;
    }

    
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
ll knapsack(const vector<ll>& v, const vector<ll>& w, ll W) {
    const ll n = v.size();
    assert(w.size() == n);
    vector<vector<ll>> dp(n+1, vector<ll>(W+1, -1));
    dp[0][0] = 0;
    rep(i, n) rep(j, W+1) {
        if (dp[i][j] < 0) continue;
        chmax(dp[i+1][j], dp[i][j]);
        if (j+w[i] <= W) {
            chmax(dp[i][j+w[i]], dp[i][j] + v[i]);
        }
    }
    ll ans = 0;
    rep(i, W+1) {
        chmax(ans, dp[n][i] + W-i);
    }
    return ans;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, D, W; cin >> n >> D >> W;
    vector<vector<ll>> p(D, vector<ll>(n)); cin >> p;
    rep(i, D-1) {
        W = knapsack(p[i+1], p[i], W);
    }
    cout << W << endl;
}

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

int main(void){
    int X;
    cin >> X;
    int b = ceil(sqrt(X));
    int maxv = 0;
    if(X==1) {
        cout << 1 << endl;
        return 0;
    }
    for(int i=2; i<=b; i++) {
        for(int j=i; j<=X; j*=i) {
            maxv = max(maxv, j);
        }
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> p;
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    p.emplace_back(b, a);
  }

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

  int res = 0;
  int prev = 0;
  for (int i = 0; i < m; i++) {
    if (p[i].second >= prev) {
      res++;
      prev = p[i].first;
    }
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 4320
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;

void rotate (string &s) {
    string nxt;
    for (int i = 0; i < s.size(); i++) {
        nxt.push_back(s[(i + 1) % s.size()]);
    }
    s = nxt;
}

int main () {

    string S,T;
    cin >> S >> T;

    REP(i,1000) {
        if (S == T) {
            cout << "Yes" << endl;
            return 0;
        }
        rotate (S);
    }

    cout << "No" << endl;
 
    return 0;
}

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

using namespace std;
int main(){
	int n, k, x, y, res=0;
	cin >> n >> k >> x >> y;
	
	if(n < k)
		for(int i=0; i<n; i++) res += x;
	else
		for(int i=0; i<k; i++) res += x;
	
	for(int i=0; i<n-k; i++) res += y;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/ruby
n=gets.to_i+1
x=n.to_s(2).size-1
q=[*1..x]
n-=1<<x
(x-1).downto(0){|i|
	next if n<1<<i
	x+=1
	q.insert(i,x)
	n-=1<<i
}
q+=[*1..q.size]
p q.size
puts q*' '

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

using namespace std;

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    if(K % 2 == 1){
        cout << (N/K)*(N/K)*(N/K) << endl;
    }else{
        ll n, m;
        n = N / K;
        m = N / (K / 2) - n;
        cout << n*n*n + m*m*m << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}
Int tmpi = 0;
double tmpd = 0.0;


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

    Int n, t[6];
    cin >> n;
    for(Int i=0; i<5; i++){
        cin >> t[i];
    }

    Int mint = pow(10, 15)+2;
    Int minind = 0;
    for(Int i=0; i<5; i++){
        if(t[i] < mint){
            mint = t[i];
            minind = i;
        }
    }
    
    Int ans = ceil(double(n)/double(mint)) + minind + 5-(minind+1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = sorted(input())
characters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','t','u','v','w','x','y','z']
ans = "None"
for i in characters:
      if i not in s:
        ans = i
        break
print(ans)
 

Measured memory_bytes: 4408
#include <stdio.h>
#include <string.h>

int main(void){
  int n,d[110][2],i,count=0;
  if(scanf("%d",&n) == EOF) return 1;
  for(i=0;i<n;i++) if(scanf("%d %d",&d[i][0],&d[i][1]) == EOF) return 1;
  
  for(i=0;i<n;i++){
    if(d[i][0] == d[i][1]) count++;
    else count=0;
    if(count >= 3){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No\n");
  
  return 0;
}

Measured memory_bytes: 1660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        for (int i = 0; i < W + 2; i++) {
            System.out.print("#");
        }
        System.out.println();
        for (int i = 0; i < H; i++) {
            System.out.println("#" + sc.next() + "#");
        }
        for (int i = 0; i < W + 2; i++) {
            System.out.print("#");
        }
        System.out.println();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

vector<vector<double>> X(10,vector<double>(10,0));

int main(){
    int N,D;
    cin >> N >> D;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < D; j++) {
            cin >> X[i][j];
        }
    }
    double sum = 0;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            for (int k = 0; k < D; k++) {
                sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            if(sqrt(sum) == (int)sqrt(sum)) {
                    ans++;
            } 
            sum = 0;
        }
    }
    cout << ans << "\n";
}

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

int main(void){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a.at(i);
    }

    int cnt=1;
    int breaked=0;
    for(int i=0;i<N;i++){
        if(a.at(i) == cnt){
            cnt++;
            //cout << i << endl;
        }else{
            breaked++;
        }
    }

    if(breaked == N){
        cout << -1 << endl;
    }else{
        cout << breaked << endl;
    }

    return(0);
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

int main(){
  string s;
  int c=0;
  cin >> s;
  map<char,int> num;
  rep(i,4){
    if(!(num.count(s.at(i)))){
      c++;
      num[s.at(i)]=1;
    }
    else num[s.at(i)] += 1;
  }
  bool ans=true;
  rep(i,4) if(num.at(s.at(i))!=2) ans=false;
  if(ans) cout << "Yes" << endl;
  else cout << "No" <<endl;
} 


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

int main(){
	int n,c,k;
	cin>>n>>c>>k;
	int ans=0;
	int t[n];
	for(int i=0;i<n;i++) cin>>t[i];
	sort(t,t+n);
	int sum=1;
	int T=t[0];
	for(int i=1;i<n;i++){
	    sum++;
	    if(sum<=c&&t[i]-T<=k) continue;
	    else{
	        sum=1;
	        T=t[i];
	        ans++;
	    }
	}
	cout<<ans+1<<endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;

template<typename T> void inv(vector<T> &a)
{
	for (int i = 0; i < a.size(); i++)
	{
		cin >> a[i];
	}
}


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

	vector<int> a(n);
	inv(a);

	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int b, e;
		cin >> b >> e;

		reverse(a.begin() + b, a.begin() + e);
	}

	bool sp = false;
	for (int i : a)
	{
		print((sp ? " " : "") << i);
		sp = true;
	}
	println("");
}



Measured memory_bytes: 3132