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

int main(void){

    char s[16] = "", *p = s;
    int length = 0, i = 0, flg = 0, flg2 = 0;
    char result[3] = "AC";

    scanf("%s", s);

    while(1){
        if(*p++ != '\0')
            length++;
        else
            break;
    }

    for(i = 0; i < length; i++){
        flg2 = 0;
        if(i == 0){
            if(s[0] != 'A'){
                strcpy(result,"WA");
                break;
            }
            flg2 = 1;
        }
        else if( i >= 2 && i <= (length - 2)){
            if(s[i] == 'C'){
                if(flg != 0){
                    strcpy(result,"WA");
                    break;
                }
                flg = 1;
                flg2 = 1;
            }
        }
        if(!('a' <= s[i] && s[i] <= 'z') && flg2 == 0){
            strcpy(result,"WA");
            break;
        }
    }

    if(flg != 1)
        strcpy(result,"WA");


    printf("%s\n",result);
    return 0;
}


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

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

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    ostr << p.first << ", " << p.second;
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll x(n); x[i]=a;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll x(m,vi(n)); x[i][j]=a;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll x(n); x[i]={a,b}; x[i].first/second;

#define PI 3.1415926535897932
    // cout << fixed << setprecision(10) << ans << endl;
#define EPS 1e-12
#define INF (ll)1e+12
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORR(i,a,b) for(ll i=(b)-1; i>=(a); i--)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
// sort(all(x));

ll sum(vll &v) {return accumulate(all(v), 0LL);}

int main(){
    ll n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vvll a(n), b(n), v(n, vll(n,0));
    REP(i,n) v[i][i] = 1;
    a[0].emplace_back(1);
    REP(i,n-2){
        a[i+1].emplace_back(i);
        a[i+1].emplace_back(i+2);
    }
    a[n-1].emplace_back(n-2);
    a[x].emplace_back(y);
    a[y].emplace_back(x);
    b = a;
    REP(i,n){
        v[i][i] = 1;
        REP(j, a[i].size()) v[i][a[i][j]] = 1;
    }
    // cout << v << endl;;

    REP(i,n-1){
        ll ans = 0;
        vvll c(n);
        REP(j,n){
            ans += b[j].size();
            REP(k, b[j].size()){
                REP(l, a[b[j][k]].size()){
                    if(v[j][a[b[j][k]][l]] == 0){
                        c[j].emplace_back(a[b[j][k]][l]);
                        v[j][a[b[j][k]][l]] = 1;
                    }
                }
            }
        }
        cout << ans/2 << endl;
        b = c;
    }
    // cout << a << endl;
    return 0;
}


Measured memory_bytes: 32000
//From Naruto to Hokage
//#include <RJ>
#include<bits/stdc++.h>
using namespace std;

#define ll          long long
#define pb          push_back
#define endl        '\n'
#define mii         map<ll,ll>
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define INF         (1ll<<60)
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
const int N=100005;
void solve(){
    ll n,k,x,ans=0;
    cin>>n>>k;
    rep(i,0,n-1){
        cin>>x;
        if(x>=k) ans++;
    }
    cout<<ans;
}
signed main()
{
    ios
    int TESTS=1;
    //cin>>TESTS;
    while(TESTS--){
        solve();
    }
    time
    return 0;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	static Set<Long> set = new HashSet<>();
	static long num;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		num = sc.nextLong();
		mat(0);
		long count = 0;
		for(Long s : set) {
			if(s.toString().matches("^(?=.*3)(?=.*5)(?=.*7).*")) {
				count++;
			}
		}
		System.out.println(count);
	}

	public static void mat(long s) {
		long tmp = s * 10 + 3;
		if(tmp <= num) {
			set.add(tmp);
			mat(tmp);
		}
		tmp = s * 10 + 5;
		if(tmp <= num) {
			set.add(tmp);
			mat(tmp);
		}
		tmp = s * 10 + 7;
		if(tmp <= num) {
			set.add(tmp);
			mat(tmp);
		}
	}

}


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

int main() {
  long long N, M;
  cin >> N >> M;
  long long ans = 0;
  ans += min(N, M/2);
  M -= 2*ans;
  if (M > 0) ans += M/4;
  cout << ans << endl;
}

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

long long modexp(int x, long long e, int m) {
    long long ans = 1, p = x % m;
    while (e > 0) {
        if (e % 2 != 0) ans = (ans * p) % m;
        p = (p * p) % m;
        e >>= 1;
    }
    return ans;
}

const int M = 998244353;

struct P { int x, y; };

bool colinear(P a, P b, P c) {
    int x1 = a.x - c.x, y1 = a.y - c.y,
        x2 = b.x - c.x, y2 = b.y - c.y;
    return x1 * y2 == x2 * y1;
}

int main() {
    int n; cin >> n;
    P p[n]; for (int i = 0; i < n; i++) cin >> p[i].x >> p[i].y;
    long long ans = modexp(2, n, M) - 1 - n - n * (n - 1) / 2;
    for (int i = 0; i < n; i++)
        for (int j = i+1; j < n; j++) {
            int count = 0;
            for (int k = j+1; k < n; k++)
                if (colinear(p[i], p[j], p[k])) count++;
            if (count > 0)
                ans -= modexp(2, count, M) - 1;
        }
    cout << (ans % M + M) % M << endl;
}


Measured memory_bytes: 1144
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n,l[300]={ };
	long long ans=0;
	cin>>n;
	for(int i=1;i<=2*n;i++){
		cin>>l[i];
	}
	sort(l+1,l+n*2+1);
	for(int i=1;i<=2*n;i+=2){
		ans+=l[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        int count = 0;
        boolean sw = false;
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;
        double dMax = Double.MIN_VALUE;
        double dMin = Double.MAX_VALUE;
        //
        Scanner sc = new Scanner(System.in);
        //int n = sc.nextInt();
        String s = sc.next();
        String s1 = s.substring(0,1);
        String s2 = s.substring(1,2);
        String s3 = s.substring(2,3);

        if (s1.equals(s2) && s2.equals(s3)) System.out.println("No");
        else System.out.println("Yes");
        sc.close();
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ull unsigned ll
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=100005;
int n,m,x,y,ans;
vector<vector<int> > v;
vector<int> nodes;
set<int> arkam;
bool vis[maxn];
int a[maxn];
void dfs(int node){
    vis[node]=true;
    nodes.push_back(node);
    arkam.insert(a[node]-1);
    for(auto i:v[node])
        if(!vis[i])dfs(i);
}
int main()
{
    IO;
    cin >> n >> m;
    v.resize(n);
    for(int i=0;i<n;++i)
        cin >> a[i];
    while(m--){
        cin >> x >> y;
        --x,--y;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=0;i<n;++i){
        if(!vis[i]){
            nodes.clear();
            arkam.clear();
            dfs(i);
            for(auto j:nodes)
                ans+=(arkam.find(j)!=arkam.end());
        }
    }
    cout<<ans<<endl;
    re 0;
}

Measured memory_bytes: 15352
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

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

	lint ans = 0;
	for (int i = 0; i < N; i++) ans += a[i] - 1;

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define D                double
#define F                first
#define S                second
#define pb               push_back
#define pf               push_front
#define MP               make_pair
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define it(it,mp)        for(auto it=mp.begin() ; it!=mp.end() ; it++)
#define IOS              ios_base :: sync_with_stdio(false); cin.tie(NULL);
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
typedef long long int                   ll;
typedef pair<int,int>                   PII;
char curr_val ;
int main()
{
    IOS
    // READ("test.txt");
    //WRITE("");
    ll n , a ;
    bool flag = true ;
    cin >> n ;
    while(n--)
    {

        cin >> a;
        if(a%2 == 0 && a%3 && a%5){
            flag = false ;

        }
    }
    (flag)?cout<<"APPROVED":cout<<"DENIED";
    return 0;
}



Measured memory_bytes: 256
H, W = map(int, input().split())
M = [list(input()) for _  in range(H)]
visited = [[0]*W for _ in range(H)]

from collections import deque
q = deque([[0, 0, 1]])
goal = False
while q:
    i, j, count = q.popleft()
    if i == H-1 and j == W-1:
        goal = True
        break
    
    for movei, movej in ((0, 1), (0, -1), (1, 0), (-1, 0)):
        ni = i + movei; nj = j + movej
        if ni < 0 or H <= ni or nj < 0 or W <= nj:
            continue
        if M[ni][nj] == '#':
            continue
        if visited[ni][nj] != 0:
            continue
        visited[ni][nj] = 1
        q.append([ni, nj, count+1])

if goal:
    numdots = 0
    for i in range(H):
        numdots += M[i].count('.')
    print(numdots - count)
else:
    print(-1)

Measured memory_bytes: 3316
N = int(input())
C = []
S = []
F = []

for i in range(N - 1):
    c, s, f = map(int, input().split())
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N - 1):
    t = 0
    
    for j in range(i, N - 1):    
        n = 0
        
        while t > S[j] + F[j] * n:
            n += 1
        
        t = S[j] + F[j] * n + C[j]

    print(t)
print(0)

Measured memory_bytes: 43868
#include<bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 1e5 + 7;
const int maxm = 1e6 + 7;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-10;
int r, c, n;
stack<int> s;
struct node
{
    double deg;
    int num;
};
bool operator<(node a, node b)
{
    return a.deg < b.deg;
}
vector<node> v;
int main(int argc, char const *argv[])
{
    scanf("%d%d%d", &r, &c, &n);
    for (int i = 1; i <= n; i++)
    {
        int xx1, yy1, xx2, yy2;
        scanf("%d%d%d%d", &xx1, &yy1, &xx2, &yy2);
        if ((xx1 == r || xx1 == 0 || yy1 == 0 || yy1 == c) && (xx2 == r || xx2 == 0 || yy2 == 0 || yy2 == c))
        {
            v.push_back(node{atan2(yy1-c/2.0, xx1-r/2.0), i});
            v.push_back(node{atan2(yy2-c/2.0, xx2-r/2.0), i});
        }
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++)
    {
        if (s.empty())
        {
            s.push(v[i].num);
        }
        else if (s.top() == v[i].num)
            s.pop();
        else
            s.push(v[i].num);
    }
    bool flag = 0;
    if (s.empty())
        flag = 1;
    while (!s.empty())
        s.pop();
    reverse(v.begin(), v.end());
    for (int i = 0; i < v.size(); i++)
    {
        if (s.empty())
        {
            s.push(v[i].num);
        }
        else if (s.top() == v[i].num)
            s.pop();
        else
            s.push(v[i].num);
    }
    if (s.empty())
        flag = 1;
    printf("%s\n", flag ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 6384
import scala.annotation.tailrec
import scala.io.StdIn._



object Main extends App {

  solve()
  @tailrec def solve(): Unit = {
    val x = readLine.trim
    if (x == "#") return
    val y = readLine.trim
    val add = readInt()
    val erase = readInt()
    val swap = readInt()
    val roll = readInt()
    println(
      x.indices.map{i ⇒ i * roll + minDistance(x.substring(i) + x.substring(0, i), y, x.length - i, add, erase, swap, roll)}.min
    )
    solve()
  }
  def minDistance(from: String, to: String, original: Int, add: Int, erase: Int, swap: Int, roll: Int): Int = {
    val memo = Array.tabulate(2){i ⇒ if (i == 1) Array.tabulate(to.length + 1){j ⇒ j * add} else Array.fill(to.length + 1){Int.MaxValue}}
    for (i ← from.indices) {
      val e = if (i >= original) erase - roll else erase
      memo(i % 2)(0) = memo((i + 1) % 2)(0) + e
      for (j ← to.indices) {
        memo(i % 2)(j + 1) = if (from(i) == to(j)) List(memo((i + 1) % 2)(j) + Math.min(0, Math.min(swap, add + e)), memo(i % 2)(j) + add, memo((i + 1) % 2)(j + 1) + e).min else List(memo((i + 1) % 2)(j) + Math.min(swap, add + e), memo(i % 2)(j) + add, memo((i + 1) % 2)(j + 1) + e).min
        //println(s"minCost from: ${from.substring(0, i + 1)}, to: ${to.substring(0, j + 1)} => ${memo(i % 2)(j + 1)}")
      }
    }

    memo((from.length + 1) % 2).last
  }
}


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

int main(){
  int N;
  int s = 0;
  cin >> N;
  for (int i = 1; i <= 9; ++i){
    if ( N % i == 0 && N / i <= 9){
      s = 1;
      break;
    }
  }
  if (s == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

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

  int cnt = 0;
  int x = 0;
  int y = 0;
  int z = 0;
  rep(i,n) {
    int m = sz(s[i]);
    if (s[i][0] != 'B' && s[i][m-1] == 'A') x++;
    if (s[i][0] == 'B' && s[i][m-1] != 'A') y++;
    if (s[i][0] == 'B' && s[i][m-1] == 'A') z++;
    rep(j,s[i].size()) {
      if (s[i].substr(j,2) == "AB") cnt++;
    }
  }

  int d;
  if (x == 0 && y == 0 && z > 0) d = z-1;
  else d = min(x+z, y+z);
  int ans = cnt + d;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int w,a,b;
    cin>>w>>a>>b;
    if(abs(a-b)<=w)cout<<0<<endl;
    else cout<<abs(a-b)-w<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>

using namespace std;


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

    printf("%.12f\n", (double)L * L * L / 27);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> zahyo(n);
    vector<pair<int,int>> checkpoint(m);
    vector<pair<int,int>> distance(m);
    for (int i = 0; i < n; i++){
        cin >> zahyo.at(i).first >> zahyo.at(i).second;
    }
    for (int i = 0; i < m; i++){
        cin >> checkpoint.at(i).first >> checkpoint.at(i).second;
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            distance.at(j).first  = abs(zahyo.at(i).first - checkpoint.at(j).first)
                              + abs(zahyo.at(i).second - checkpoint.at(j).second);
            distance.at(j).second = j + 1;
        }
        sort(distance.begin(), distance.end());//小さい順に並べる
        cout << distance.at(0).second << endl;
    }
}

Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
typedef long long LL;
const int N=205;
const int MOD=1e9+7;
int n,m;
int a[N];
int f[2][100005];
int JC[N];
bool cmp (int x,int y)	{return x>y;}
int add (int x,int y)	{x=x+y;return x>MOD?x-MOD:x;}
int mul (int x,int y)	{return (LL)x*y%MOD;}
int main()
{
	scanf("%d%d",&n,&m);
	JC[0]=1;for (int u=1;u<=n;u++) JC[u]=mul(JC[u-1],u);
	for (int u=1;u<=n;u++)	scanf("%d",&a[u]);
	sort(a+1,a+1+n,cmp);
	f[0][m]=1;
	int op=0;
	for (int u=1;u<=n;u++)
	{
	//	printf("u:%d %d\n",u,a[u]);
		op^=1;
		for (int j=0;j<=m;j++) f[op][j]=0;
		for (int j=0;j<=m;j++)
		{
			if (j>=a[u]) 
			{
				f[op][j]=add(f[op][j],mul(f[op^1][j],n-u));
				f[op][j%a[u]]=add(f[op][j%a[u]],f[op^1][j]);
			}
			else
			{
				f[op][j]=add(f[op][j],mul(f[op^1][j],n-u+1));
			}
		}
		/*for (int i=0;i<=m;i++) 
		if (f[op][i]!=0) printf("%d %d\n",i,f[op][i]);
		system("pause");*/
	}
	int ans=0;
	for (int u=0;u<=m;u++) 
	{
		//printf("%d %d\n",u,f[op][u]);
		ans=add(ans,mul(u,f[op][u]));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 200100;
const ll mod = 998244353;
ll fact[maxn], ifact[maxn];
ll n, m, k;

ll power(ll a, ll b) {
	if(b == 0) return 1LL;
	else if(b == 1) return 1LL * a % mod;
	else {
		if(b % 2 == 0) {
			ll half = power(a, b/2);
			return (half*half)%mod;
		}
		else {
			return (a*power(a, b-1))%mod;
		}
	}
}

void preprocess() {
	fact[0] = 1LL;
	ifact[0] = 1LL;

	for(int i=1;i<maxn;i++) {
		fact[i] = 1LL * i * fact[i-1]; fact[i] %= mod;
		ifact[i] = power(fact[i], mod-2);
	}
}

ll ncr(ll n, ll k) {
	ll f = (fact[n] * ifact[k]) % mod;
	f *= ifact[n-k]; f %= mod;
	return f;
}


int main() {
	cin>>n>>m>>k;
	preprocess();

	ll result = 0LL;
	for(int i=0;i<=k;i++) {
		ll cnt = ncr(n-1, i);
		ll curr_val = ( cnt * power(m-1, n-1-i) ) % mod;
		curr_val *= m; curr_val %= mod;
		result += curr_val;
		result %= mod;
	}
	cout<<result;
}

Measured memory_bytes: 6768
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using G = vector<vector<int>>;
const long long INF = 1LL << 60;

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

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

int main(){
  int n,k;
  cin >> n >> k;
  vector<ll> dp(n,INF);
  vector<ll> h(n,0);
  rep(i,n) cin >> h[i];
  dp[0] = 0;
  for(int i=0;i<n;i++){
      for(int j=1;j <= k;j++){
          if(i+j >= n) break;
          chmin(dp[i+j],dp[i] + abs(h[i] - h[i+j]));
      }
  }
  cout << dp[n-1] << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int int64_t

int n,m;
int dp[100001];

int stairup(int x){
	if(x<0)return 0;
	if(dp[x]!=-1)return dp[x];
	dp[x]=(stairup(x-1)+stairup(x-2))%MOD;
	return dp[x];
}

signed main(){
	cin>>n>>m;
	fill(dp,dp+100001,-1);
	dp[0]=1;
	rep(i,m){
		int c;
		cin>>c;
		dp[c]=0;
	}
	cout<<stairup(n)<<endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll k;
  string s;
  cin >> k >> s;
  
  if(s.size()<=k) cout << s << newl;
  else cout << s.substr(0, k) << "..." << newl;
  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n;
    string s;
    cin>>n>>s;
    int ans=-1;
    for(int i=1;i<n;i++){
        string s1,s2;
        s1=s.substr(0,i);
        s2=s.substr(i);
        bool c1[26],c2[26];
        for(int j=0;j<26;j++){
            c1[j]=false;c2[j]=false;
        }
        for(int j=0;j<s1.size();j++)c1[s1[j]-'a']=true;
        for(int j=0;j<s2.size();j++)c2[s2[j]-'a']=true;
        int count=0;
        for(int j=0;j<26;j++){
            if(c1[j]&&c2[j])count++;
        }
        if(ans<count){
            ans=count;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    vector h(n+1,0);
    for (int i=1; i<=n; i++) cin >> h[i];

    vector<bool> g(n+1, true);
    for (int i=0; i<m; i++) {
        int a,b;
        cin >> a >> b;

        if (h[a] == h[b]) {
            g[a] = g[b] = false;
        } else if (h[a] > h[b]) {
            g[b] = false;
        } else {
            g[a] = false;
        }
    }

    debug(g);
    int ans = count(g.begin()+1, g.end(), true);
    cout << ans << endl;
}

Measured memory_bytes: 3360
N,M = map(int,input().split())
edges = [list(map(int,input().split())) for _ in range(M)]

def dfs(A,n):
    for a in A[n]:
        if visited[a-1] == -1:
            visited[a-1] = 1
            dfs(A,a-1)
    if -1 in visited:
        return True
    else:
        return False

ans = 0 
for i in range(M):
    A = [[] for _ in range(N)]
    edges_new = edges[:i] + edges[i+1:]
    for a,b in edges_new:
        A[a-1].append(b)
        A[b-1].append(a)
    visited = [-1]*N
    visited[0] = 1
    if dfs(A,0):
        ans += 1
print(ans)


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

int main()
{
  int A, B;
  cin >> A >> B;

  int max = A + B;
  if (max < A - B) {
    max = A - B;
  }
  if (max < A * B) {
    max = A * B;
  }
  cout << max << endl;
}

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

int main(){
  double ans=-1;
  double a,b;
  cin >> a >> b;
  if(((a+1)/0.08)>(b/0.10)&&((a+1)/0.08)<=((b+1)/0.10)){
    if(fmod((b/0.10),1.0)==0)ans=(int)(b/0.10);
    else ans=(int)(b/0.10+1);
  }
  else if((a/0.08)>=(b/0.10)&&(a/0.08)<((b+1)/0.10)){
    if(fmod((a/0.08),1.0)==0)ans=(int)(a/0.08);
    else ans=(int)(a/0.08+1);
  }
  
  cout << ans << endl;
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

int a, b, c;

int main() {
	read(a), read(b), read(c);
	write(max(0, c - (a - b)));
	putchar('\n');
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n){
		cin>>a[i];
	}
	vector<vector<ll>> g(n);
	vector<ll> dp(n,inf);
	rep(i,n-1){
		ll u,v;
		cin>>u>>v;
		u--,v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	vector<ll> ans(n,-1);
	auto dfs=[&](auto &dfs,ll v,ll pre)->void{
		ll ind=lower_bound(begin(dp),end(dp),a[v])-begin(dp);
		ll now=dp[ind];
		dp[ind]=a[v];
		ans[v]=lower_bound(begin(dp),end(dp),inf)-begin(dp);
		for(auto to:g[v]){
			if(to==pre) continue;
			dfs(dfs,to,v);
		}
		dp[ind]=now;
	};
	dfs(dfs,0,-1);
	cout<<ans<<endl;
}

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

using namespace std;

const int N = 2e5+5;

const int mod = 1e9+7;

int n;
int ar[N];

long long get(int x){
    long long cost = 0;
    for(int i = 1; i <= n; i++){
        cost += (x - ar[i]) * (x - ar[i]);
    }
    return cost;
}

int main(){
    cin >> n;
    long long av = 0;
    for(int i = 1; i <= n; i++){
        cin >> ar[i];
        av += ar[i];
    }
    av /= n;
    printf("%lld\n" , min(get(av) , get(av + 1)));
}


Measured memory_bytes: 3708
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;

ll n, A, B;

int main()
{
	scanf("%lld%lld%lld", &n, &A, &B);
	if(A > B)	swap(A, B);
	if(((B - A) & 1) == 0)
	{
		printf("%lld\n", (B - A) >> 1);
	}
	else
	{
		printf("%lld\n", min(A + ((B - A) >> 1), n - B + 1 + ((B - A) >> 1)));
	}
	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#define CHAR_SIZE 26

using namespace std;

bool alpha[30] = {false};

int main() {

    string s;

    cin >> s;

    bool change_flag = false;

    for (int i = 0; i < s.length(); i++) {
        int index = s[i] - 'a';
        alpha[index] = true;
    }

    if (s.length() < CHAR_SIZE) {
        for (int i = 0; i < CHAR_SIZE; i++) {
            if (alpha[i] == false) {
                s = s + (char)('a' + i);
                cout << s << endl;
                return 0;
            }
        }
    } else {
        for (int i = CHAR_SIZE - 1; i > 0; i--) {
            if (s[i - 1] < s[i]) {
                for (int j = CHAR_SIZE; j > i - 1; j--) {
                    if (s[i - 1] < s[j]) {
                        s[i - 1] = s[j];
                        cout << s.substr(0, i) << endl;
                        return 0;
                    }
                }
            }
        }
    }
    
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
typedef long long ll;
typedef long double ld;
char str[2005];
vector<int> E[2005];
ll num[2005], low[2005], high[2005];
void dfs(int x, int p = -1) {
	num[x] = (str[x] == '1');
	high[x] = low[x] = 0;
	int minv = 0, pick = -1;
	for (int y : E[x]) {
		if (y == p) continue;
		dfs(y, x);
		num[x] += num[y];
		high[y] += num[y];
		low[y] += num[y];
		high[x] += high[y];
		minv ^= high[y] & 1;
		if (pick == -1 || low[y] > low[pick]) pick = y;
	}
	if (pick != -1) {
		low[x] = low[pick];
		for (int y : E[x]) {
			if (y == p) continue;
			if (y != pick) low[x] -= high[y];
		}
		low[x] = max((ll)minv, low[x]);
	}
}
int main() {
	int n;
	scanf("%d%s", &n, str + 1);
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		E[a].push_back(b);
		E[b].push_back(a);
	}
	int ans = INT_MAX;
	for (int i = 1; i <= n; ++i) {
		dfs(i);
		if (low[i] == 0) {
			ans = min((ll)ans, high[i] / 2);
		}
	}
	printf("%d\n", ans == INT_MAX ? -1 : ans);
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}
const int PrimeMax = 100001;
int is_prime[PrimeMax];
void Eratosthenes(int N){
  for(int i = 0; i < N; i++){
    is_prime[i] = 1;
  }
  is_prime[1] = 0;
  for(int i = 2; i*i < N ; i++){
    if(is_prime[i]){
      for(int j = 0; i * (j + 2) < N; j++){
        is_prime[i *(j + 2)] = 0;
      }
    }
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  set<int> v;
  int n;
  while(cin>>n&&n){
    v.clear();
    REP(i,1,n){
      v.insert(i*i%n);
    }
    vector<int> v2(all(v));
    vary(int,ans,(n-1)/2+1,0);
    rep(i,v2.size()){
      REP(j,i+1,v2.size()){
        int k = v2[i] - v2[j];
        k += (k<0)? n:0;
        k = ((n-1)/2 < k)?n-k:k;
        ans[k]++;
      }
    }
    REP(i,1,(n-1)/2+1){
      cout << ans[i] * 2<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3304
#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 n, ans = 0;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      auto itr = lower_bound(l.begin(), l.end(), l[i] + l[j]);
      int ng = distance(itr, l.end());
      ans += n - j - 1 - ng;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int total(int i){
  int count=0;
 while(i>0){
      count+=i%10;
      i/=10;
    }
  return count;
}

int main(){
  int N;
  int A,B;
  cin >> N >> A >> B;
  int sum=0;
  for(int i=1;i<=N;i++){
    int n=total(i);
    if(A<=n&&n<=B){
      sum+=i;
    }
  }
  cout<<sum <<endl;
}
    
    
  


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

int main()
{
    string s;
    cin >> s;
    if(s=="Sunny"){
        cout << "Cloudy" << endl;
    }
    if(s=="Cloudy")
    {
        cout << "Rainy" << endl;
    }
    if(s=="Rainy")
    {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
int N,X,Y,ct,output[1000];
int main() {
	cin >> N;
	for(int g=0; g<N; ++g) {
		cin >> X >> Y >> ct;
		int T[64][64] = {{0}},up[200][200] = {{0}},left[200][200] = {{0}};
		for(int i=0; i<ct; ++i) {
			int x1,x2,y1,y2;
			cin >> x1 >> y1 >> x2 >> y2;
			if(x1==x2)
			up[x1][max(y1,y2)] = 1;
			else left[max(x1,x2)][y1] = 1;
		}
		T[0][0] = 1;
		for(int x=0; x<=X; ++x) {
			for(int y=0; y<=Y; ++y) {
				if(up[x][y]==0) T[x][y] += T[x][y-1];
				if(left[x][y]==0) T[x][y] += T[x-1][y];
			}
		}
		output[g] = T[X][Y];
	}
	for(int i=0; i<N; ++i) {
		if(output[i] == 0) 
			cout << "Miserable Hokusai!" << endl;
		else
		cout << output[i] << endl;
	}
        return 0;
}

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

using namespace std;

const int maxn = 1e5 + 10;
int a[maxn][5], dp[maxn][5], n;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n;

    for (int i = 1; i <= n; i++)
        for (int j = 0; j < 3; j++)
            cin >> a[i][j];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++)
                if (j != k)
                    dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i + 1][k]);

    cout << max({dp[n][0], dp[n][1], dp[n][2]});

    return 0;
}

Measured memory_bytes: 4224
import sys
N, M = map(int, input().split())

#とりまぶっこむ 
SClis = [] 
for _ in range(M):
    a, b = map(int, input().split())
    SClis.append([a,b])

ans = [-1]*N

for i in range(M):
    singlelis = SClis[i]
    S =  (singlelis[0] - 1)
    C =  (singlelis[1])
    
    if ans[S] != -1 and ans[S] != C:
        print(-1)
        sys.exit()
    else:
        ans[S] = C


    
if N == 1:
    if ans[0] == -1:
        ans[0] = 0
        print(''.join(map(str, ans)))
        sys.exit()

if N != 1:
    if ans[0] == 0:
        print(-1)
        sys.exit()
    
    if ans[0] == -1:
        ans[0] = 1
    
    for i in range(1,N):
        if ans[i] == -1:
            ans[i] = 0

print(''.join(map(str, ans)))


Measured memory_bytes: 9152
N = int(input())
S = input()

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

for i in range(N-1,-1,-1):
    for j in range(N-1,-1,-1):
        # print(i,j)
        if S[i] == S[j]:
            dp[i][j] = dp[i+1][j+1] + 1 

# print(dp)
ans = 0
for i in range(N):
    for j in range(N):
       val = min(abs(i-j),dp[i][j])
       ans = max(val,ans)

print(ans) 

Measured memory_bytes: 232200
#include <stdio.h>

int main(){
    char str[15];
    char ans[15];
    scanf("%s", str);

    int j = 0;
    for (int i=0; str[i]!='\0'; i++){
        if (str[i] != 'B'){
            ans[j++] = str[i];
            // printf("%d = %c\n", j-1, ans[j-1]);
            if (str[i+1] == 'B'){
                j--;
            }
            ans[j] = '\0';
        }
        else{
            if (j >= 0){
                // printf("%d = null\n", j);
                ans[j] = '\0';
                if (str[i+1] == 'B'){
                    (j == 0) ? j = 0 : j--;
                }
            }
        }
        // printf("%d = %s\n", i+1, ans);
    } 
    printf("%s\n", ans);
    
    return 0;
}   

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

int main(){
	int i;
	int a,b;
	int num;
	char op;
	
	for(i=0;op!="?";i++){
		scanf("%d %c %d",&a,&op,&b);
		
		switch(op){
			case '+':
				num = a + b;
				break;
			case '-':
				num = a - b;
				break;
			case '*':
				num = a * b;
				break;
			case '/':
				num = a / b;
				break;
			case '?':
				return 0;
			default:
				break;
		}
		
		printf("%d\n",num);
	}

return 0;
}


Measured memory_bytes: 2076
n,y = map(int,input().split())

flag = False
for a in range(n+1):
  for b in range(n+1-a):
    c = n-a-b
    if a*10000 + b*5000 + c*1000 == y:
      flag = True
      print("{} {} {}".format(a,b,c))
      break
  if flag:
    break
if not flag:
  print("-1 -1 -1")

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

struct edge { int to, cost; };

typedef pair<long long, int> plli;
int main() {
  int n, m, r;
  cin>>n>>m>>r;
  vector<edge> graph[n];
  for (int i=0; i<m; i++) {
    int s, t, d;
    cin>>s>>t>>d;
    graph[s].push_back({t, d});
  }
  long long inf = 1e5 * 1e4 + 1;
  long long d[n];
  bool used[n];
  for (int i=0; i<n; i++) {
    d[i] = inf;
    used[i] = false;
  }
  d[r] = 0;
  priority_queue<plli, vector<plli>, greater<plli> > que;
  que.push(make_pair(0, r));


  while (!que.empty()) {
    auto t = que.top(); que.pop();
    if (used[t.second]) {
      continue;
    }
    for (auto e: graph[t.second]) {
      if (d[t.second] != inf && d[e.to] > d[t.second] + e.cost) {
        long long cost = d[t.second] + e.cost;
        d[e.to] = cost;
        que.push(make_pair(cost, e.to));
      }
    }
  }
  for (auto di: d) {
    if (di == inf) {
      cout<<"INF"<<endl;
    } else {
      cout<<di<<endl;
    }
  }
}


Measured memory_bytes: 14540
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] a = new char[h][w];
        for (int i = 0; i < h; i++) {
            a[i] = sc.next().toCharArray();
        }
        for (int i = 0; i < h + 2; i++) {
            for (int j = 0; j < w + 2; j++) {
                if(i == 0 || i == h + 1 || j == 0 || j == w + 1) {
                    System.out.print("#");
                } else {
                    System.out.print(a[i - 1][j - 1]);
                }
            }
            System.out.println();
        }
    }
}

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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[m];
    for(int i = 0; i < m; i++)
    {
        cin >> a[i];
    }
    if(n >= m)
    {
        cout << 0;
        return 0;
    }
    sort(a, a + m);
    int b[m - 1];
    for(int i = 0; i < m - 1; i++)
    {
        b[i] = abs(a[i + 1] - a[i]);
    }
    sort(b, b + m - 1);
    int res = 0;
    for(int i = 0; i < m - n; i++)
    {
        res += b[i];
    }
    cout << res;
    return 0;

}


Measured memory_bytes: 1024
#!/usr/bin/env python3

import numpy as np
from scipy.special import comb

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))

a_sum = np.cumsum(a)


re_list = {}
re_list[0] = 1
for i in a_sum:
    re = i % m
    if re in re_list:
        re_list[re] += 1
    else:
        re_list[re] = 1

# print(re_list)
ans = 0
for value in re_list.values():
    ans += comb(value, 2, exact=True)

print(ans)


Measured memory_bytes: 54156
n, q = map(int, input().split())
s = input()
a = [0 for i in range(n)]
ct = 0
for i in range(n-1):
    if s[i] == "A" and s[i+1] == "C":
        ct += 1
    a[i] = ct

for i in range(q):
    l, r = map(int, input().split())
    if l == 1:
        print(a[r-2])
    else:
        print(a[r-2]-a[l-2])

Measured memory_bytes: 6104
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <deque>
#include <iomanip>
using namespace std;
#define rep(i,n) for (ll i=0;i<n;i++)
#define REP(i,n) for (ll i=1;i<=n;i++)
#define PI 3.141592653589793238462643383279
typedef long long ll;
const ll INF = 1e9 + 7;

double A, B, X;

int main() {
	cin >> A >> B >> X;
	double H = X / (A * A);
	double R = B - H;
	double ans;
	if (B > R * 2) {
		ans = atan(R/(A/2));
		ans /= PI;
		ans *= 180;
	}
	else {
		double S = 2 * A * H / B;
		ans = atan(B/S);
		ans /= PI;
		ans *= 180;
	}
	cout << fixed << setprecision(10) << ans << endl;
	return 0;
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int,input().split()))

ans = 0
for a in A:
    ans ^= a
for i in range(N):
    A[i] &= ~ans

def gauss_jordan(bs):
    rank = 0
    pivot_cols = []
    for col in reversed(range(61)):
        pivot = -1
        for i,row in enumerate(bs[rank:]):
            if row&(1<<col):
                pivot = rank+i
                break
        if pivot < 0: continue
        pivot_cols.append(col)
        bs[pivot],bs[rank] = bs[rank],bs[pivot]
        for i,row in enumerate(bs):
            if i != rank and row&(1<<col):
                bs[i] ^= bs[rank]
        rank += 1
    return (pivot_cols,bs)

pivot_cols,bs = gauss_jordan(A)
x = 0
for j in reversed(range(61)):
    nx = x|(1<<j)
    b = nx
    for i,c in enumerate(pivot_cols):
        if b&(1<<c):
            b ^= bs[i]
    if (b&nx) == 0:
        x = nx
ans += x*2
print(ans)

Measured memory_bytes: 16116
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

typedef long long LL;

const int MAXN=100000;

int n;
LL k,a[MAXN+1];

void init(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i]; 
}

void solve(){
	LL l=0,b=40;
	while(b>=0){
		LL cnt0=0,cnt1=0;
		for(int i=1;i<=n;i++)
			if((a[i]>>b)&1) cnt1++;
			else cnt0++;
		//cerr<<"b="<<b<<" : "<<cnt0<<" "<<cnt1<<"\n";
		
		if(l+(1LL<<b)>k);
		else{
			if(cnt0>cnt1) l+=(1LL<<b);
		}
		b--;
	}
	//cerr<<"l="<<l<<"\n";
	LL ans=0;
	for(int i=1;i<=n;i++)
		ans+=(l^a[i]);
	cout<<ans<<"\n";
}

int main(){
	init();
	solve();
}


Measured memory_bytes: 1024
s = input().split()
a = int(s[0])
b = int(s[1])
k = int(s[2])

def sol(a,b,k):
    if b-a+1 <= 2*k:
        for i in range(a,b+1):
            print(i)
        return True
    for i in range(a,a+k):
        print(i)
    for i in range(b-k+1,b+1):
        print(i)
    return (True)

dummy = sol(a, b, k)

Measured memory_bytes: 3064
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109311;
const long double pi = 3.1415926535897932384626433;
typedef pair<int, int> P;
typedef pair<int, P> PP;
struct edge { int to, cost; };
vector<int>V[100005];
int in[100005];
vector<int>ans[100005];
int out[100005];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, n + m - 1) {
		int a, b; cin >> a >> b;
		V[a - 1].push_back(b - 1);
		in[b - 1]++;
	}
	
	stack<int>st;
	rep(i, n)if (!in[i])st.push(i);

	while (st.size()) {
		int i = st.top();
		st.pop();
		rep(j, V[i].size()) {
			in[V[i][j]]--;
			if (!in[V[i][j]]) {
				st.push(V[i][j]);
				ans[i].push_back(V[i][j]);
			}
		}
	}
	rep(i, n)out[i] = -1;
	rep(i, n) {
		rep(j,ans[i].size()) {
			out[ans[i][j]] = i;
		}
	}
	rep(i, n)cout << out[i] + 1 << endl;
}

Measured memory_bytes: 13312
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;

	int count = 0;
	for (int i = 0; i < S.length(); i++) {
		if (S[i] != T[i]) {
			count++;
		}
	}

	cout << count << endl;
	

}






Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define inf 1001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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; }

int main() {
    cin.tie(0); cin.sync_with_stdio(false);
    int a, p;
    cin >> a >> p;
    p += 3*a;
    cout << p/2 << endl;
}

Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	h := make([]int, N)
	for i := 0; i < N; i++ {
		h[i] = getInt()
	}
	edge := make([][]int, N)
	for i := 0; i < M; i++ {
		a, b := getInt()-1, getInt()-1
		edge[a] = append(edge[a], b)
		edge[b] = append(edge[b], a)
	}

	ans := 0
	for i := 0; i < N; i++ {
		ok := true
		for _, v := range edge[i] {
			if h[i] <= h[v] {
				ok = false
				break
			}
		}
		if ok {
			ans++
		}
	}
	out(ans)
}


Measured memory_bytes: 11984