akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(j,n) for(int j = 0; j < (n); ++j)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define drep2(j,n) for(int j = (n)-1; j >= 0; --j)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define srep2(j,s,t) for (int j = s; j < t; ++j)
#define srep3(k,s,t) for (int k = s; k < t; ++k)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  vector<pair<string,P>> A(N);
  rep(i,N) {
    string a;
    int b;
    cin >> a  >> b;
    A[i] = make_pair(a,P(b,i));
  }
  sort(rng(A),[](pair<string,P> &l,pair<string,P> &r) {
    if(l.first == r.first) {
      return l.second.first < r.second.first;
    } else {
      return l.first > r.first;
    }
  });
  drep(i,N) {
    cout << A[i].second.second+1<< endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int MO=1e9+7;
int n,k,a[222222];
LL ans,fac[200010],inv[200010],INV[200010];
LL pw(LL x,LL y){
	LL t=1;
	for (;y;y>>=1){
		if (y&1) t=t*x%MO;
		x=x*x%MO;
	}
	return t;
}
LL C(int x,int y){
	return fac[x]*inv[y]%MO*inv[x-y]%MO;
}
struct Poly{
	LL p[1010];
	Poly(){memset(p,0,sizeof(p));}
	Poly operator * (const Poly & A) const{
		Poly B;
		FOR(i,0,n)
			FOR(j,0,n-i)
				(B.p[i+j]+=p[i]*A.p[j])%=MO;
		return B;
	}
}P;
int main(){
	fac[0]=1;
	FOR(i,1,200000) fac[i]=fac[i-1]*i%MO;
	FOR(i,1,200000) INV[i]=pw(i,MO-2);
	inv[200000]=pw(fac[200000],MO-2);
	FORD(i,199999,0) inv[i]=inv[i+1]*(i+1)%MO;
	cin>>n>>k;
	FOR(i,1,k) getint(a[i]);
	P.p[0]=1;
	FOR(i,1,k){
		Poly t;
		FOR(j,0,a[i]) t.p[j]=C(n-j,a[i]-j)*inv[j]%MO;
		P=P*t;
	}
	ans=P.p[n]*fac[n]%MO;
	ans=(ans%MO+MO)%MO;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
import sys
n, k = map(int, input().split())
a = list(map(int, input().split()))

a = [_ - 1 for _ in a]

history = []
last_visited = [None for i in range(n)]
now = 0

history.append(0)
last_visited[0] = 0

for t in range(1, k+1): # 1, 2, ..., k
  now = a[now]
  history.append(now)
  
  if last_visited[now] is None:
    last_visited[now] = t
    if t == k:
      print(now + 1)
      sys.exit()
  else:
    t0 = last_visited[now]
    t1 = t
    # 頂点 now に t0 及び t1 に訪問した状況
    # 等差数列 S = [t0, t1, .....] を考えて，
    # 「k 以下の最大の S の要素」t_max を求める
    t_max_idx = (k - t0) // (t1 - t0)
    t_max = t0 + (t1 - t0) * t_max_idx
    
    # 時刻 t_max に history[t0] にいる
    # → 時刻 k には history[t0 + (k - t_max)] にいる
    print(history[t0 + (k - t_max)] + 1)
    sys.exit()


Measured memory_bytes: 124648
#include <stdio.h>
int main(void){
    int x,y;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0)break;
    
    if(x<y)
    printf("%d %d\n",x,y);
    else 
    printf("%d %d\n",y,x);
    }
    return 0;
}


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

int main()
{
  int A, B, X;

  cin >> A >> B >> X;

  if ( A <= X
    && A + B >= X )
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
<?php  
while ($line = fgets(STDIN)) {
   $tmp[] = trim($line);
}
unset($tmp[0]);
$count = 0;
$bool = true;
foreach ($tmp as &$value) {
  $line = explode(" ", $value);
  if ($line[0] == $line[1]){
    $count += 1;
  }else{
    $count = 0;
  }
  if($count>=3){
    echo "Yes";
    break;
  } 
}

if($count<3){
  echo "No";
} 


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

int main()
{
	int a, b, c;
	int d; // ?????£?????????
	int f;
	int div = 0; //?´???°?????°

	cin >> a >> b >> c;
	d = c % a;
	f = b - a + 1; //??°??????????????°

	for (int n = 0; n < f; n++)
	{
		if (d == 0)
		{
			div++;
		}
		a++;
		d = c % a;
	}
	cout << div << "\n";
	return 0;
}

Measured memory_bytes: 3100
#include<stdio.h>
#include<string.h>
int main(){
	char S[100000];
	scanf("%s",S);

	int length = strlen(S);
	int K = strlen(S);
	
	for ( int i=0; i<length-1 ; i++ ) {
		if ( S[i+1] != S[i] ) {
			if( 2*(i+1) < length /*&& length -(i+1) < K*/) {
				K = length - (i+1) ;
			} else if ( i+1<K ) {
				K = i+1;
			}
		}
	}
	printf("%d",K); 
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>

using namespace std;

void solve()
{
	string str;
	while(getline(cin, str))
	{
		if(str == ".")
		{
			break;
		}
		stack<char> Stack;
		bool flag = true;
		for(int i = 0; i < str.size(); ++i)
		{
			if(str[i] == '(' || str[i] == '[')
			{
				Stack.push(str[i]);
			}
			else if(str[i] == ')')
			{
				if(Stack.empty() || Stack.top() != '(')
				{
					flag = false;
					break;
				}
				else
				{
					Stack.pop();
				}
			}
			else if(str[i] == ']')
			{
				if(Stack.empty() || Stack.top() != '[')
				{
					flag = false;
					break;
				}
				else
				{
					Stack.pop();
				}
			}
		}
		if(flag && !Stack.empty())
		{
			flag = false;
		}
        
        if(flag)
		{
			cout << "yes" << endl;
		}
        else
		{
			cout << "no" << endl;
		}
	}
}

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

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

using namespace std;

int main()
{
    int w,h,x,y,r;
    cin >> w>>h>>x>>y>>r;
    if(w>x&&h>y)
    {
        if(x>=r&&y>=r)
        {
            cout << "Yes" << endl;
            return(0);
        }
        else
        {
            cout << "No" << endl;
            return(0);
        }
    }
    else
    {
        cout << "No" << endl;
        return(0);
    }
    return(0);

}


Measured memory_bytes: 3096
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a == b){
		printf("%d\n", c);
	}
	else if (a == c){
		printf("%d\n", b);
	}
	else if (b == c){
		printf("%d\n", a);
	}
	return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N, K = map(int, readline().split())
    to = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, readline().split())
        a-=1
        b-=1
        to[a].append(b)
        to[b].append(a)

    P = int(1e9)+7
    
    #方針
    #頂点0からBFSで頂点を訪問していく
    #頂点0から順に取りうる色の種類数を決めていく
    #深さ0のとき頂点0はK色から選ぶことができる
    #左側の子から順に色を決めていく
    #深さ1の左端の頂点は頂点0で一つ使用されているのでそれ以外の色であるK-1色から選ぶ
    #深さ1の左端からi番目（左端をi=0）の頂点はK-1-i色から選ぶ

    #深さ2以降の頂点は左端の頂点に対して選択できる色はK-2色である
    from collections import deque 
    dq = deque()
    #頂点0から探索していく
    dq.append(0)
    #頂点0はK色の選択肢がある
    ans = K%P
    done = [0 for _ in range(N)]
    done[0] = 1
    #BFS
    while len(dq)>0:
        v = dq.popleft()
        i = 2
        if v == 0:
            i = 1
        for nx in to[v]:
            if done[nx] == 1:
                continue
            if K-i<=0:
                print(0)
                return
            ans *= K-i
            ans %= P
            i += 1
            done[nx] = 1
            dq.append(nx)

    print(ans)
if __name__ == '__main__':
    main()


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

int main(){
  int n, x;
  vector<int> v;

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

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

  int r = x;
  int ans = 0;
  for (int i = 0; i <= n - 2; i++) {
    if (r >= v[i]) {
      r -= v[i];
      ans++;
    }
  }

  if (r == v[n - 1]) {
    ans += 1;
    cout << ans << endl;
  }
  else {
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 256
using System;
class insertionSort{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    String strtemp = Console.ReadLine();
    Console.WriteLine(strtemp);
    String[] str = strtemp.Split(' ');
    for(int i=1; i<n; i++){
      String temp = str[i];
      int j = i-1;
      while(j >= 0 && int.Parse(str[j]) > int.Parse(temp)){
        str[j+1] = str[j];
        j--;
      }
      str[j+1] = temp;
      for(int k=0; k<n; k++){
        if(k==0){
          Console.Write("{0}",str[k]);
        }
        else{
          Console.Write(" {0}",str[k]);
        }
      }
      Console.WriteLine();
    }
  }
}



Measured memory_bytes: 15876
//
//AtCoder Beginner Contest 151
//D
//https://atcoder.jp/contests/abc151/tasks/abc151_d
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<string> MAP(H);
    REP(h, H) cin >> MAP[h];

    int ans = 0;
    REP(h,H)REP(w,W){
        if (MAP[h][w]=='#') continue;

        vector<vector<int>> dist(H, vector<int>(W));
        REP(hh, H)REP(ww, W) dist[hh][ww] = -1;

        queue<pair<int, int>> Q;
        Q.push(make_pair(h, w));
        dist[h][w] = 0;
        int distMax = 0;

        while (!Q.empty()) {
            int cx = Q.front().first;
            int cy = Q.front().second;
            Q.pop();

            REP(i,4){
                int ex = cx + dx[i];
                int ey = cy + dy[i];
                if ((ex<0) || (ex>=H)) continue;
                if ((ey<0) || (ey>=W)) continue;
                if (MAP[ex][ey] == '#') continue;
                if (dist[ex][ey] != -1) continue;
                Q.push(make_pair(ex, ey));
                dist[ex][ey] = dist[cx][cy] + 1;
                distMax = max(distMax, dist[ex][ey]);
            }
        }
        ans=max(ans, distMax);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N, K;
    cin >> N >> K;
    vector<Pll> p(N);
    ll a, b;
    rep(0, i, N)
    {
        cin >> a >> b;
        p.at(i) = make_pair(a, b);
    }
    sort(all(p));
    ll num = 0;
    rep(0, i, N)
    {
        num += p.at(i).second;
        if (num >= K)
        {
            cout << p.at(i).first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(){
int n,i,j,ans=1;
scanf("%d",&n);
for(i=1;i<40;i++){
j=i;
if(i!=1){
while(j<=n){
j=j*i;
if(j<=n&&j>ans)
ans=j;
}
}
}
printf("%d\n",ans);
return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 9e18
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


int main(void) {
	string s, t;
	cin >> s >> t;
	int S = s.size();
	int T = t.size();
	bool ok = false;
	reprev(i, S - T + 1) {
		bool flag = true;
		rep(j, T) {
			if (!(s[i + j] == '?' || s[i + j] == t[j])) {
				flag = false;
				break;
			}
		}
		if (flag) {
			ok = true;
			rep(j, S) {
				// [i,i+T)はT
				if (j < i || j >= i + T) {
					if (s[j] == '?')cout << 'a';
					else cout << s[j];
				}
				else {
					cout << t[j - i];
				}
			}
			break;
		}
	}
	if (!ok) {
		cout << "UNRESTORABLE";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
def is_symmetric(board):
    for i in range(N):
        for j in range(i, N):
            if board(j, i) != board(i, j):
                return False
    return True


def translate(board, a, b):
    def get(i, j):
        return board[(i + a) % N][(j + b) % N]
    
    return get


def solve(board):
    ans = 0
    for a in range(N):
        if is_symmetric(translate(board, a, 0)):
            ans += N - a
    for b in range(N):
        if b == 0:
            continue
        if is_symmetric(translate(board, 0, b)):
            ans += N - b
    return ans


N = int(input())
board = []
for i in range(N):
    board.append(input())


print(solve(board))

Measured memory_bytes: 41324
#include<stdio.h>
#define DIV 1000000007

typedef unsigned long long int verylong;

verylong mod(verylong m,int n){
    verylong x,y=0,z=0,i,j;
    /*printf("mod(%d,%d): called\n",m,n);*/
    if(n==0){
        return 1;
    }else if(n==1){
        return m;
    }else{
        x = mod((m*m)%DIV,n/2)%DIV;
        if(n%2==0){
            return x;
        }else{
            return (x*m)%DIV;
        }
    }
}

int main(){
    int m;
    int n;
    scanf("%d %d",&m,&n);
    printf("%d\n",mod(m,n));
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b,c;
    char d,e;
  	string s;
  	cin>>a>>b;
  if(a%b==0)
    cout<<0<<endl;
 else
   cout<<1<<endl;
 
 /* else if(a==23)
    cout<<"Christmas Eve Eve"<<endl;
  else
    cout<<"Christmas Eve Eve Eve"<<endl;
  */

  return 0;
}


Measured memory_bytes: 256
N = gets.to_i
dp = Array.new(10){ Array.new(10, 0) }
# dp[h][t] はN以下の先頭がh,末尾がtの数字の数の総数

(1 .. N).each do |i|
  dp[i.to_s[0].to_i][i.to_s[-1].to_i] += 1
end

total = 0
(1 .. 9).each do |i|
  (1 .. 9).each do |j|
    total += dp[i][j] * dp[j][i]
  end
end
puts total


Measured memory_bytes: 3836
using System;

class Program
{
	static void Main(string[] args)
	{
		string[] input = Console.ReadLine().Split(' ');
		int L = int.Parse(input[0]);
		int R = int.Parse(input[1]);
		int d = int.Parse(input[2]);

		int sumNum = 0;
		int result = 0;

		while (sumNum <= R)
        {
			sumNum += d;
            if (sumNum >= L && sumNum <= R)
            {
				result++;
			}
        }

		Console.WriteLine(result);
	}

}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 1;
    for(int i = 1; i < n; i++) {
        if(s[i] != s[i-1]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
    string S;
    cin >> S;
    bool flag = true;

    if (S.length() < 2)
    {
        flag = false;
    }
    
    if (S[S.length() - 1] != 'i' )
    {
        flag = false;
    }
    

    for (size_t i = 0; i < S.length(); i++)
    {
        if (i % 2 == 0)
        {
            if (S[i] != 'h')
            {
                flag = false;
            }
            
        }
        else
        {
            if (S[i] != 'i')
            {
                flag = false;
            }
        }
        
        
            
    }
    
    if (flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
const int INF = 0x3f3f3f3f;

int dl[210][210];
int ds[210][210];
long long int dp[1010][210];   
//定义 dp[i][j] := 已经去了第i个镇子后，船停在第j个镇子里的状态下的最短路。
int n,m,r; 
int way[1010];

int main()
{
	while(cin>>n>>m)
	{
		if(n==0&&m==0)
		{
			return 0;
		}
		memset(dl,INF,sizeof(dl));
		memset(ds,INF,sizeof(ds));
		memset(dp,INF,sizeof(dp));
		for(int i = 1;i <= n;i++)
		{
			dl[i][i] = ds[i][i] = 0;
		}
		for(int i = 1;i <= m;i++)
		{
			int x,y,t;
			char sl;
			cin>>x>>y>>t>>sl;
			if(sl == 'L')
			{
				dl[x][y] = min(dl[x][y],t);
				dl[y][x] = dl[x][y];
			}
			else
			{
				ds[x][y] = min(ds[x][y],t);
				ds[y][x] = ds[x][y];
			}
		}
		cin>>r;
		for(int i = 1;i <= r;i++)
		{
			cin>>way[i];
		}
		for(int k = 1;k <= n;k++)
		{
			for(int i = 1;i <= n;i++)
			{
				for(int j = 1;j <= n;j++)
				{
					dl[i][j] = min(dl[i][j],dl[i][k] + dl[k][j]);
					ds[i][j] = min(ds[i][j],ds[i][k] + ds[k][j]);
				}
			}
		}
		//第一次出发可以将船停在任意处再回来 
		for(int i = 1;i <= n;i++)
		{
			dp[1][i] = ds[way[1]][i] + dl[way[1]][i];
		}
		for(int i = 2;i <= r;i++)
		{
			for(int j = 1;j <= n;j++)
			{   //走旱路 
				dp[i][j] = min(dp[i][j],dp[i-1][j]+dl[way[i-1]][way[i]]);   
				for(int k = 1;k <= n;k++)    //现在停船点 
				{//走水路 
					dp[i][k] = min(dp[i][k],dp[i-1][j]+dl[way[i-1]][j]+ds[j][k]+dl[k][way[i]]);
				}
			}
		}
		long long int ans = INF;
		for(int i = 1;i <= n;i++)
		{
			ans = min(ans,dp[r][i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 5092
n, m = map(int, input().split())
h = list(map(int, input().split()))
ans = n
t = [1]*n
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if t[a] and h[a] <= h[b]:
        t[a] = 0
        ans -= 1
    if t[b] and h[b] <= h[a]:
        t[b] = 0
        ans -= 1
print(ans)

Measured memory_bytes: 20040
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const double eps=1e-7;
const int inf=0x3f3f3f3f;
const int max_n=100005;
ll ceil(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?(x+y-1)/y:-x/y;}
ll floor(ll x,ll y){if(x==0)return 0;if(y<0)x=-x,y=-y;bool sign=x>0;x=abs(x);return sign?x/y:-(x+y-1)/y;}
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
    inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){if(y==0)return 1;int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
/**********************head************************/
int h,n;
int main(){
    scanf("%d%d",&h,&n);
    for(int i=1;i<=n;i++){
        int x;scanf("%d",&x);
        h-=x;
    }
    if(h<=0)printf("Yes\n");
    else printf("No\n");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
static const int MAX = 200000;

int main()
{
    int R[MAX],n;
    cin  >> n;

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

    int maxv = -2000000000;
    int minv = R[0];

    for(int i=1;i<n;i++){
        maxv = max(maxv ,R[i]-minv);
        minv = min(minv ,R[i]);
    }

    cout << maxv << endl;

    return 0;
}


Measured memory_bytes: 3892
// #include <bitset>
// #include <cmath>
// #include <cstring>
// #include <deque>
// #include <functional>
// #include <iostream>
// #include <map>
// #include <numeric>
// #include <queue>
// #include <set>
// #include <stack>
// #include <stdlib.h>
// #include <string>
// #include <utility>
// #include <vector>
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
#define INF 1e9
using namespace std;
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
template<typename T> void cmax(T &a, T b) { a = max(a, b); }

signed main() {
  string s;
  cin >> s;

  int idx, len = (int)s.size();
  rep(i, s.size()) if (s[i] == '*') idx = i;
  int left = idx - 1, right = idx + 1;
  int ans = 0;
  while (0 <= left && right < len) {
    if (s[left] == '(' && s[right] == ')') {
      ans++;
      left--;
      right++;
    }
    if (0 < left && s[left - 1] == '(' && s[left] == ')') left -= 2;
    if (right < len - 1 && s[right] == '(' && s[right + 1] == ')') right += 2;
  }

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



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

int main()
{
	int n;
	cin>>n;
	
	long int a=2,b=1;
	for(int i=2;i<=n;i+=2){
		a+=b;
		b+=a;
	}
	
	cout<<((n%2)? b:a)<<endl;
	
	return 0;
}


Measured memory_bytes: 256
from sys import stdin

inf = 10**9 + 1

def solve():
    n = int(stdin.readline())
    max_d = -inf
    min_v = inf * 2

    for i in range(n):
        r = int(stdin.readline())

        max_d = max(max_d, r - min_v)
        min_v = min(min_v, r)

    print(max_d)


def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

if __name__ == '__main__':
    solve()


Measured memory_bytes: 5624
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  string S;
  while (cin >> S) {
    int win = count(S.begin(), S.end(), 'o') + (15 - S.size());
    bool res = win >= 8;
    cout << (res ? "YES" : "NO") << endl;
  }
  return 0;
}


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

int main() {

double x1,x2,y1,y2;
double x,y,z;
scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

x = (x2-x1) * (x2-x1);
y = (y2-y1) * (y2-y1);

printf("%.11lf",sqrt(x+y));


return 0;

}



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

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

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    String s = sc.next();
    int K = sc.nextInt();
    Set<String> list = new TreeSet<String>();
    for(int i=0; i<s.length(); i++){
      for(int j=0; j<5; j++){
        if(i+j >= s.length()) continue;
        list.add(s.substring(i,i+j+1) );
      }
    }
    int cnt = 0;
    for(String ans: list){
      cnt++;
      if(cnt == K) out.println(ans);
    }
  }

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

Measured memory_bytes: 22740
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define ios ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define so sizeof
#define pb push_back
#define cl clear() ;
#define vl vector<ll>
#define sz size()
#define len length()
#define emp empty()
#define el endl;cout.flush()
#define be begin()
#define fi first
#define se second
#define br break
#define en end()
#define ro return 0
#define eb emplace_back
#define con continue
#define ms(x) memset(x , 0, so x)
#define all(x) (x).be , (x).en
#define acc(x) accumulate((x).be , (x).en , 0ll)
#define forn(i,a,b) for(ll i=a;i<=b;++i)
#define rng_58 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define plll pair<ll,pair<ll,ll>>
#define plvl pair<pair<ll,ll> ,ll>
#define mp make_pair
#define trace3(a,b,c) cerr <<"a is " << a << " b is " << b << " c is " << c << el;
#define trace4(a,b,c,d) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << el ;
#define trace5(a,b,c,d,e) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << el;
#define trace6(a,b,c,d,e,f) cerr <<"a is " << a << " b is " << b << " c is " << c <<" d is " << d << " e is " << e << " f is " << f << el ;

ll cm(ll ind , vl &v)
{
    ll b = v[ind] ;
    ll sum = 0 ;
    ll n = ll(v.sz) ;
    forn(j , 0 , n - 1 ) {
       ll foo = abs(b - v[j]);
       sum = sum + foo ;
    }
    return sum ;
}

int main()
{
    ios;
    ll n ;
    cin >> n ;
    vl v;
    forn(i , 1 , n ) {
       ll x;
       cin >> x;
       v.pb(x) ;
    }
    forn(i , 1 , n ){
       v[i-1] = v[i-1] - i ;
    }
    sort(all(v));
    if(n <= 3){
    ll minn = 3e18 ;
    forn(i , 0 , n - 1) {
       ll b = v[i];
       ll sum =  0 ;
       forn(j , 0 , n - 1 ) {
          ll foo = abs(b - v[j]);
          sum = sum + foo ;
       }
       minn = min(minn , sum );
    }
    cout << minn << el ;
    }
    else {
        ll foo = n / 2 ;
        ll r1 = cm(foo , v);
        ll r2 = cm(foo - 1 , v) ;
        ll r3 = cm(foo - 2 , v)  ;
        ll r4 = cm(foo + 1 , v) ;
        ll r5 = cm(foo + 2 , v) ;
        ll ans = min(r1 , min(r2 , r3));
        ans = min(ans , min(r4 , r5));
        cout << ans << el ;
    }

}































Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int d[100000];
int c[100002];
int mod = 998244353;

int main() {
  int n;
  while(cin>>n) {
    inputs(d,n);
    memset(c,0,sizeof(c));
    REP(i,n) c[d[i]]++;
    if (d[0] != 0 || c[0] != 1) {
      cout << 0 << endl;
      continue;
    }
    ll ans = 1;
    REP(i,100001) {
      REP(j,c[i+1]) ans = ans * c[i] % mod;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 1024
import collections

n = int(input())
graph = [tuple(map(int, input().split())) for _ in range(n - 1)]
tree = [[] for _ in range(n)]
deg = [0] * n
color = {}
for a, b in graph:
    a, b = min(a - 1, b - 1), max(a - 1, b - 1)
    deg[a] += 1
    deg[b] += 1
    tree[a].append(b)
    tree[b].append(a)
    color[(a, b)] = 0
color_max = max(deg)
print(color_max)

c = [0] * n
c[0] = -1
que = collections.deque([0])
while len(que) != 0:
    i = que.popleft()
    tmp = 1
    for j in tree[i]:
        if c[j] != 0: continue
        a, b = min(i, j), max(i, j)
        if tmp == c[i]: tmp += 1
        color[(a, b)] = tmp
        c[j] = tmp
        que.append(j)
        tmp += 1

for a, b in graph:
    a, b = min(a - 1, b - 1), max(a - 1, b - 1)
    print(color[(a, b)])


Measured memory_bytes: 52696
def myAnswer(s:list)->str:
   ans = []
   for string in s:
      if(string == "B"):
         if(ans == []):
            continue
         else:
            ans.pop()
      else:
         ans.append(string)

   return "".join(ans)

def modelAnswer():
   return
def main():
   s = list(input())
   print(myAnswer(s))
if __name__ == '__main__':
   main()

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

int main(){
    double n,m,d;
    cin >> n >> m >> d;
    if(d==0){
        cout << setprecision(20) << (m-1)/n << endl;
    }
    else{
        cout << setprecision(20) << (m-1)*2*(n-d)/(n*n) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
int main()
{
    ft
    ll t,i,j,n,m,l=0,r=-2e15;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>m;
        l+=m;
        r=max(r,m);
    }
    l-=(r/2);
    cout<<l<<"\n";
    return 0;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	long long n;
	cin>>n;
	vector<long long> num(n);

	long long minus=0;
	long long sum=0;
	long long low=inf;

	for(long long i=0;i<n;i++){
		cin>>num.at(i);
		if(num.at(i)<0) minus++;
		sum+=abs(num.at(i));
		low=min(low,abs(num.at(i)));
	}

	if(minus%2==0) cout<<sum<<endl;
	else cout<<sum-low*2<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n,a,b,c,d,umax,umin,dmax,dmin,MAX,MIN;
  cin >> n >> a >> b >> c >> d;
  for(int i=0;i<n;i++){
    umax = i*d; 
    umin = i*c;
    dmax = (n-1-i)*d;
    dmin = (n-1-i)*c;
    MAX = a+umax-dmin;
    MIN = a+umin-dmax;
    if(MIN<=b and b<=MAX){
      cout << "YES\n";
      return 0;
    }
  }
  cout << "NO\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, N) for(int i=0, i##_len=(N); i<i##_len; i++)
#define RREP(i, N) for(int i=1, i##_len=(N); i<i##_len; i++)
#define P(x) cout << (x)
#define Pn(x) cout << (x) << '\n'
#define pb push_back
#define mod 1000000007;
using ll = long long;
using namespace std;

int N;
int A[200010];
int O[200010];

int main() {
    cin >> N;
    REP(i, N) cin >> A[i];
    REP(i, N) O[i] = A[i]; 
    sort(A, A+N);
    REP(i, N){
        if (A[N-1] != O[i]) Pn(A[N-1]);
        else Pn(A[N-2]);
    }

    return 0;
}


Measured memory_bytes: 3200
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<algorithm>
#include<string.h>
using namespace std;
const int maxn=10005;
const int mod=1000007;
const double eps=1e-3;
int a[maxn];
int ma[105][105];
int h,w,n;
int main()
{
        while(cin>>h>>w)
        {
                memset(ma,0,sizeof(ma));
                cin>>n;
                for(int i=0;i<n;i++)
                scanf("%d",&a[i]);
                int k=0;
                for(int i=0;i<h;i++)
                        {

                        if(i&1)
                        {
                                for(int j=w-1;j>=0;j--)
                                {
                                        if(a[k]==0)k++;
                                        a[k]--;
                                                ma[i][j]=k+1;
                                }
                        }
                        else
                        {
                                for(int j=0;j<w;j++)
                                {
                                        if(a[k]==0) k++;
                                        a[k]--;
                                        ma[i][j]=k+1;
                                }
                        }
                        }
                for(int i=0;i<h;i++)
                {
                for(int j=0;j<w;j++)
                {
                        if(!j) printf("%d",ma[i][j]);
                        else
                                printf(" %d",ma[i][j]);
                }
                cout<<endl;
                }
        }
	//system("pause");
	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

int main(void) {

	double i;

	scanf("%lf", &i);

	if (i >= 400 && i <= 599) {
		printf("8\n");
	}
	else if (i >= 600 && i <= 799) {
		printf("7\n");
	}
	else if (i >= 800 && i <= 999) {
		printf("6\n");
	}
	else if (i >= 1000 && i <= 1199) {
		printf("5\n");
	}
	else if (i >= 1200 && i <= 1399) {
		printf("4\n");
	}
	else if (i >= 1400 && i <= 1599) {
		printf("3\n");
	}
	else if (i >= 1600 && i <= 1799) {
		printf("2\n");
	}
	else if (i >= 1800 && i <= 1999) {
		printf("1\n");
	}


	return 0;
}

Measured memory_bytes: 1728
// AtCoder ABC135: B - 0 or 1 Swap
// 2019.8.26 bal4u

#include <stdio.h>
 
int main()
{
	int i, p, f, N;
	
	scanf("%d", &N);
	f = 0; for (i = 1; i <= N; i++) {
		scanf("%d", &p);
		if (p != i) f++;
	}
	puts(f <= 2? "YES": "NO");
	return 0;
}

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

#define ll long long
#define pll pair<ll,ll> 

vector<ll> S(10000006, 0);
vector<ll> A(10000006, 0);

int main(){
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	

	

	ll n;
	cin>>n;
	const ll N=n+1;
	A[0]=A[1]=0;
	for(ll i=2;i<N;i++){
		if(A[i]==0){
			for(ll j=2*i;j<N;j+=i){
				A[j]=i;
			}
		}
	}

	S[1]=1;
	for(ll i=2;i<N;i++){
		if(A[i]==0)
			S[i]=2;
		else {
			ll x=i;
			while(x%A[i]==0)
				x/=A[i];
			if(x==1)
				S[i]=S[i/A[i]]+1;
			else 
				S[i]=S[x]*S[i/x];
		}
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
		ans+=i*S[i];
	cout<<ans;
}


Measured memory_bytes: 159404
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

def main():
    N = int(input())
    c = list(input())[:-1]
    # bad_pairs = []
    w_count = 0
    r_count = 0
    for i in range(N):
        if c[i] == 'W':
            w_count += 1
        else:
            r_count += 1
        # if c[i] == 'W' and i < N - 1 and c[i + 1] == 'R':
        #     bad_pairs.append({ 'W': i, 'R': i + 1 })
    # if len(bad_pairs) == 0:
    #     print(0)
    #     exit(0)
    if w_count == N or r_count == N:
        print(0)
        exit(0)
    no_exchange = 0
    for i in range(r_count):
        if c[i] == 'R':
            no_exchange += 1
    # print(no_exchange, w_count, r_count)
    print(r_count - no_exchange)

if __name__ == '__main__':
    main()


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

using vb = std::vector<bool>;
using vvb = std::vector<vb>;
using pii = std::pair<int, int>;

struct Node {
	std::list<int> edges;
	int odd{-1};
};
std::vector<Node> graph;

int solve();
pii dfs(int, int);

int main()
{
	printf("%d\n", solve());
	return 0;
}

int solve()
{
	int n, m;
	scanf("%d%d", &n, &m);
	vvb road(n, vb(n));
	for (int i{}; i < m; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--; b--;
		road[a][b] = road[b][a] = true;
	}
	graph.resize(n);
	for (int i{}; i < n; i++)
		for (int j{}; j < n; j++)
			if (!road[i][j] && i != j)
				graph[i].edges.push_back(j);
	
	std::vector<pii> connect_size;
	for (int i{}; i < n; i++)
		if (graph[i].odd < 0)
		{
			connect_size.push_back(dfs(i, 0));
			if (connect_size.back().first < 0)
				return -1;
		}
	
	std::vector<bool> dp(n + 1);
	dp[0] = true;
	for (auto& e: connect_size)
	{
		for (int j{n - 1}; j >= 0; j--)
		{
			if (!dp[j]) continue;
			dp[j] = false;
			dp[j + e.first] = true;
			dp[j + e.second] = true;
		}
	}
	for (int i{n / 2}; i <= n; i++)
		if (dp[i]) return i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2;
	return -1;
}

pii dfs(int index, int odd)
{
	if (graph[index].odd >= 0)
	{
		if (graph[index].odd == odd)
			return pii(0, 0);
		else
			return pii(-1, -1);
	}
	graph[index].odd = odd;
	pii ret;
	if (odd)
		ret.second++;
	else
		ret.first++;
	for (auto& e: graph[index].edges)
	{
		pii tmp{dfs(e, 1 - odd)};
		if (tmp.first < 0) return pii(-1, -1);
		ret.first += tmp.first;
		ret.second += tmp.second;
	}
	return ret;
}

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



int main() {
  int  H,W,i,j;
  cin>>H>>W;
  string S[H];
  for(i=0;i<H;i++){
      cin>>S[i];
    }
  char Map[H][W];
  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      int count=0;

      if(S[i].at(j)=='#'){
        Map[i][j]='#';
      }else{
        int count=0;
        char num='0';
        if(S[max(i-1,0)].at(j)=='#')count++;
        if(S[i].at(max(j-1,0))=='#')count++;
        if(S[min(i+1,H-1)].at(j)=='#')count++;
        if(S[i].at(min(j+1,W-1))=='#')count++;

        if(i-1>=0&&j-1>=0)if(S[max(i-1,0)].at(max(j-1,0))=='#')count++;
        if(i-1>=0&&j+1<=W-1)if(S[max(i-1,0)].at(min(j+1,W-1))=='#')count++;
        if(i+1<=H-1&&j+1<=W-1)if(S[min(i+1,H-1)].at(min(j+1,W-1))=='#')count++;
        if(i+1<=H-1&&j-1>=0)if(S[min(i+1,H-1)].at(max(j-1,0))=='#')count++;
        Map[i][j]=num+count;
        }
      }
    }
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        cout<<Map[i][j];
      }
      cout<<endl;
    }

}


Measured memory_bytes: 256
N=int(input())
word_list=[]

ans="Yes"
for i in range(N):
  word=input()
  if word in word_list:
    ans="No"
    break
  else:
    word_list.append(word)
    if i>=1:
      if word_list[i-1][len(word_list[i-1])-1]!=word[0]:
        ans="No"
        break
      else:
        continue

print(ans)

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 15 22:01:38 2019

@author: aozora
"""
N, *L = map(int, open(0).read().split())
MOD = 10**9+7
graph = [[] for i in range(N+1)]
for a, b in zip(*[iter(L)]*2):
  graph[a].append(b)
  graph[b].append(a)
root = 1
parent = [0]*(N+1)
order = []
stack = [root]
while stack:
  x = stack.pop()
  order.append(x)
  for c in graph[x]:
    if parent[x]==c:
      continue
    stack.append(c)
    parent[c] = x

fact = [1] * (N + 10)
for n in range(1, N + 10):
    fact[n] = n * fact[n - 1] % MOD
fact_inv = [1] * (N + 10)
fact_inv[-1] = pow(fact[-1], MOD - 2, MOD)
for n in range(N + 9, 0, -1):
    fact_inv[n - 1] = fact_inv[n] * n % MOD

dp_d = [1]*(N+1)
size_d = [0]*(N+1)
for v in order[::-1]:
  s = size_d[v]
  p = parent[v]
  dp_d[v] *= fact[s]
  dp_d[v] %= MOD
  m = dp_d[v]
  size_d[p] += s+1
  dp_d[p] *= fact_inv[s+1]*m
  dp_d[p] %= MOD

size_u = [N-2-x for x in size_d]
dp_u = [1]*(N+1)

for v in order[1:]:
  p = parent[v]
  x = dp_d[p]
  x *= fact_inv[size_d[p]]
  x *= fact[size_d[v]+1]
  x *= pow(dp_d[v],MOD-2,MOD)
  x *= fact[size_u[v]]
  x *= fact_inv[size_u[p]+1]
  x *= dp_u[p]
  dp_u[v] = x%MOD

for xd, xu, sd, su in zip(dp_d[1:], dp_u[1:], size_d[1:], size_u[1:]):
    su += 1
    x = xd * xu * fact[sd + su] * fact_inv[sd] * fact_inv[su] % MOD
    print(x)

Measured memory_bytes: 127316
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

string six(int num){
	string ans = to_string(num);
	while(ans.size() < 6){
		ans = "0" + ans;
	}
	return ans;
}

vector<pair<int,int> > city[100001]; 
string ans[100000];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N,M;
	cin >> N >> M;
	for(int i=0; i<M; i++){
		int a,b;
		cin >> a >> b;
		city[a].push_back(MP(b,i));
	}
	for(int i=1; i<=N; i++){
		sort(city[i].begin(), city[i].end());
		for(int j=0; j<city[i].size(); j++){
			ans[city[i][j].second] = six(i) + six(j+1);
		}
	}
	for(int i=0; i<M; i++){
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 12416
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int h, w;
    while (cin >> h >> w && h){
        REP(i,h){
            REP(j,w){
                cout << '#';
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3080