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

int main(){
	char s[5],tmp=0;
	bool f=0;
	int cnt=0;
	scanf("%s",s);
	for(int i=0;i<4;i++){
		if(tmp==s[i]){
			cnt++;
		} else {
			tmp=s[i];
			cnt=1;
		}
		if(cnt>=3)f=1;
	}
	if(f)puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include <stdio.h>

int max(int x, int y)
{
    if (x > y)
        return x;
    else
        return y;
}

int main()
{
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    printf("%d", max(a * b, c * d));
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	int al=a.length(),bl=b.length();
	for(int i=0;i<al-1;i++)
		cout<<a[i]<<b[i];
	cout<<a[al-1];
	if(al==bl) cout<<b[bl-1];
	cout<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n, m;
  cin >> n >> m;
  vector<string> a(n);
  vector<string> b(m);
  REP(i, n) { cin >> a.at(i); }
  REP(i, m) { cin >> b.at(i); }

  REP(i, n - m + 1) {
    REP(j, n - m + 1) {
      bool f = true;
      REP(k, m) {
        //cout << a.at(i + k).substr(j, m) <<"  "<<b.at(k)<< "\n";
        if (b.at(k) != a.at(i + k).substr(j, m)) f = false;
      }
     // cout  << "\n";
      if (f) {
        cout << "Yes\n";
        return 0;
      }
    }
  }

  cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ios ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);

int main()
{
    ios
    ll n;
    cin>>n;
    vector<ll> v(n);
    ll ct=0,sum=0,ctm=0,mn=1000000000;
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
        sum+=abs(v[i]);
        if(v[i]<0)
            ctm++;
        if(v[i]==0)
            ct++;
        mn=min(abs(v[i]),mn);
    }
    if(ctm%2==0)
        cout<<sum;
    else if(ctm%2==1 && ct>0)
        cout<<sum;
    else
        cout<<sum-2*mn;
    return 0;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a*b > c*d) cout << a*b;
  else cout << c*d;
  cout << endl;
}

Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
      
      string input = Console.ReadLine();
      string a = "";
      string b = "";
      string output = "";
      
      for(int i = 0; i < input.Length; i++)
      {
        if((i+1) % 2 == 1)
        {
        	a = a + input[i];
        }
        else
        {
        	b = b + input[i];
        }
      }
      
      if(a.Contains("L") || b.Contains("R"))
      {
        output = "No";
      }
      else
      {
      	output = "Yes";
      }
      Console.WriteLine(output);
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
using namespace std;

int n;

void fun(int pos, int count, string & s){
	if(pos == n){
		cout<<s<<endl;
	}
	else{
		for(int i = 1; i <= count; i++){
			s[pos] = 'a' + i - 1;
			fun(pos + 1, count, s);
		}
		s[pos] = 'a' + count;
		fun(pos + 1, count + 1, s);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	string s;
	s.resize(n);
	fun(0, 0, s);
	return 0;
}

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

int n,ta,ao,ans;
vector<int> g[100005];
int dis[100005];

void dfs(int x,int p,int d){
    if(d>=dis[x]){//如果被抓到了就退出
        ans=max(ans,dis[x]);
        return;
    }
    for(int i=0;i<g[x].size();i++){
        int &y=g[x][i];
        if(y!=p){
            dfs(y,x,d+1);
        }
    }
    if(g[x].size()==1){//是叶子结点，就特判一下之前做法中提到的情况
        ans=max(ans,dis[x]-1);
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>ta>>ao;
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    memset(dis,-1,sizeof(dis));
    dis[ao]=0;
    {//预处理青木到每个结点的距离dis
        queue<int> q;
        q.push(ao);
        while(!q.empty()){
            int x=q.front();q.pop();
            for(int i=0;i<g[x].size();i++){
                int &y=g[x][i];
                if(dis[y]==-1){
                    dis[y]=dis[x]+1;
                    q.push(y);
                }
            }
        }
    }
    dfs(ta,-1,0);
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

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

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr int ginka_inf = 50 * 50;
constexpr ll dist_inf = 100000'00000'00000LL;
constexpr int n_inf = 50;
struct edge {
    int cod;
    int unchin;
    ll jikan;
};
int n, m;
int s;
vector<vector<edge>> edges(n_inf);
vector<int> koukan_ginka_s(n_inf);
vector<ll> koukan_jikan_s(n_inf);

vector<vector<bool>> used_dijk(n_inf, vector<bool>(ginka_inf + 1, false));
vector<vector<ll>> res(n_inf, vector<ll>(ginka_inf + 1, dist_inf));

typedef tuple<ll, int, int> dijk_type;
void dijk(const dijk_type &tup) {
    priority_queue<dijk_type, vector<dijk_type>, greater<dijk_type>> mins;
    mins.push(tup);
    while (!mins.empty()) {
        ll dist; int v, ginka; tie(dist, v, ginka) = mins.top(); mins.pop();
        if (used_dijk[v][ginka]) {
            continue;
        }
        used_dijk[v][ginka] = true;
        res[v][ginka] = min(res[v][ginka], dist);
        {
            auto ginka_ = ginka + koukan_ginka_s[v];
            auto dist_ = dist + koukan_jikan_s[v];
            if (ginka_ <= ginka_inf && !used_dijk[v][ginka_]) {
                mins.push({dist_, v, ginka_});
            }
        }
        for (auto e : edges[v]) {
            auto ginka_ = ginka - e.unchin;
            auto dist_ = dist + e.jikan;
            auto v_ = e.cod;
            if (ginka_ >= 0 && !used_dijk[v_][ginka_]) {
                mins.push({dist_, v_, ginka_});
            }
        }
    }
}

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(15); // 浮動小数の表示の精度

    cin >> n >> m >> s;
    s = min(s, ginka_inf);

    edges.resize(n);
    koukan_ginka_s.resize(n);
    koukan_jikan_s.resize(n);
    used_dijk.resize(n);
    res.resize(n);

    rep(i, 0, m) {
        int u, v, un; ll ji;
        cin >> u >> v >> un >> ji;
        u--; v--;
        edges[u].push_back({v, un, ji});
        edges[v].push_back({u, un, ji});
    }

    rep(i, 0, n) {
        int gi, ji;
        cin >> gi >> ji;
        koukan_ginka_s[i] = min(gi, ginka_inf);
        koukan_jikan_s[i] = ji;
    }

    dijk({0LL, 0, s});
    rep(v, 1, n) {
        ll r = dist_inf;
        rep(j, 0, ginka_inf + 1) {
            r = min(r, res[v][j]);
        }
        cout << r << '\n';
    }

    return 0;
}


Measured memory_bytes: 8332
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int maxn=100000;
int n;
vector<int> g[maxn+5],id[maxn+5];
int c[maxn+5],ans[maxn+5],Col=-1;
void add(int u,int v,int tot)
{
	g[u].push_back(v);
	id[u].push_back(tot);
	return;
}
void dfs(int u,int fa)
{
	int color=1;
	for(int i=0;i<g[u].size();i++)
	{
		int v=g[u][i];
		if(v==fa) continue;
		if(color==c[u]) color++;
		c[v]=color;
		Col=max(Col,color);
		ans[id[u][i]]=c[v];
		dfs(v,u);
		color++;
	}
	return;
}
signed main()
{
	scanf("%d",&n);
	int u,v;
	for(int i=1;i<=n-1;i++)
	{
		scanf("%d%d",&u,&v);
		add(u,v,i);
		add(v,u,i);
	}
	c[1]=-1;
	dfs(1,0);
	printf("%d\n",Col);
	for(int i=1;i<=n-1;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 14208
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		try {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			String str = input.readLine();
			int n = Integer.parseInt(input.readLine());
			for (int i = 0; i < n; i++) {
				String[] line = input.readLine().split(" ");
				String command = line[0];
				int begin = Integer.parseInt(line[1]);
				int end = Integer.parseInt(line[2]) + 1;
				if (command.equals("print")) {
					System.out.println(str.substring(begin, end));
				} else if (command.equals("reverse")) {
					if (begin == 0) {
						str = new StringBuffer(str.substring(0, end)).reverse().toString().concat(str.substring(end));
					} else if (end == str.length()) {
						str = str.substring(0, begin).concat(new StringBuffer(str.substring(begin)).reverse().toString());
					} else {
						str = str.substring(0, begin).concat(new StringBuffer(str.substring(begin, end)).reverse().toString()).concat(str.substring(end));
					}
				} else if (command.equals("replace")) {
					if (begin == 0) {
						str = line[3].concat(str.substring(end));
					} else if (end == str.length()) {
						str = str.substring(0, begin).concat(line[3]);
					} else {
						str = str.substring(0, begin).concat(line[3]).concat(str.substring(end));
					}
				}
			}
			input.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 21428
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int x,a,b;
int pow5(int x)
{
	return x*x*x*x*x;
}
void judge(int a)
{
	int t=pow5(a)-x,d,op=1;
	if(t<0)t=-t,op=-1;
	d=floor(pow(t,1.0000/5));
	//cerr<<a<<" "<<op*d<<endl;
	if(pow5(d)==t)
	{
		cout<<a<<" "<<op*d;
		exit(0);
	}
}
signed main()
{
	cin>>x;
	a=0;
	//judge(2);/*
	while(1)
	{
		judge(a);
		a++;
	}
}

Measured memory_bytes: 4064
#include <stdio.h>
int main(void)
{
  int a, b;
  scanf("%d%d",&a ,&b);
  if (a < b)
    puts("a < b");
  else if (a > b)
    puts("a > b");
  else if (a == b)
    puts("a == b");

  return 0;
}

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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

typedef long long ll;
typedef pair<int, int> ii;

int main(){

	string a, b;
	cin >> a >> b;

	for(int i = 0; i + b.size() <= a.size(); ++i){
		string tmp = a.substr(i, b.size());
		bool flag = true;
		for(int j = 0; j < b.size(); ++j){
			flag &= (tmp[j] == b[j] || tmp[j] == '_' || b[j] == '_');
		}

		if(flag){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}



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

T = [0]
X = [0]
Y = [0]


for i in range(N) :
    t, x, y = map(int, input().split())
    T.append(t)
    X.append(x)
    Y.append(y)
#print(T, X, Y)

judge = True

for i in range(1, N + 1) :
    if T[i] - T[i-1] >= abs(X[i] - X[i-1]) + abs(Y[i] - Y[i-1]) :
        if (T[i] - T[i-1] - (abs(X[i] - X[i-1]) + abs(Y[i] - Y[i-1]))) % 2 == 0 :
            #print('test')
            continue
    judge = False
    break

if judge :
    print('Yes')
else :
    print('No')


Measured memory_bytes: 11728
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[10][10],b[10][10],c[10][10],TEST;
int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};
bool solve(int x){
  r(i,10)if((x>>i)&1){
    c[0][i]=1;
    r(j,5){
      int y=dy[j];
      int x=dx[j]+i;
      if(y<0||x<0||y>9||x>9)continue;
      b[y][x]=(b[y][x]+1)%2;
    }
  }
  for(int i=0;i<9;i++){
    r(j,10){
      if(b[i][j]){
        c[i+1][j]=1;
        r(k,5){
          int y=i+dy[k]+1;
          int x=j+dx[k];
          if(y<0||x<0||y>9||x>9)continue;
          b[y][x]=(b[y][x]+1)%2;
        }
      }
    }
  }
  r(i,10)r(j,10)if(b[i][j])return 0;
  return 1;
}
int main(){
  cin>>TEST;
  while(TEST--){
    r(i,10)r(j,10)cin>>a[i][j];
    for(int i=0;i<(1<<10);i++){
      r(k,10)r(j,10)b[k][j]=a[k][j];
      memset(c,0,sizeof(c));
      if(solve(i)){
        r(i,10){
          r(j,10){
            if(j)cout<<' ';
            cout<<c[i][j];
          }
          cout<<endl;
        }
        goto L;
      }
    }L:;
  }
}

Measured memory_bytes: 3084
#include <cstdio>
#include <cstdlib>

int gcd(int, int);

int main(){
    int n,X;
    scanf("%d %d",&n,&X);
    int x[n];
    for(int i = 0; i < n; i++){
        scanf("%d",&x[i]);
    }

    if(n == 1){
        printf("%d\n",abs(x[0] - X));

        return 0;
    }

    int ans = gcd(abs(x[0] - X), abs(x[1] - x[0]));
    for(int i = 1; i + 1 < n; i++){
        ans = gcd(ans, abs(x[i + 1] - x[i]));
    }
    printf("%d\n",ans);

    return 0;
}

int gcd(int a, int b){
    int r,p;
    if(a < b){
        p = a;
        a = b;
        b = p;
    }

    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
 
    return b;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (int)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;

#define MAX 100001

ll a[3][MAX],n,dp[3][MAX],tmp;

int main(void){
    cin>>n;
    rep(i,n)rep(j,3)cin>>a[j][i];
    dp[0][0]=a[0][0]; dp[1][0]=a[1][0]; dp[2][0]=a[2][0];
    rep(i,n-1)rep(j,3)dp[j][i+1]=max(dp[(j+1)%3][i]+a[j][i+1],dp[(j+2)%3][i]+a[j][i+1]);
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int GCD(int x,int y){
  if(x<y){
    swap(x,y);
  }
  while(x%y!=0){
    int temp=x;
    x=y;
    y=temp%y;
  }
  return y;
}

int digitsum(int x){
  int sum=0;
  while(x>0){
    sum+=(x%10);
    x/=10;
  }
  return sum;
}

int main() {
  int x,y,z;
  cin>>x>>y>>z;
  swap(x,y);swap(x,z);
  cout<<x<<' '<<y<<' '<<z<<endl;
  return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
    ll n,x,t;
    cin>>n>>x>>t;
    ll ans=0;
    if(n%x==0)
    {
        ans=(n/x)*t;
    }
    else
        ans=(n/x+1)*t;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

const ll mod = 1e9 + 7;
const int N = int(3e5) + 999;
#define int long long int
#define inf 1e18

int g[51][51], p[51][51];
int n, k;

void inp()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            cin >> g[i][j];
}
void sub()
{
    for (int i = 0; i < 51; i++)
        for (int j = 0; j < 51; j++)
            p[i][j] = g[i][j];
}
void mult()
{
    int c[51][51];
    memset(c, 0, sizeof c);
    for (int i = 0; i < 51; i++)
        for (int j = 0; j < 51; j++)
            for (int k = 0; k < 51; k++)
                c[i][j] = (c[i][j] + (p[i][k] * p[k][j]) % mod) % mod;

    for (int i = 0; i < 51; i++)
        for (int j = 0; j < 51; j++)
            p[i][j] = c[i][j] % mod;
}

void mult2()
{
    int c[51][51];
    memset(c, 0, sizeof c);
    for (int i = 0; i < 51; i++)
        for (int j = 0; j < 51; j++)
            for (int k = 0; k < 51; k++)
                c[i][j] = (c[i][j] + (p[i][k] * g[k][j]) % mod) % mod;

    for (int i = 0; i < 51; i++)
        for (int j = 0; j < 51; j++)
            p[i][j] = c[i][j] % mod;
}

void power(int p0)
{
    if (p0 == 1)
    {
        sub();
        return;
    }

    power(p0 / 2);
    mult();
    if (p0 % 2)
        mult2();
}

int32_t main()
{
    IOS;
    inp();
    power(k);
    int ans = 0;
    for (int i = 0; i < 51; i++)
    {
        for (int j = 0; j < 51; j++)
            ans = (ans + p[i][j]) % mod;
    }
    cout << ans % mod;
    return 0;
}

Measured memory_bytes: 384
/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#ifndef H_int_literals
#define H_int_literals

#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

#endif  /* !defined(H_int_literals) */

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */

#ifndef H_make_vector
#define H_make_vector

#include <cstddef>
#include <type_traits>
#include <vector>

namespace detail {
  template <typename Tp, size_t N>
  std::vector<Tp> make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N == 1), Tp const&>::type x
  ) {
    return std::vector<Tp>(sizes[0], x);
  }
  template <typename Tp, size_t N>
  auto make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N > 1), Tp const&>::type x
  ) {
    size_t size = sizes[N-1];
    sizes.pop_back();
    return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
        size, make_vector<Tp, N-1>(sizes, x)
    );
  }
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x = Tp()) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

#endif  /* !defined(H_make_vector) */

#include <cstdio>
#include <cstdint>
#include <vector>
#include <string>

int main() {
  char buf[1048576];
  scanf("%s", buf);
  std::string s = buf;
  s.insert(s.begin(), '0');

  size_t n = s.length();

  int const inf = 1e9;
  auto dp = make_vector({n+1, 2_zu}, inf);
  dp[0][0] = 0;
  for (size_t i = 0; i < n; ++i) {
    // fprintf(stderr, "s[-%zu]: '%c'\n", i, s[n-1-i]);
    for (size_t j = 0; j <= 1; ++j) {
      int d = s[n-1-i] - '0' + j;
      int self = dp[i][j];

      // そのままはらう
      dp[i+1][0] = std::min(dp[i+1][0], self + d);

      // 多くはらって、おつりをもらう
      dp[i+1][1] = std::min(dp[i+1][1], self + 1 + (9-d));
    }
  }

  // for (size_t j = 0; j <= 1; ++j)
  //   for (size_t i = 0; i <= n; ++i)
  //     fprintf(stderr, "%d%c", dp[i][j], i<n? ' ': '\n');

  printf("%d\n", dp[n][0]);
}


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

static const int MAX = 2501;
static const int INF = 1e9;

// ベルマンフォード法 O(EV)
vector<pair<int, int>> G[MAX];
vector<int> dist; // 最短距離
vector<bool> neg; // 負閉路
// main関数からこれらを削除すること

// 戻り値がtrueなら負の閉路を含む
bool bellman_ford(int n, int s) { // nは頂点数, sは開始頂点
  dist = vector<int>(n, INF); // 大きな数
  neg = vector<bool>(n, false);
  dist[s] = 0; // 開始点の距離は0
  pair<int, int> p;
  for (int i = 0; i < n; i++) {
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < G[v].size(); k++) {
        p = G[v][k];
        if (dist[v] != INF && dist[p.first] > dist[v] + p.second) {
          dist[p.first] = dist[v] + p.second;
          if (i == n - 1) neg[p.first] = true; // n回目にも更新があるなら負の閉路が存在
        }
      }
    }
  }
  return false;
}

// 隣接リストを用いた幅優先探索 O(|V|+|E|)
vector<int> d(MAX, INF), visited(MAX, 0); // 始点sから頂点iまでの最短距離をd[i]に記録
// main関数からこれらを削除すること

void bfs(int s) {
  d = vector<int>(MAX, INF);
  queue<int> q;
  q.push(s);
  d[s] = 0;
  visited[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v = 0; v < G[u].size(); v++) {
      if (d[G[u][v].first] == INF) {
        d[G[u][v].first] = d[u] + 1;
        q.push(G[u][v].first);
        visited[G[u][v].first] = 1;
      }
    }
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m, p;
  cin >> n >> m >> p;
  
//vector<pair<int, int>> G[n]; // G:頂点数がnのグラフを表す隣接リスト
  
  int u, v, w;
  for (int i = 0; i < m; i++) {
    cin >> u >> v >> w;
    u--;
    v--;
    G[u].emplace_back(make_pair(v, p - w));
//  G[v].emplace_back(make_pair(u, w)); // 有向グラフではこの行をコメントアウト
  }
  
  bellman_ford(n, 0);
  
  for (int i = 0; i < n; i++) {
    if (neg[i] && visited[i] == 0) {
      bfs(i);
      if (visited[n - 1]) {
        cout << -1 << '\n';
        return 0;
      }
    }
  }
  
  cout << max(0, -dist[n - 1]) << '\n';
  return 0;
}

Measured memory_bytes: 512
using System;
class Program
{
    static void Main(string[] args)
    {
        int ct = int.Parse(Console.ReadLine());
        string[] input = Console.ReadLine().Split(' ');
        int[] A = new int[ct];
        for (var i = 0; i < ct; i++)
        {
            A[i] = int.Parse(input[i]);
        }

        var r1 = 0;
        for (var i = 0; i < ct; i++)
        {
            r1 += (i % 2 == 0) ? A[i] : -A[i];
        }
        Console.WriteLine(r1);
        var p = r1 / 2;
        for (var i = 1; i < ct; i++)
        {
            var rp = A[i-1]-p;
            Console.WriteLine(rp*2);
            p = rp;
        }
    }
}


Measured memory_bytes: 25692
n,k,q = gets.chomp.split(" ").map(&:to_i)
a_arr = q.times.map{gets.to_i}

hash = {}
a_arr.each do |a|
  hash[a] ||= 0
  hash[a] += 1
end

(1..n).each do |i|
  if k - q + hash[i].to_i > 0 then
    puts "Yes"
  else
    puts "No"
  end
end


Measured memory_bytes: 6908
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef vector<int>         vi;
const int mod = 1000000007;






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

    int n,flag=1;
    cin>>n;
    vi a(n);
    vi b(n);
    vi c(n);

    for(int i =0;i < n;i++){
        cin>>a[i];
    }
    for(int i =0;i < n;i++){
        cin>>b[i];
    }
    for(int i =0;i < n;i++){
        cin>>c[i];
    }
    sort(all(a));
    sort(all(b));
    sort(all(c));
    int ans =0;
    auto it = b.begin();
    auto it1 = c.begin();
    for(int i =0;i < n;i++){
        it = lower_bound(all(a),b[i]);
        int middle_ind = it-a.begin();

        it1 = upper_bound(all(c),b[i]);
        int end_elem = n-(it1 - c.begin()) ;
        ans =ans + middle_ind*end_elem;




    }
    cout<<ans<<endl;






}






























































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

using namespace std;

typedef long long LL;

const int N = 110;

int n, a[N];

bool check()
{
    bool flag = true;
    for(int i = 0; i < n - 1; i++)
        if(a[i] > a[i + 1])
            return false;
    return true;
}

int main()
{
    int cnt = 0;

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

    if(check())
    {
        puts("YES");
        return 0;
    }

    for(int i = 0; i < n; i++)
        for(int j = 0; j < i; j++)
        {
            swap(a[i], a[j]);
            if(check())
            {
                puts("YES");
                return 0;
            }
            swap(a[i], a[j]);
        }

    puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='H'&&b=='H')   printf("H\n"); 
			else if(a=='H'&&b=='D')  printf("D\n");
			else if(a=='D'&&b=='D')  printf("H\n");
			else if(a=='D'&&b=='H')  printf("D\n");
			return 0;
}


Measured memory_bytes: 128
import math
n, x = map(int, input().split())
xx = sorted(list(map(int, input().split())) + [x])
y = xx[0]
for i in range(n + 1):
    xx[i] -= y
y = xx[1]
for i in range(2, n + 1):
    y = math.gcd(y, xx[i])
print(y)


Measured memory_bytes: 20432
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
class Program
{
    static void Main(string[] args)
    {
        var k = int.Parse(Console.ReadLine());
        long ans = 0;
 
        for(int a = 1; a <= k; a++)
        {
            for (int b = 1; b <= k; b++)
            {
                for (int c = 1; c <= k; c++)
                {
                    var tmp = Gcd(a, b);
                    ans = ans + Gcd(tmp, c);
                }
            }
        }
 
        Console.WriteLine(ans);
    }
 
    /// <summary>
    /// 最大公約数
    /// </summary>
    public static long Gcd(long m, long n)
    {
        // 必ず m > n にする
        if (m < n)
        {
            var tmp = m;
            m = n;
            n = tmp;
        }
 
        while (true)
        {
            var r = m % n;
            if (r == 0) return n;
            m = n;
            n = r;
        }
    }
}

Measured memory_bytes: 27536
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int a[100010], b[100010];
signed main(void)
{
  int n;
  cin >> n;
  REP(i, n) cin >> a[i];

  int idx = 1, ret = 0;
  REP(i, n) {
    if(a[i] == idx) idx++;
    else {
      ret += (a[i]-1)/idx;
      if(i == 0) idx++;
    }
  }
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
 
  int n;
  cin >> n;
  int a = n * 100 / 108;
  if (int(a * 1.08) == n)
    cout << a << '\n';
  else if (int((a+1) * 1.08) == n)
    cout << a+1 << '\n';
  else
    cout << ":(" << '\n';
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define sz(x)                       (ll) x.size()
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define endl                        '\n'

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 2e5 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 998244353; //1e9 + 7
const ld PI = 4 * atan((ld) 1);
ll a[MAXN];
int main() {
    fast_io;
    set_random;
    ll n;
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a , a + n);
    ll ans = 0;
    for (ll i = 0; i < n - 2; i++) {
        for (ll j = i + 1; j < n - 1; j++) {
            for (ll k = j + 1; k < n; k++) {
                ll x = a[i], y = a[j], z = a[k];
                if (x + y > z && y + z > x && x + z > y)
                    ans++;
                else break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
N = int(input())
#A,B,C = map(int,input().split())
w = list(map(int,input().split()))
ans = 1000000000
w_sum = sum(w)
ruisekiwa = [0]*(N+1)
for i in range(1,N+1):
    ruisekiwa[i] = ruisekiwa[i-1]+w[i-1]
for i in range(N+1):
    sa = abs((w_sum-ruisekiwa[i])-ruisekiwa[i])
    ans = min(sa,ans)
print(ans)

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

using namespace std;

int A[3];

void solve() {

    int i = 0, five_counter = 0, seven_counter = 0;
    for (i = 0; i < 3 ; i++) {
        if (A[i] == 5){
            five_counter += 1;
        }
        else if (A[i] == 7) {
            seven_counter += 1;
        }
    }

    if(five_counter == 2 && seven_counter == 1) {
        cout << "YES" << endl;
    }

    else{
        cout << "NO" << endl;
    }

}

int main() {
    cin >> A[0] >> A[1] >> A[2];

    solve();
}

Measured memory_bytes: 3608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
            String N = sc.next();

            String kekka = "No";

            for(int i=0; i<N.length(); i++) {
                if('7'==N.charAt(i)) kekka = "Yes";
            }

            System.out.println(kekka);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

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

#define _rep4(i,p,n,k) for(int i=(p),_rep##_bound=(n),_rep##_inc=(k);i<_rep##_bound;i+=_rep##_inc)
#define _rep3(i,p,n,_a) _rep4(i,p,n,1)
#define _rep2(i,n,_a,_b) _rep4(i,0,n,1)
#define _repcall(a,b,c,d,name,...) name(a,b,c,d)
#define rep(...) _repcall(__VA_ARGS__,_rep4,_rep3,_rep2)

int work(std::istream &in) {
    int N;
    in >> N;
    std::string S;
    in >> S;
    std::vector<std::vector<int>> T(10, std::vector<int>(N + 2));
    rep(i, 10) T[i][N + 1] = N + 1;
    for (int j = N; 0 <= j; --j) {
        rep(i, 10) {
            if (S[j] - '0' == i) {
                T[i][j] = j + 1;
            } else {
                T[i][j] = T[i][j + 1];
            }
        }
    }
    int ret = 0;
    rep(i, 10) {
        rep(j, 10) {
            rep(k, 10) {
                if (T[k][T[j][T[i][0]]] != N + 1) ++ret;
            }
        }
    }
    return ret;
}

int runTest() {
    int ret = 0;

    struct testcase {
        const char *input;
        int expected;
    };

    struct testcase testdata[] = {
        { "4\n0224", 3 },
        { "6\n123123", 17 },
        { "19\n3141592653589793238", 329 },
    };

    for (const auto &t : testdata) {
        auto in = std::stringstream(t.input);
        int actual = work(in);
        if (actual != t.expected) {
            fprintf(stderr, "expected %d, but actual %d\n", t.expected, actual);
            ret = 1;
        }
    }

    return ret;
}

int main(int argc, char *argv[]) {
    if (argc == 2 && strcmp("--test", argv[1]) == 0) {
        return runTest();
    }
    printf("%d\n", work(std::cin));
    return 0;
}


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


#define M 1000000
#define NL -1
#define K 14

char H[M][K];


int getC(char cr){
  if(cr == 'A') return 1;
  if(cr == 'C') return 2;
  if(cr == 'G') return 3;
  if(cr == 'T') return 4;
  return 0;
}

int getk(char str[]){
  int sum = 0,p = 1,i;
  for(i = 0;i<strlen(str);i++){
    sum += p*(getC(str[i]));
    p *= 5;
  }
  return sum;
}

int HA(int k){
  return k % M;
}
int HB(int k){
  return 1 +(k %(M-1));
}

int s(char str[]){
  int key,i,P;
  key = getk(str);
  for(i = 0;;i++){
    P = (HA(key)+i*HB(key)) % M;
    if(strcmp(H[P],str) == 0) return 1;
    else if(strlen(H[P]) == 0) return 0;
  }
  return 0;

}

int ins(char str[]){
  int k,i,P;
  k = getk(str);
  for(i = 0;;i++){
    P = (HA(k)+i*HB(k)) %M;
     if(strcmp(H[P],str) == 0) return 1;
     else if(strlen(H[P]) == 0) {
       strcpy(H[P],str);
       return 0;
     }
  }
  return 0;
}


int main(){
  int i,n,P;
  char str[K],c[9];
  for(i = 0;i<M;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i = 0;i<n;i++){
    scanf("%s %s",c,str);

    if(c[0] == 'i'){
      ins(str);
    }
    else{
      if(s(str)){
	printf("yes\n");
      }
      else{
	printf("no\n");
      }
    }
  }
  return 0;
}


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

using namespace std;

int main()
{
  string s;
  int cnt = 0;

  cin >> s;

  for ( int i = 0; i < s.size(); ++i ) {
    if ( s[i] == 'o' ) ++cnt;
  }

  cout << 700+cnt*100 << endl;
}


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

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

	long long MOD = 1000000000 + 7;
	long long ans = 0;
	if( S > 2 ) {
		vector<long long> dp( S + 1 );
		dp[0] = 1;
		for( int i = 3; i < S + 1; i++ ) {
			for( int j = 0; j < i - 3 + 1; j++ ) {
				dp[i] += dp[j];
				dp[i] %= MOD;
			}
		}
		ans = dp[S];
	}

	cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

ll n,m,k;
string s,t;

int main() {
  cin >> n >> m >> s >> t;
  ll g=__gcd(n,m);
  ll ans=n/g*m; n/=g,m/=g;
  bool ok=true;
  rep(i,g)if(s[n*i]!=t[m*i]) ok=false;
  cout << (ok ? ans : -1) << endl;
}

Measured memory_bytes: 512
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<pii,int> ppiii ;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1e9 + 7;
int n,m,Q;
ll dp[4010][4010]={0};
ll fact[202020], frev[202020];//階乗,逆元
ll C(int p, int q)
{
	if (q < 0 || p < q) return 0;
	return fact[p] * frev[q] % MOD * frev[p - q] % MOD;
}
ll modpow(ll a, ll b) {//a^b%mod
	ll res = 1;
	for (; b > 0; a = a * a % MOD, b /= 2) if (b & 1) res = res * a % MOD;
	return res;
}
int main(){
	cin>>n;
	int a,b;
	vector<pii> data(n);	
	fact[0] = frev[0] = 1;
	for (int i = 1; i <= 10000; ++i) {
		fact[i] = (fact[i - 1] * i) % MOD;
		frev[i] = modpow(fact[i],MOD-2);
	}
	for(int i=0;i<n;i++){
		cin>>a>>b;
		dp[2001-a][2001-b]++;
		data[i]=mp(a,b);
	}
	for(int i=1;i<=4009;i++){
		for(int j=1;j<=4009;j++){
			dp[i][j]=(dp[i][j]+dp[i-1][j]+dp[i][j-1])%MOD;
		}
	}
	//cout<<dp[0][9]<<endl;
	ll ans=0;
	for(int i=0;i<n;i++){
		int p=data[i].first,q=data[i].second;
		ans=(ans+dp[2001+p][2001+q])%MOD;
			ans=(ans+MOD-C(2*p+2*q,2*q))%MOD;
	}
	ans=(ans*frev[2])%MOD;
	cout<<ans<<endl;

}

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

int main(){
  long long int n;
  cin>>n;
  vector<long long int> vec(n);
  long long int sum=0;
  for(int i=0;i<n;i++){
    cin>>vec.at(i);
    sum+=vec.at(i);
  }
  long long int p=0,q=2020202020*100000+1;
  for(int i=0;i<n;i++){
    p+=vec.at(i);
    q=min(q,abs(sum-p-p));
  }
  cout<<q<<endl;    
}

Measured memory_bytes: 1792
// #include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <map>
#include <math.h>
#include <algorithm> // std::sort, std::min, std::next_permutation, std::lower_bound
#include <iomanip> // std::setprecision
#include <cmath> // std::ceil
#include <numeric> // std::gcd, std::lcm
#include <limits> // std::numeric_limits<long int>::max()
#include <unordered_map>
#include <map>
#include <cmath> // std::atan2
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
#define INF 1999999999
#define MODA 1000000007 
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];

  vector<bool> tpeek(N, false);
  vector<bool> bpeek(N, false);
  for (ll i=0; i<N-1; ++i) {
    if (A[i] > A[i+1]) tpeek[i] = true;
    if (A[i] < A[i+1]) bpeek[i] = true;
  }

  ll m = 1000;
  ll s = 0;
  for (ll i=0; i<N-1; ++i) {
    if (bpeek[i]) {
      s += m/A[i];
      m %= A[i];
    }
    if (tpeek[i]) {
      m += A[i]*s;
      s = 0;
    }
  }
  if (s != 0) {
      m += A[N-1]*s;
      s = 0;
  }
  cout << m << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<vector<char>> s(N, vector<char>(10));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 10; j++){
      cin >> s[i][j];
    }
  }
  for (int i = 0; i < N; i++){
    sort(s[i].begin(), s[i].end());
  }
  vector<string> s2(N);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < 10; j++){
      s2[i] += s[i][j];
    }
  }
  sort(s2.begin(), s2.end());
  int C = 0;
  long long ans = 0;
  for (int i = 1; i < N; i++){
    if (s2[i - 1] == s2[i]){
      C++;
      ans += C;
    } else {
      C = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	int roop;
	int swaped=0;
	for(roop=0;roop<N;roop++){
		cin >> A[roop];
	}
	int roop2,minrp2;
	for(roop=0;roop<N;roop++){
		minrp2=roop;
		for(roop2=roop;roop2<N;roop2++){
			if(A[roop2]<A[minrp2])
				minrp2=roop2;
		}
		if(minrp2-roop){
			swap(A[roop],A[minrp2]);
			swaped++;
		}
	}
	for(roop=0;roop<N;roop++){
		cout << A[roop];
		if(roop<N-1){
			cout << " ";
		}else{
			cout << endl;
		}
	}
	cout << swaped << endl;
	return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

class graph
{
public:
	struct edge
	{
		ll to,cost;
		// bool operator<(const edge& e) const
  //   	{
  //       	return cost > e.cost;
  //   	}
	};

	vector<vector<edge> > e;  //隣接リスト
	vector<bool> used;
	vector<int> value;
	bool flag = true;

	graph(int n): e(n),used(n),value(n){}

	void dfs(ll r)
	{
		if(used[r]) return;
		used[r] = true;
		for(int i = 0; i < e[r].size(); i++){
			if(e[r][i].cost>=0){
				if(used[e[r][i].to]){
					if(value[e[r][i].to] - value[r] != e[r][i].cost){
						flag = false;
						return;
					}
				}else{
					value[e[r][i].to] = value[r] + e[r][i].cost;
				}
			}else{
				if(used[e[r][i].to]){
					if(value[e[r][i].to] - value[r] != e[r][i].cost){
						flag = false;
						return;
					}
				}else{
					value[e[r][i].to] = value[r] + e[r][i].cost;
				}
			}
			dfs(e[r][i].to);
		}
		return;
	}


	void add_edge(ll from,ll to,ll cost)
	{
		e[from].push_back((edge){to,cost});
		e[to].push_back((edge){from,-cost});  //undirected
	}
};

int main()
{
	int n,m;
	cin >> n >> m;
	vector<int> l(m),r(m),d(m);
	graph G(n);
	for(int i = 0; i < m; i++){
		cin >> l[i] >> r[i] >> d[i];
		l[i]--;
		r[i]--;
		G.add_edge(l[i],r[i],d[i]);
	}

	for(int i = 0; i < n; i++){
		if(!G.flag) break;
		if(!G.used[i]){
			G.value[i] = 0;
			G.dfs(i);
		}
	}

	cout << (G.flag?"Yes":"No") << endl;

	return 0;
}

Measured memory_bytes: 17536
#include<iostream>
using namespace std;
using ll = long long;

ll mod = 1e9 + 7,dp[110][10];
int h, w, k;

int main(){
    cin >> h >> w >> k;
    dp[0][0] = 1, k--;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < (1 << (w - 1)); j++){
            bool out = true;
            for (int k = 0; k < w - 2; k++){
                if (j & (1 << k) && j & (1 << (k + 1)))out = false;
            }
            if (!out)continue;
            int p[w];
            for (int k = 0; k < w; k++)p[k] = k;
            for (int k = 0; k < w - 1; k++){
                if (j & (1 << k))swap(p[k], p[k + 1]);
            }
            for (int k = 0; k < w; k++){
                dp[i + 1][p[k]] += dp[i][k];
                dp[i + 1][p[k]] %= mod;
            }
        }
    }
    cout << dp[h][k] << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
	char S[20];
	int S_len, x ,i;
	do{
		scanf("%s",S);
		S_len = strlen(S);
	}while(S_len < 3 || S_len > 20);
	srand(time(NULL));
	x = rand() % (S_len - 2);
	for(i=1;i <=3;i++){
	printf("%c",S[x]);
	x++;
	}
	return 0;
}

Measured memory_bytes: 2072
n = int(input())
h = list(map(int, input().split()))
t = 0
result = 0
for i in range(n - 1):
  if h[i + 1] <= h[i]:
    t += 1
  else:
    result = max(t, result)
    t = 0
result = max(t, result)
print(result)

Measured memory_bytes: 20508
def main():
  import sys
  buf=sys.stdin.buffer
  h,w=map(int,buf.readline().split())
  s=buf.readline()
  a=b=x=y=s[0]==35
  d=[(b,a)]
  d_add=d.append
  for i in range(1,w):
    f=s[i]==35
    b+=a^f
    a=f
    d_add((b,a))
  for s in buf.read().split():
    f=s[0]==35
    y+=x^f
    b=y
    a=x=f
    p=[(b,a)]
    p_add=p.append
    for i in range(1,w):
      f=s[i]==35
      b+=a^f
      c,g=d[i]
      c+=f^g
      if b>c:b=c
      a=f
      p_add((b,a))
    d=p
  print(b+1>>1)
main()

Measured memory_bytes: 3064
class UnionFind:
    def __init__(self, N):
        # negative value: represents the root of a tree; its absolute value is the size of the tree
        # positive value: the parent's index
        self.vertices = [-1 for _ in range(N)]
        self.rank = [0] * N
        
    def find(self, v):
        if self.vertices[v] < 0: # v is a root
            return v
        else:
            # path compression: reconnect v to the root
            self.vertices[v] = self.find(self.vertices[v])
            return self.vertices[v]
        
    def union(self, u, v):
        s1 = self.find(u) # the root of the tree including vertex u
        s2 = self.find(v) # the root of the tree including vertex v
        
        if s1 == s2: # u and v is in the same tree
            return False
        
        if self.rank[s1] > self.rank[s2]: # the tree including u is taller
            self.vertices[s1] += self.vertices[s2] # update the size of the bigger tree
            self.vertices[s2] = s1
        else: # the tree including v is taller
            self.vertices[s2] += self.vertices[s1] # update the size of the bigger tree
            self.vertices[s1] = s2
            if self.rank[s1] == self.rank[s2]:
                self.rank[s2] += 1
        return True
        
    def is_connected(self, u, v):
        return self.find(u) == self.find(v)
    
    def size(self, v):
        return -self.vertices[self.find(v)]

N, M = map(int, input().split())
E = []
for _ in range(M):
    a, b = map(int, input().split())
    E.append((a, b))
    
ans = 0
for i in range(M):
    uf = UnionFind(N)
    edges = [e for j, e in enumerate(E) if j != i]
    for a, b in edges:
        uf.union(a-1, b-1)
    if len([v for v in uf.vertices if v < 0]) >= 2:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
//#include <iomanip>
#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<int> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,p ;
	cin >> n >> p ;
	string s ; cin >> s ;
	if(p==2||p==5){
		ll ans = 0 ;
		for(int i=0;i<n;i++){
			if((s.at(i)-'0')%p==0){
				ans += i+1 ;
			}
		}
		cout << ans << endl ;
		return 0 ;
	}
	vll rem(n+1,0) ;
	vll cnt(p,0) ;
	cnt.at(0) = 1 ;
	ll ten = 1 ;
	ll ans = 0 ;
	for(int i=n-1;i>=0;i--){
		ll sub = s.at(i)-'0' ;
		sub = sub*ten%p ;
		sub = (sub+rem.at(i+1))%p ;
		ans += cnt.at(sub) ;
		cnt.at(sub)++ ;
		rem.at(i) = sub ;
		ten = ten*10%p ;
//		cout << sub << endl ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 1412
h,w,d=gets.split(" ").map(&:to_i)
h.times{|i|
	w.times{|j|
		mode1=((i+j)/d).to_i%2
		mode2=((h-1-i+j)/d).to_i%2
		print("RGBY"[mode1|(mode2<<1)])
	}
	puts ""
}

Measured memory_bytes: 2044