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

int main() {
    string s,t;cin>>s>>t;
    int cnt = 0;
    for (int i = 0; i < s.length(); ++i) {
        if(s[i] != t[i]) cnt++;
    }
    cout<<cnt<<'\n';
    return 0;
}

Measured memory_bytes: 3896
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

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

  string S;
  cin >> S;

  int Q;
  cin >> Q;

  vector<int> K;
  ll k;
  for (int i = 0; i < Q; ++i) {
    cin >> k;
    K.push_back(k);
  }

  for (int k : K) {
    fprintf(stderr, "k: %d\n", k);
    ll ans = 0;
    map<string, ll> counter;

    for (int i = 0; i < N; ++i) {
      char ch = S[i];

      switch(ch) {
        case 'D':
          counter["D"]++;
          break;
        case 'M':
          counter["M"]++;
          counter["DM"] += counter["D"];
          break;
        case 'C':
          ans += counter["DM"];
          break;
        default:
          // NOOP
          break;
      }

      if (i >= k - 1) {
        char c = S[i - k + 1];

        switch(c) {
          case 'D':
            counter["D"]--;
            counter["DM"] -= counter["M"];
            break;
          case 'M':
            counter["M"]--;
            break;
          default:
            // NOOP
            break;
        }
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5300
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
    int d;
    cin >> d;
    vector<int> c(26);
    rep(i, 26) cin >> c[i];
    vector<vector<int>> s(d, vector<int>(26));
    rep(i, d) rep(j, 26) cin >> s[i][j];
    int t;
    vector<int> last(26, -1);
    int satisfy = 0;
    vector<int> ans(365);
    rep(i, 365) {
        int an;
        rep(j, 26) {
            int sa = satisfy;
            vector<int> la = last;
            sa += s[i][j];
            la[j] = i;
            int decrease = 0;
            rep(k, 26) decrease += c[k] * (i - last[k]);
            sa -= decrease;
            if (chmax(satisfy, sa))
                an = j;
        }
        ans.push_back(an);
    }
	rep(i,365)
        cout << ans[i]+1 << endl;
}

Measured memory_bytes: 3664
#include <stdio.h>
#include <math.h>

int main()
{
	double x1, y1, x2, y2, dx, dy;
	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	dx = x1 - x2;
	dy = y1 - y2;
	printf("%.5f\n", sqrt((dx * dx) + (dy * dy)));
	return 0;
}


Measured memory_bytes: 2052
#include <stdio.h>
#define N 1000001

int spf[N], u[N], s[17], d, i, k;
char* r = "pairwise";

int gcd(a, b, t) { while (b)t = b, b = a %= b, a = t; return a; }

main(j) {
    while (++i < N)spf[i] = i;
    for (i = 2; i * i < N; i++) {
        for (j = i * i; j < N; j += i) {
            if (spf[j] == j)
                spf[j] = i;
        }
    }
    for (scanf("%*d"); ~scanf("%d", &j); k = 0) {
        d = gcd(d, j);
        for (; j > 1; j /= spf[j]) {
            i = spf[j];
            if (u[i]) r = "setwise";
            s[k++] = i;
        }
        while(k--)u[s[k]] = 1;
    }
    printf("%s coprime\n", d > 1 ? "not" : r);
    return 0;
}


Measured memory_bytes: 9500
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
    int a, b, x;
    cin >> a >> b >> x;
    if(a > x){
        cout << "NO" << endl;
    }else if(a+b >= x){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

ll n, k;

int main() {
	cin>>n>>k;
	ll a[n+1];
	for (int i=1; i<=n; i++) {
		cin>>a[i];
	}
	bool stop=0, b[n+1];
	memset(b, 0, sizeof(b));
	b[1]=1;
	ll pos=1, u[n+1], ke=2, start;
	u[1]=1;
	while (!stop) {
		pos=a[pos];
		if (!b[pos]) {
			b[pos]=1;
			u[ke]=pos;
			ke++;
		}
		else stop=1;
	}
	for (int i=1; i<ke; i++) {
		if (u[i]==pos) start=i;
	}
	ll ulang=ke-start;
	if (k<start) cout<<u[k+1]<<endl;
	else {
		ll ans=(k-start+1)%ulang;
		cout<<u[ans+start]<<endl;
	}
}



Measured memory_bytes: 6792
#include<bits/stdc++.h>
using namespace std;
#define INF "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

string chmin( string a, string b){
  if(a.size() != b.size()) return (a.size() < b.size() ? a : b);
  return (a < b ? a : b);
}

int main(){
  string dp1[10][10],dp2[10][1 << 10];
  int n;
  vector< string > str;

  while( cin >> n, n){
    fill_n( *dp1, 10 * 10, INF);
    fill_n( *dp2, 10 * 1 << 10, INF);
    str.resize(n);
    for(int i = 0; i < n; i++){
      cin >> str[i];
    }
    unsigned bit = 0u;
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(i == j || (bit >> i) & 1 || (bit >> j) & 1) continue;
        if(str[i].find(str[j]) != string::npos) bit |= 1 << j;
      }
    }
  
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
        if(i == j) continue;
        dp1[i][j] = str[j];
        if((bit >> i) & 1 || (bit >> j) & 1) continue;
        for(int k = 0; k < str[i].size(); k++){
          if(str[i].substr(k) == str[j].substr(0, str[i].substr(k).size())){
            dp1[i][j] = str[j].substr(str[i].substr(k).size());
            break;
          }
        }
      }
    }
  
    for(int i = 0; i < n; i++){
      dp2[i][bit|(1 << i)] = str[i];
    }
    for(int i = 0; i < 1 << n; i++){
      for(int j = 0; j < n; j++){
        if(dp2[j][i|bit] == INF) continue;
        for(int k = 0; k < n; k++){
          if(j == k || ((i|bit) >> k) & 1) continue; //mumumu??
          dp2[k][i|bit|(1 << k)] = chmin( dp2[k][i|bit|(1 << k)], dp2[j][i|bit] + dp1[j][k]);
        }
      }
    }
    string ret = INF;
    for(int i = 0; i < n; i++){
      ret = chmin( ret, dp2[i][(1 << n) - 1]);
    }
  
    cout << ret << endl;
  }
}

Measured memory_bytes: 2848
N, A, B = map(int, input().split())

if N == 1:
    if A == B:
        print(1)
    else:
        print(0)
else:
    if A > B:
        print(0)
    elif A == B:
        print(1)
    else:
        print((A+B*(N-1))-(A*(N-1)+B)+1)


Measured memory_bytes: 3060
//
//  codefestival question1
//

#include <stdio.h>

int main()
{
  int i;
  int flagc = 0, flagf = 0;

  char s[101];

  scanf("%s", s);

  for(i = 0;i < 100;i++){
    if(s[i] == 'c' || s[i] == 'C') flagc = 1;
    if(flagc){
      if(s[i] == 'f' || s[i] == 'F') flagf = 1;
    }

    if(flagc && flagf){
      printf("Yes\n");
      return 0;
    }
  }

  printf("No\n");
  return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.math.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    int a= sc.nextInt();
    String s=sc.next();
    if(a>=3200) {
      System.out.println(s);
    } else {
      System.out.println("red");
    }
    
  }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // kondisi pertama gua perlu ceck dalam waktu t possible gak untuk trevel dari point x1,y1 ke xi, yi
    // ada urusannya dengan ganjil dan genap, . kalo distancenya ganjil time juga harus ganjil.
    // kalo distance genap time juga harus genap
    int n; cin >> n;
    int currt = 0;
    int currx = 0;
    int curry = 0;
    for (int i = 0; i < n; i++) {
        int t, x, y; cin >> t >> x >> y;
        int d = abs(currx - x) + abs(curry - y);
        int dt = abs(t - currt);
        if(d > dt || dt % 2 != d % 2) {
            cout << "No"; return 0;
        }
        currx = x; curry = y; currt = t;
    }
    cout << "Yes";
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            var giftList = new List<Gift>();

            for(int k = 1; k <= N; k++)
            {
                string[] input = Console.ReadLine().Split(' ');
                giftList.Add(new Gift(double.Parse(input[0]), input[1]));
            }

            double s = 0;

            foreach(var gift in giftList)
            {
                s += gift.ToYen();
            }

            Console.WriteLine(s);

        }
    }

    class Gift
    {
        public double mount;
        public string unit;

        public Gift(double mount, string unit)
        {
            this.mount = mount;
            this.unit = unit;
        }

        public double ToYen()
        {
            if(unit == "JPY")
            {
                return mount;
            }
            else
            {
                return mount * 380000;
            }
        }


    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdlib>
const int maxn = 205;
using namespace std;


int m,n;
int d[15][15],maze[maxn][maxn];

void floy(){
    for(int k = 0 ; k < 10 ; k++){
        for(int i = 0 ; i < 10 ; i++){
            for(int j = 0 ; j < 10 ; j++){
                d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
            }
        }
    }
}

int main(){
    while(~scanf("%d%d",&n,&m)){
        for(int i = 0 ; i < 10 ; i++){
            for(int j = 0 ; j < 10 ; j++){
                scanf("%d",&d[i][j]);
            }
        }
        for(int i = 1 ; i <= n ; i++){
            for(int j = 1 ; j <= m ; j++){
                scanf("%d",&maze[i][j]);
            }
        }
        int sum = 0;
        floy();
        for(int i = 1 ; i <= n ; i++){
            for(int j = 1 ; j <= m ; j++){
                if(maze[i][j] != -1){
                    sum += d[maze[i][j]][1];
                }
            }
        }
        printf("%d\n",sum);
    }
    return 0;
}
/*
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8
5 5
0 999 999 999 999 999 999 999 999 999
999 0 999 999 999 999 999 999 999 999
999 999 0 999 999 999 999 999 999 999
999 999 999 0 999 999 999 999 999 999
999 999 999 999 0 999 999 999 999 999
999 999 999 999 999 0 999 999 999 999
999 999 999 999 999 999 0 999 999 999
999 999 999 999 999 999 999 0 999 999
999 999 999 999 999 999 999 999 0 999
999 999 999 999 999 999 999 999 999 0
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
3 5
0 4 3 6 2 7 2 5 3 3
4 0 5 3 7 5 3 7 2 7
5 7 0 7 2 9 3 2 9 1
3 6 2 0 2 4 6 4 2 3
3 5 7 4 0 6 9 7 6 7
9 8 5 2 2 0 4 7 6 5
5 4 6 3 2 3 0 5 4 3
3 6 2 3 4 2 4 0 8 9
4 6 5 4 3 5 3 2 0 8
2 1 3 4 5 7 8 6 4 0
3 5 2 6 1
2 5 3 2 1
6 9 2 5 6
*/

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
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; }

int main() {
    ll n; cin >> n;
    if (n % 2 == 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 0;
    ll d = 10;
    while (d <= n) {
        ans += n / d;
        d *= 5;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
S = input()
mod = 2019
L = [0]*mod
n = 0
for i in range(len(S)-1, -1, -1):
    n += int(S[i])*pow(10, len(S)-i-1, mod)
    n %= mod
    L[n] += 1

ans = 0
L[0] += 1
for l in L:
    ans += l*(l-1)//2
print(ans)

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

const int MAX_N = 12;
const int MAX_V = 1e7+1;
int D, G;
int p[MAX_N];
int c[MAX_N];

int go(int bf)
{
	int pt = 0, pb = 0;
	for(int i=0;i<D;++i)if(bf>>i&1){
		pt += p[i+1]*100*(i+1)+c[i+1];
		pb += p[i+1];
	}
	for(int i=D-1;pt<G&&i>=0;--i)if(!(bf>>i&1)){
		int diff = G-pt;
		int point = 100*(i+1);
		int so = min(p[i+1]-1, (diff+point-1)/point);
		pt += so*point;
		pb += so;
	}
	if(pt >= G) return pb;
	else return -1;
}

void solve()
{
	int ans = 2000;
	for(int b=0;b<(1<<D);++b){
		int best = go(b);
		if(best != -1) ans = min(ans, best);
	}
	cout << ans << '\n';
}

int main()
{
	cin >> D >> G;
	for(int i=1;i<=D;++i) cin >> p[i] >> c[i];
	solve();
	return 0;
}

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

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

typedef pair<int,int> P;

struct data{
    int t,pc,stu,s;
};
void solve(){
    int N,M;cin>>N>>M;
    if(N==0)exit(0);
    int r;cin>>r;

    vector<data>v;
    vector<vector<data>>use;
    use.resize(N+1);
    REP(i,r){
        int t,n,m,s;
        cin>>t>>n>>m>>s;
        v.push_back({t,n,m,s});
        use[n].push_back({t,n,m,s});
    }

    int q;cin>>q;
    while(q--){
        int ts,te,m;cin>>ts>>te>>m;
        vector<int>cnt(1261);
        REP(i,N+1){
            for(int j = 0;j<(int)use[i].size();j+=2){
                if(use[i][j].stu==m){
                    for(int t=use[i][j].t;t<(int)use[i][j+1].t;t++)cnt[t]++;
                }
            }
        }
        int res = 0;
        for(int t = ts;t<te;t++){
            if(cnt[t])res++;
        }
        cout<<res<<endl;
    }

}

signed main(){
    while(true)solve();
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;


int main(){
  int N, K;
  cin >> N >> K;
  map<int, int> A;
  rep(i, N) A[i] = 0;
  rep(i, K){
    int d;
    cin >> d;
    rep(j, d){
      int a;
      cin >> a;
      a--;
      A[a]++;
    }
  }
  int ans = 0;
  for (auto a : A){
    if (a.second == 0) ans++;
  }
  cout << ans << endl;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const int MAX=1e5+100;

vector<ll> dijkstra(int V, int s, vector<vector<ll>> &G) {
  vector<ll> d(V,LLONG_MAX);d[s]=0;
  priority_queue<P,vector<P>,greater<P>> q;q.push({0,s});
  while (!q.empty()) {
    int precost,v;tie(precost,v)=q.top();q.pop();
    if (d[v]<precost) continue;
    for (ll n:G[v]) {
      if (d[n]>d[v]+1) {
        d[n] = d[v]+1;
        q.push({d[n],n});
      }
    }
  }
  return d;
}

int main() {
  // u,vそれぞれからダイクストラを計算
  // 高橋より青木の方が距離が遠くて、かつ青木の距離が最大になる点に高橋が逃げるのが
  // 最も長引く
  // 終了する点はその一歩手前の点なので、−１する
  int N,u,v;cin>>N>>u>>v;
  u--;v--;
  vector<vector<ll>> G(N);
  REP(i,N-1) {
    int a,b;cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<ll> d1 = dijkstra(N,u,G);
  vector<ll> d2 = dijkstra(N,v,G);

  ll ans = 0;
  // 必ずd1[i]<d2[i]となる点は存在する
  REP(i,N) {
    if (d1[i]>=d2[i]) continue;
    mmax(ans,d2[i]);
  }
  OUT(ans-1);

  return 0;
}

Measured memory_bytes: 9632
n = gets.to_i
a = n.times.map {gets.split.map(&:to_i)}

c = Array.new(n) {Array.new(n, 0)}
n.times do |k|
    n.times do |s|
        next if k == s
        (s+1).upto(n-1) do |f|
            x = a[s][k] + a[k][f]
            if x < a[s][f]
                p -1
                exit
            elsif x == a[s][f]
                c[s][f] += 1
            end
        end
    end
end

ans = 0
n.times do |i|
    (i+1).upto(n-1) do |j|
        ans += a[i][j] if c[i][j] == 1
    end
end

p ans

Measured memory_bytes: 15816
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V 
import qualified Data.Vector.Mutable as VM
import Control.Monad 
import Debug.Trace

main :: IO ()
main = breads >>= main'
    where
        main' [n, m, q] = replicateM m breads >>= calc n >>= main'' q
        main'' q vs = replicateM q breads >>= printRes . solve vs
        printRes = mapM_ print 

type V2 a = V.Vector (V.Vector a)
type MV2 a = VM.IOVector (VM.IOVector a)

calc :: Int -> [[Int]] -> IO (V2 Int)
calc n lrs = initialize >>= fill >>= accumulate >>= finalize
    where
        initialize = VM.replicateM (n + 1) $ VM.replicate (n + 1) 0
        fill vs = vs <$ mapM_ (\[p, q] -> modifyM vs succ (p, q)) lrs
        accumulate vs = vs <$ mapM_ mf [(x, y) | x <- [1..n], y <- [1..n]]
            where
                mf (i, j) = do
                    x <- readM vs (i - 1, j - 1)
                    y <- readM vs (i - 1, j)
                    z <- readM vs (i, j - 1)
                    modifyM vs (\v -> v + y + z - x) (i, j)
        finalize = V.unsafeFreeze >=> fmap traceShowId . V.mapM V.unsafeFreeze

solve :: V2 Int -> [[Int]] -> [Int]
solve vs = map mf
    where
        mf [p, q] = vs `at` (q, q) + vs `at` (p - 1, p - 1) - vs `at` (p - 1, q) - vs `at` (q, p - 1)

at :: V2 a -> (Int, Int) -> a
at vs (x, y) = vs V.! x V.! y

readM :: MV2 a -> (Int, Int) -> IO a
readM vs (x, y) = VM.unsafeRead vs x >>= flip VM.unsafeRead y

writeM :: MV2 a -> (Int, Int) -> a -> IO ()
writeM vs (x, y) v = VM.unsafeRead vs x >>= (\xs -> VM.unsafeWrite xs y v)

modifyM :: MV2 a -> (a -> a) -> (Int, Int) -> IO ()
modifyM vs f (x, y) = VM.unsafeRead vs x >>= (\xs -> VM.unsafeModify xs f y)

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 133372
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>>vvi;

int main(){
  string s,t;
  cin>>s>>t;
  int n=s.size();
  vector<int>count(n);
  map<char,int>ma;
  rep(i,n){
    ma[s[i]]++;
    count[i]=ma[s[i]];
  }
  bool ans=true;
  map<char,int>mama;
  rep(i,n){
    mama[t[i]]++;
    if(count[i]!=mama[t[i]])ans=false;
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M,K;
const ll mo=998244353;

ll comb(ll N_, ll C_) {
	const int NUM_=400001;
	static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
	if (fact[0]==0) {
		inv[1]=fact[0]=factr[0]=1;
		for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
		for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	}
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}

ll modpow(ll a, ll n=mo-2) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>K;
	
	ll sum=0;
	for(i=0;i<=K;i++) {
		sum+=comb(N-1,i)*M%mo*modpow(M-1,N-i-1)%mo;
	}
	cout<<sum%mo<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

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

    return 0;
}


Measured memory_bytes: 3624
use proconio::input;


fn main() {
    input!{
        n:usize,
        k:i32,
        }
    let mut a = Vec::new();
    
    for i in 0..k {
          input! {
            d: i32,
            mut A: [i32; d],
          }

          a.append(&mut A);
  }
  	  a.sort();
      a.dedup();
      println!("{}",n - a.len());
}

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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N + 1);
  vector<int64_t> B(N);
  int64_t kill = 0;
  int64_t surplus = 0;
  for (int i = 0; i < N + 1; i++){
    cin >> A[i];
  }
  for (int i = 0; i < N; i++){
    cin >> B[i];
  }
  for (int i = 0; i < N; i++){
    if (A[i] > B[i] + surplus){
      kill += B[i] + surplus;
      surplus = 0;
    }
    else if (A[i] < surplus){
      kill += A[i];
      surplus = B[i];
    }
    else {
      kill += A[i];
      surplus = B[i] - (A[i] - surplus);
    }
  }
  cout << kill + min(A[N], surplus)<< endl;
}


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

int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    vector<vector<int>> gf(n), gb(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        gf[a-1].push_back(b-1);
        gf[b-1].push_back(a-1);
    }
    rep(i,k) {
        int c,d;
        cin >> c >> d;
        gb[c-1].push_back(d-1);
        gb[d-1].push_back(c-1);
    }

    vector<unordered_set<int>> p;
    vector<int> pidx(n, -1);

    rep(i,n) {
        if(pidx[i] >= 0) continue;

        unordered_set<int> s;
        p.push_back(s);

        vector<bool> seen(n, false);
        queue<int> que;
        que.push(i);
        seen[i] = true;

        while(!que.empty()) {
            int cv = que.front();
            que.pop();
            p.back().insert(cv);
            pidx[cv] = p.size()-1;

            for(auto nv:gf[cv]) {
                if(seen[nv]) continue;
                que.push(nv);
                seen[nv] = true;
            }
        }
    }

    rep(i,n) {
        int cnt = p[pidx[i]].size() - gf[i].size() - 1;
        for(auto bl:gb[i])
            if(p[pidx[i]].count(bl)) --cnt;
        cout << cnt << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 20864
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;
int n,A,B,C,x;
vector<int> v;

int dfs(int t,int a,int b,int c){
    if(t==n)  return min(a,min(b,c))>0 ? abs(A-a)+abs(B-b)+abs(C-c)-30 : 1e9;
    int k1=dfs(t+1,a,b,c);
    int k2=dfs(t+1,a+v[t],b,c)+10;
    int k3=dfs(t+1,a,b+v[t],c)+10;
    int k4=dfs(t+1,a,b,c+v[t])+10;
    return min(min(k1,k2),min(k3,k4));   
}
int main(){
    cs
    cin>>n>>A>>B>>C;
    rep(i,n) {cin>>x;v.push_back(x);}
    cout<<dfs(0,0,0,0);
}

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

public class Hello
{
    public static void Main()
    {
        var sd = Console.ReadLine().Trim();
        var t = Console.ReadLine().Trim();
        var a = sd.ToCharArray();
        var tL = t.Length;
        var aL = sd.Length;
        var ss = new List<string>();
        for (int i = 0; i <= aL - tL; i++)
        {
            for (int j = 0; j < tL; j++)
                if (sd[i + j] != '?' && sd[i + j] != t[j]) goto next;
            ss.Add(createS(sd, t, i));
            next:;
        }
        if (ss.Count() == 0) Console.WriteLine("UNRESTORABLE");
        else Console.WriteLine(ss.OrderBy(x => x).First());
    }
    public static string createS(string sd, string t, int d)
    {
        var a = sd.ToCharArray();
        for (int i = 0; i < t.Length; i++) a[i + d] = t[i];
        for (int i = 0; i < a.Length; i++)
            if (a[i] == '?') a[i] = 'a';
        return new string(a);
    }
}


Measured memory_bytes: 13652
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long pow = 1;
		for(int i = 0;i <n;i++) {
			pow = pow *(i+1);
			pow = pow % 1000000007;
		}
		System.out.println(pow);
	}

}


Measured memory_bytes: 21844
// Problem : B - Postdocs
// Contest : AtCoder - NOMURA Programming Competition 2020
// URL : https://atcoder.jp/contests/nomura2020/tasks/nomura2020_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;	

#define FOR(i,a,b) for(int i = (a); i <= (b); ++i)
#define FORD(i,a,b) for(int i = (a); i >= (b); --i)
#define RI(i,n) FOR(i,1,(n))
#define REP(i,n) FOR(i,0,(n)-1)
#define mini(a,b) a=min(a,b)
#define maxi(a,b) a=max(a,b)
#define pb push_back
#define st first
#define nd second
#define sz(w) (int) w.size()
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<pii, int> para;
const ll inf = 1e18 + 7;
const ll maxN = 1e6 + 5;
const ll MOD = 1e9 + 7;

// sprawdz MODULO!
int main() {
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s;
	cin >> s;
	REP(i, sz(s)) {
		if (s[i] == '?') s[i] = 'D';
	}
	cout << s;
	return 0;
}
 


Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i%2==0 && a[i]%2==1)x++;
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 3624
import sys
r,c = map(int,input().split())
masume = [[0 for i in range(c)] for j in range(r)]
for i in range(r):
	masume[i] = list(input())

for ri in range(r):
	for ci in range(c):
		if masume[ri][ci] == '#':
			sys.stdout.write(masume[ri][ci])
			continue
		count = 0
		for ar in [-1,0,1]:
			for ac in [-1,0,1]:
				chkr = ri + ar
				chkc = ci + ac
				if chkr >= 0 and chkr < r and chkc >= 0 and chkc < c and masume[chkr][chkc] == '#':
					count+= 1
		sys.stdout.write(str(count))
	print("")

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
using namespace std;

int main()
{
  int N, M;
  while (cin >> N >> M && N != 0) {
    vector<vector<pair<int,int> > > g(N);
    for (int i = 0; i < N; i++) {
      int k;
      cin >> k;
      for (int j = 0; j < k; j++) {
        int c, d;
        cin >> c >> d;
        g[i].push_back(make_pair(c, d));
      }
    }

    vector<vector<vector<int> > > dp(N);
    for (int i = 0; i < N; i++) {
      dp[i].resize(g[i].size(), vector<int>(M+1, numeric_limits<int>::max()/2));
    }
    for (int i = 0; i < g[0].size(); i++) {
      dp[0][i][0] = 0;
    }
    for (int i = 0; i < g[1].size(); i++) {
      dp[1][i][1] = 0;
    }

    int ans = numeric_limits<int>::max();
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < g[i].size(); j++) {
        for (int m = 0; m <= M; m++) {
          if (i+1 == N) {
            ans = min(ans, dp[i][j][m]);
          } else {
            for (int k = 0; k < g[i+1].size(); k++) {
              dp[i+1][k][m] = min(dp[i+1][k][m], dp[i][j][m] + (g[i][j].second + g[i+1][k].second)*abs(g[i][j].first - g[i+1][k].first));
            }

            if (i < N-1 && m < M) {
              if (i+2 == N) {
                ans = min(ans, dp[i][j][m]);
              } else {
                for (int k = 0; k < g[i+2].size(); k++) {
                  dp[i+2][k][m+1] = min(dp[i+2][k][m+1], dp[i][j][m] + (g[i][j].second + g[i+2][k].second)*abs(g[i][j].first - g[i+2][k].first));
                }
              }
            }
          }
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

int main() {
  int a,b,c,d,e;
  cin >> a;
  b=a/1000;
  c=a%1000/100;
  d=a%100/10;
  e=a%10;
  if((c==d)&&(b==d||c==e))
    cout<< "Yes" <<endl;
  else
    cout<< "No" <<endl;
}

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

int h, n, dp[40001], a[1001], b[1001], dif, rez = inf;

int main()
{
    cin >> h >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i <= h; ++i) dp[i] = inf;

    dp[h] = 0;
    for (int i = 1; i <= n; ++i)
    {
        for (int j = h; j >= 0; --j)
        {
            dp[max(0, j - a[i])] = min(dp[max(0, j - a[i])], dp[j] + b[i]);
        }
        rez = min(rez, dp[0]);
    }
    cout << rez;
    return 0;
}


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

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

void solve(long long K) {
    if (K < 10) {
        cout << K << endl;
        return;
    }

    queue<int> que;
    for (int i = 1; i < 10; i++) {
        que.push(i);
    }
    int k = 0;

    while (true) {
        k++;
        auto x = que.front();
        que.pop();
        // cout << k << " " << x << endl;
        if (k == K) {
            cout << x << endl;
            return;
        }

        if (x % 10 != 0) {
            que.push(x * 10 + x % 10 - 1);
        }
        que.push(x * 10 + x % 10);
        if (x % 10 != 9) {
            que.push(x * 10 + x % 10 + 1);
        }
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long K;
    scanf("%lld", &K);
    solve(K);
    return 0;
}


Measured memory_bytes: 1792
/*
    In the name of
        "ALLAH"
    And say "AL-HAMD-U-LILLAH"
*/

#include<bits/stdc++.h>
#define   ll   long long
#define   llu  unsigned long long
#define   _    printf("\n")
int      take() {
    int n;
    scanf("%d",&n);
    return n;

}
double  ttake() {
    double n;
    scanf("%lf",&n);
    return n;
}
ll     takes() {
    ll n;
    scanf("%lld",&n);
    return n;

}

#define  Int            take()
#define  Dnt            ttake()
#define  LL             takes()
#define  done           {return 0;}
#define  fr(i,x,n,a)    for(int i=x;i<=n;i+=a)
#define  FR(a,b,x)      for(int i=(a);i<=(b);i+=(x))
#define  rfr(i,x,n,a)   for(int i=x;i>=n;i--)
int      cas;
#define  print          printf("Case %d:",++cas)
#define  vi             vector<int>
#define  vl              vector<ll>
#define  pb              push_back
#define  pii             pair<int,int>
#define  vii             vector<pii>
#define  pll             pair<ll,ll>
#define  pil             pair<int,ll>
#define  pli             pair<ll,int>
#define  mk              make_pair
#define  fill(x,v)       memset(x,v,sizeof x)

using    namespace      std;

bool     approximatelyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     essentiallyEqual(float a, float b, float epsilon) {
    return fabs(a - b) <= ( (fabs(a) > fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyGreaterThan(float a, float b, float epsilon) {
    return (a - b) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}

bool     definitelyLessThan(float a, float b, float epsilon) {
    return (b - a) > ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
}
#define  STR            {struct info}
#define  dbg(x)         {cout<<"ekhane"<<x<<endl;}
#define  SS             second
#define  FF             first
#define  PQ             priority_queue
#define  great          greatest
#define  less           lesser
#define  mii            map<int,int>
#define  mil            map<int,ll>
#define  mll            map<ll,ll>
#define  msb            map<string,bool>
#define  V              vector
#define  M              100005
#define  pf             printf
#define  inf            INT_MAX
//////////////////////////////////////////

int main( ){
    int tc = 1 ;
    while( tc-- ){
        int t = 0 , thr = 0 , n = Int , arr[ n + 1 ] , ans = 0 ;
        fr( i , 1 , n , 1 ){
            int x = Int ;
            int u = x ;
            while( u % 2 == 0 ) t++ , u /= 2 ;
        }
        cout<<t<<endl;
    }
    done ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[110000];

main(){
  ll ans=0;
  string s;
  cin>>s;
  ll x=s.length()/2;
  rep(i,0,x){
    if(s[i]!=s[s.length()-1-i])ans++;
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n; cin >> n;
  V<> h(n), p(n); for (int i = 0; i < n; ++i) cin >> h[i] >> p[i];
  V<> id(n); iota(begin(id), end(id), 0);
  sort(begin(id), end(id), [&](int i, int j) { return h[i] + p[i] < h[j] + p[j]; });
  constexpr int inf = 2e9 + 10;
  VV<> dp; assign(dp, 2, n + 1, inf);
  dp[0][0] = 0;
  for (int i = 0; i < n; ++i) {
    dp[i + 1 & 1] = dp[i & 1];
    for (int j = 0; j < n; ++j) if (h[id[i]] >= dp[i & 1][j]) {
      dp[i + 1 & 1][j + 1] = min(dp[i + 1 & 1][j + 1], dp[i & 1][j] + p[id[i]]);
    }
  }
  cout << distance(begin(dp[n & 1]), lower_bound(begin(dp[n & 1]), end(dp[n & 1]), inf)) - 1 << '\n';
}

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

int main(){
  int N;
  cin >> N;
  if(N%2==0 && N<6 && N!=2){
    cout << N*2;
  }
  else if(N%2==0){
    cout << N;
  }
  else{
    cout << N*2;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll MOD=(ll)1e9+7;
//}}}

int main(){
  string s;
  cin >> s;
  bool ans = false;
  rep(i, s.size() - 1){
    if(s.substr(i, 2) == "AC") ans = true;
  }
  puts(ans ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

struct edge {
    int to;
    int cost;
    edge(int t, int w) : to(t), cost(w) { }
};

typedef pair<int, int> P;  // first: 最短距離, second: 頂点番号

int V, d[MAX];
vector<edge> G[MAX]; // 隣接リスト表現

void dijkstra(int s) {
    fill(d, d + V, INF);
    d[s] = 0;  // 始点sへの最短距離は0

    priority_queue<P, vector<P>, greater<P> > que;  // 距離が小さい順に取り出せるようgreater<P>を指定
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
        if (d[v] < p.first) {
            continue;
        }
        for (auto e : G[v]) {  // 頂点vから出る辺eを走査
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}


int main(){
  cin>>V;
  repn(i,V){
    G[i].pb(edge((i+1)%V,1));
    G[i].pb(edge((i*10)%V,0));
  }
  dijkstra(1);
  cout<<d[0]+1<<endl;
}


Measured memory_bytes: 16504
import heapq
def main():
    N = int(input())
    A = list(map(int, input().split()))
    AH = sorted([(a, i) for i, a in enumerate(A[:2 * N])], reverse=True)
    AT = sorted(A[-N:])
    ATT = []
    for a in AT:
        heapq.heappush(ATT, -a)
    used = [False] * (2 * N)
    for _, i in AH[:N]:
        used[i] = True

    h = sum(a for a, _ in AH[:N])
    t = sum(AT)
    m = h - t
    hp = N
    for i in reversed(range(N, 2 * N)):
        t += A[i]
        t += heapq.heappushpop(ATT, -A[i])
        if used[i]:
            h -= A[i]
            while AH[hp][1] > i:
                hp += 1
            h += AH[hp][0]
            used[AH[hp][1]] = True
            hp += 1

        m = max(m, h - t)
    return m

print(main())


Measured memory_bytes: 44708
#include <stdio.h>
#include <string>
#include <list>
using namespace std;

int main(void) {
	int n, in;
	scanf("%d",&n);
	list<int> ls;
	char s[20];
	for (int i = 0;i < n;i++) {
		scanf("%s%d", s, &in);
		if (s[0] == 'i') {
			ls.push_front(in);
		}
		else if (s[6] == 'F') {
			ls.pop_front();
		}
		else if (s[6] == 'L') {
			ls.pop_back();
		}
		else if (s[0] == 'd') {
			for (auto itr = ls.begin();itr != ls.end();itr++) {
				if (in == *itr) {
					itr = ls.erase(itr);break;
				}
			}
		}
	}
	for (auto itr=ls.begin();itr!=ls.end();itr++){
		printf("%d", *itr);
		if (itr != --ls.end()) printf(" ");
	}
	printf("\n");;
	return 0;
}


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

int main() {
  int N;
  cin>>N;
if (N%1000/100==N%100/10){
    if(N/1000==N%1000/100||N%100/10==N%10){
    cout<<"Yes"<<endl;
    }else{
     cout<<"No"<<endl;
    }
}else{
     cout<<"No"<<endl;

}

}

Measured memory_bytes: 256
ball = 'A'
while 1:
    try:
        cuplist = list(map(str, input().split(",")))
        if cuplist == ['']:
            break
    except:
        break

    if cuplist[0] == ball:
        ball = cuplist[1]
    elif cuplist[1] == ball:
        ball = cuplist[0]

print(ball)



Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int kurai(int x) {
  int ret = 1;
  while(x >= 10) {
    x /= 10;
    ret++;
  }
  return ret;
}

int baibai(int x) {
  int ret = 1;
  rep(i,x) ret *= 10;
  return ret;
}

int beki(int x,int y) {
  x %= baibai(y);
  x /= baibai(y - 1);
  return x;
}

int main() {
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> data(m);
  rep(i,m) cin >> data[i].first >> data[i].second;
  int ans = 0;
  for(int i = 0; i < 1000; i++) {
    if(kurai(i) != n) continue;
    int check = 0;
    rep(j,m) {
      if(beki(i,n - data[j].first + 1) == data[j].second) check++;
    }
    if(check == m) {
      cout << i << "\n";
      ans++;
      break;
    }
  }
  if(ans == 0) cout << -1 << "\n";
}

Measured memory_bytes: 256
def LIHW(h):
    return [list(map(int, input().split())) for _ in range(h)]


masu = LIHW(3)
ans = "Yes"
for i in range(2):
    if masu[i+1][1]-masu[i+1][0] != masu[0][1]-masu[0][0]:
        ans = "No"
    if masu[i+1][2]-masu[i+1][1] != masu[0][2]-masu[0][1]:
        ans = "No"
for i in range(2):
    if masu[1][i+1]-masu[0][i+1] != masu[1][0]-masu[0][0]:
        ans = "No"
    if masu[2][i+1]-masu[1][i+1] != masu[2][0]-masu[1][0]:
        ans = "No"
print(ans)


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

int main()
{
    // 入力
    int a, b, c;
    cin >> a >> b >> c;
    // 処理
    int ans = b / a;
    if (ans > c)
    {
        ans = c;
    }
    // 出力
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

lines = sys.stdin.readlines()
N, M = map(int, lines[0].split())
X = [int(x) for x in lines[1].split()]

X.sort()

diff = []
for i in range(0, len(X) - 1):
	diff.append(abs(X[i] - X[i+1]))

diff.sort()
if N == 1:
	print(sum(diff))
else:
	print(sum(diff[:-(N-1)]))

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

int main() {
  int H, W;
  cin >> H >> W;//縦横の入力
  int i, j;
  for (i = 0; i < W + 2; i++)
  cout << "#";//最初の行
  cout << endl;
  for (j = 0; j < H; j++) {
  vector<char> vec(W + 2);
  vec.at(0) = '#';
  for (i = 0; i < W; i++)
  cin >> vec.at(i + 1);
  vec.at(W + 1) = '#';//行内での入力
  for (i = 0; i < W + 2; i++)
  cout << vec.at(i);
  cout << endl;//行内での出力
  }
  for (i = 0; i < W + 2; i++)
  cout << "#";//最後の行
  cout << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


    using namespace std;
 
    int main(){
      int n,a,b;
      cin >> n;
      if(n==1)cout << "Hello World" << endl;
      else{
       cin >> a >> b;
        cout << a+b << endl;
      }
      return 0;}

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

#define vec(v) vector<int>(v)
#define be(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define mapci(mp) map<char*,int>(mp)
#define mapcc(mp) map<char*,char*>(mp)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n],mi,ma=-1,y,x;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n);
    ma=a[n-1];
    mi=1e9+1;
    if(ma%2==0){
        ma/=2;
        for(int i=0;i<n-1;i++){
            if(mi>=abs(a[i]-ma)){
            mi=min(mi,abs(a[i]-ma));
            x=a[i];
        }
        }
        cout <<ma*2<<" "<<x<<endl;
    }
    else{
        ma/=2;
        for(int i=0;i<n-1;i++){
            y=abs(a[i]-ma);
            if(mi>y){
                mi=y;
                x=a[i];
            }
            else if(mi==y){
                if(a[i]>ma){
                    mi=y;
                    x=a[i];
                }
            }
        }
        cout <<ma*2+1<<" "<<x<<endl;
    }
    return 0;
}


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

#define fr(i,n) _back
#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int T = 1e5+2;
const int N = 4;
int dp[T][N][N][N];
int choose[T][N][N][N];
int v[T][2];
int n;

int solve(int at, int a, int b, int c) {
    if((a<0) or (b<0) or (c<0)) return 0;
    if(at == n) return 1;
    a = min(a,3); b = min(b,3); c = min(c,3);
    int &r = dp[at][a][b][c];
    if(~r) return r;

    bool x = solve(at+1,a-(v[at][0]==0)+(v[at][1]==0),
            b-(v[at][0]==1)+(v[at][1]==1),
            c-(v[at][0]==2)+(v[at][1]==2));
    bool y = solve(at+1,a+(v[at][0]==0)-(v[at][1]==0),
            b+(v[at][0]==1)-(v[at][1]==1),
            c+(v[at][0]==2)-(v[at][1]==2));

    choose[at][a][b][c] = (x?1:0);

    return r = (x|y);
}

void build(int at, int a, int b, int c) {
    if(at==n) return;
    a = min(a,3);
    b = min(b,3);
    c = min(c,3);
    cout << (char)('A' + v[at][choose[at][a][b][c]]) << endl;
    if(!choose[at][a][b][c]) {;
        build(at+1,a+(v[at][0]==0)-(v[at][1]==0),
            b+(v[at][0]==1)-(v[at][1]==1),
            c+(v[at][0]==2)-(v[at][1]==2));
    } else {
        build(at+1,a-(v[at][0]==0)+(v[at][1]==0),
            b-(v[at][0]==1)+(v[at][1]==1),
            c-(v[at][0]==2)+(v[at][1]==2));
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(dp,-1,sizeof dp);
    cin.tie(0); cout.tie(0);
    int a,b,c;
    cin >> n >> a >> b >> c;
    for(int i = 0; i < n; i++) {
        string s; cin >> s;
        v[i][0] = s[0]-'A', v[i][1] = s[1]-'A';
    }
    if(solve(0,a,b,c)) cout << "Yes" << endl, build(0,a,b,c);
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 63780