akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    static int[][] graph;
    static int[] color;
    static long wCnt = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        graph = buildGraph(sc, N, M);
        long ans = 0;
        color = new int[N];
        if (dfs(0, 0, 1)) {
            ans = wCnt * (N - wCnt) - M;
        } else{
           ans = ((long) N * (N - 1)) / 2 - M;
        }
        System.out.println(ans);
        sc.close();

    }

    private static boolean dfs(int pre, int cur, int c) {
        color[cur] = c;
        if(c == 1) wCnt++;
        boolean ret = true;
        for(int i = 0; i < graph[cur].length; i++){
            int x = graph[cur][i];
            if(color[x] == 0){
                if(x == pre) continue;
                ret &= dfs(cur, x, -c);
            }else if(color[x] != -c){
                ret = false;
            }
            if(!ret) break;
        }

        return ret;
    }

    public static int[][] buildGraph(Scanner sc, int n, int m){
        int[][] graph = new int[n][];
        int[][] edges = new int[m][2];
        int[] deg = new int[n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() -1;
            int b = sc.nextInt() -1;
            edges[i][0] = a;
            edges[i][1] = b;
            deg[a]++;
            deg[b]++;
        }
        for (int i = 0; i < n; i++) {
            graph[i] = new int[deg[i]];
        }
        for (int i = 0; i < m; i++) {
            int a = edges[i][0];
            int b = edges[i][1];
            graph[a][--deg[a]] = b;
            graph[b][--deg[b]] = a;
        }

        return graph;
    }

}

Measured memory_bytes: 95668
def linearSearch(S, T):
    n = 0
    for t in T:
        for s in S:
            if s == t:
                n += 1
                break
    return n

if __name__ == "__main__":
    input()
    S = raw_input().split()
    input()
    T = raw_input().split()
    print linearSearch(S, T)

Measured memory_bytes: 6436
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;

void main() {
    int N = readln.chomp.to!int;
    foreach(int i; 0..N) {
        long[] input = readln.split.to!(long[]);
        long x = input[0];
        long y = input[1];
        long b = input[2];
        long p = input[3];

        long value1 = x*b + y*p;
        long value2 = (x*max(b, 5) + y*max(p, 2))*8/10;
        min(value1, value2).writeln;
    }
}

Measured memory_bytes: 2488
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String a[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        System.out.println(getAnswer(n));
    }

    static long getAnswer(int n) {
        int a = 1;
        for (int i = 1; i <= 2; i++) {
            a *= n;
        }
        return a * n;
    }
    
}


Measured memory_bytes: 24316
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a,v,b,w,t;
    
    a = sc.nextInt();
    v = sc.nextInt();
    b = sc.nextInt();
    w = sc.nextInt();
    t = sc.nextInt();
    
    if(Math.abs(a-b) <= ((v-w)*t)){
        System.out.println("YES");
    }else{
   		System.out.println("NO");
   	}
  }
}

Measured memory_bytes: 35724
red_to_eat, green_to_eat, num_red, num_green, num_white = gets.split.map(&:to_i)
reds = gets.split.map(&:to_i).sort
greens = gets.split.map(&:to_i).sort
whites = gets.split.map(&:to_i).sort

res = 0

(red_to_eat + green_to_eat).times do
  ary = []
  ary.push([whites[-1], :white]) if whites.length > 0
  ary.push([reds[-1], :red]) if reds.length > 0 and red_to_eat > 0
  ary.push([greens[-1], :green]) if greens.length > 0 and green_to_eat > 0
  
  tmp = ary.max_by {|el| el[0] }
  res += tmp[0]
  
  case tmp[1]
  when :white
    whites.pop
  when :red
    reds.pop
    red_to_eat -= 1
  when :green
    greens.pop
    green_to_eat -= 1
  end
end

puts res

Measured memory_bytes: 32488
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    K_max = (N-1)*(N-2) // 2
    if K > K_max:
        print(-1)
        return

    edges = [ [False] * N for _ in range(N) ]

    def star():
        for i in range(1, N):
            edges[0][i] = True
            edges[i][0] = True

    def add_edge():
        for i in range(1, N):
            for j in range(i+1, N):
                if not edges[i][j]:
                    edges[i][j] = True
                    edges[j][i] = True
                    return

    star()
    for i in range(K_max, K, -1):
        add_edge()

    result = []
    for i in range(N):
        for j in range(i+1, N):
            if edges[i][j]:
                result.append((i+1, j+1))

    print(len(result))
    for i, j in result:
        print("{} {}".format(i, j))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3716
# coding: utf-8
import sys
input = sys.stdin.readline

def f(n, k, h):
    dp = [0] * n
    for i in range(1, n):
        js = max(i - k, 0)
        dp[i] = min(dp[j] + abs(h[i] - h[j]) \
            for j in range(js, i))
    return(dp[i])

n, k = map(int, input().rstrip().split())    # 2 <= n <= 10^5, 1 <= k <= 100
h = list(map(int, input().rstrip().split()))

print(f(n, k, h))


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

typedef long long ll;

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,l,n) for(int i=(l);i<(n);i++)

template<class T>
using vt = vector<T>;
template<class T>
using vvt = vector<vector<T>>;


int main(){
    int A,B;
    cin >> A >> B;
    if(A+B >= 10) cout << "error" << endl;
    else cout << A+B << endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<set>
#include<iomanip>
#define pi 3.14159265358979323846
#define ll long long
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  if(n % 2 == 1){
    cout << "No\n";
    return 0;
  }
  n = n / 2;
  string ss = s.substr(n);
  rep(i, 0, n){
    if(s[i] != ss[i]){
      cout << "No\n";
      return 0;
    }
  }
  
  cout << "Yes\n";
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[2000],memo[2][2000][2000];
long long sum(int j,int left,int right){
  if(left == right){
    if(j == 0) return 0;
    if(j == 1) return a[left];
  }
  if(memo[j][left][right] != -1) return memo[j][left][right];
  long long res = 0;
  if(j == 0){
    if(a[left] > a[right]){
      if(left == 0) res = max(res,sum(1,n-1,right));
      else res = max(res,sum(1,left-1,right));
    } else {
      if(right == n-1) res = max(res,sum(1,left,0));
      else res = max(res,sum(1,left,right+1));
    }
  }if(j == 1){
      if(left == 0) res = max(res,sum(0,n-1,right)+a[left]);
      else res = max(res,sum(0,left-1,right)+a[left]);
      if(right == n-1) res = max(res,sum(0,left,0)+a[right]);
      else res = max(res,sum(0,left,right+1)+a[right]);
  }
  return memo[j][left][right] = res;
}
int main(){
  long long ans = 0;
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  fill_n(**memo,2*2000*2000,-1);
  for(int i=0;i<n;i++){
    ans = max(ans,sum(0,i==0?n-1:i-1,i==n-1?0:i+1)+a[i]);
  }
  cout << ans << endl;
  return (0);
}

Measured memory_bytes: 65752
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>
#define endl "\n"
using namespace std;

int main()
{
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  if ( a[0]+a[1] == a[2] )
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
int main(){
    ll N;
    cin>>N;
    
    ll cnt=0;
    REP1(i,N){
        ll t;
        cin>>t;
        if(i%2==1&&t%2==1){
            cnt++;
        }
    }
    
    cout<<cnt;//+(H%D==0?1:0);
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3620
gets.to_i
a = gets.split.map(&:to_i).tally

a.default_proc = -> _, _ { 0 }
o = a.sum { |k, v| k * v }

gets.to_i.times {
  b, c = gets.split.map &:to_i
  o = o - b * a[b] + c * a[b]
  a[b], a[c] = 0, a[b] + a[c]
  puts o
}

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

int N,A[200000];
ll res;
map<int,int>mp;

int main(){
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A[i];
		A[i]-=i;
		mp[A[i]]++;
	}
	for(int i=0;i<N;i++){
		mp[A[i]]--;
		res+=mp[-A[i]-i-i];
	}
	cout<<res<<endl;
}


Measured memory_bytes: 21288
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
//const int mod = 1e9 + 7;
const int mod = 998244353;

int main(){
    ll n,m,x; cin >> n >> m >> x;
    vl c(n);
    vvl a(n,vl(m));
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    ll ans = linf;
    rep(bit,1<<n){
        vl sum(m,0);
        ll money = 0;
        rep(i,n){
            if(bit>>i & 1){
                rep(j,m){
                    sum[j] += a[i][j];
                }
                money += c[i];
            }
        }
        bool flag = true;
        rep(j,m){
            if(sum[j] < x){
                flag = false;
                break;
            }
        }
        if(flag) chmin(ans, money);
    }
    if(ans == linf) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define ll long long
#define F(type, i, a, b) for(type i = a; i <= b; i ++)
#define RF(type, i, a, b) for(type i = a; i >= b;i --)
#define sz(a) sizeof(a)
#define deb(a) cerr<<" ["<<#a<<"->"<<a<<"] "
#define next_line cerr<<'\n'
#define all(a) a.begin(), a.end()
#define iter(it, s) for(auto it = s.begin(); it != s.end(); it ++)

using namespace std;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll Mat[3001][3001], dp[3001][3001][4];
ll r, c, k;

ll INF = 1e16;

ll MaxVal(ll st_i, ll st_j, ll pick_n){
    if((st_i == (r - 1)) && (st_j == (c - 1)))
        return ((pick_n != 3LL) * Mat[st_i][st_j]);
    if(dp[st_i][st_j][pick_n] != -1LL)
        return dp[st_i][st_j][pick_n];
    ll ans = 0LL;
    if(st_i < (r - 1LL))  {
        ans = MaxVal(st_i + 1LL, st_j, 0LL);   
        if(pick_n != 3LL)
            ans = max(ans, MaxVal(st_i + 1LL, st_j, 0LL) + Mat[st_i][st_j]);
    }
    if(st_j < (c - 1LL)){
        ans = max(ans, MaxVal(st_i, st_j + 1LL, pick_n));
        if(pick_n != 3LL)
            ans = max(ans, MaxVal(st_i, st_j + 1LL, pick_n + 1LL) + Mat[st_i][st_j]);
    }
    dp[st_i][st_j][pick_n] = ans;
    return ans;
}

void solve()
{
    cin>>r>>c>>k;
    F(int, i, 0, 3000){
        F(int, j, 0, 3000){
            F(int, k, 0, 3){
                dp[i][j][k] = -1LL;
            }
        }
    }
    F(int, i, 0, k - 1){
        ll r1,c1,v;
        cin>>r1>>c1>>v;
        Mat[r1 - 1][c1 - 1] = v;
    }
    cout<<MaxVal(0, 0, 0);
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        freopen("Debug.txt", "w", stderr);
    #else
    #endif
        solve();
}


Measured memory_bytes: 355640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define endl '\n'

int t=1,T;

void print2d(vector<vector<int>> &v){
    for(int i=0;i<v.size();i++){
        for(int x:v[i]){
            cout << x <<' ';
        }
        cout <<endl;
    }
}

void print(vector<int> &a){
    for(int x : a){
        cout << x <<' ';
    }
    cout << endl;
    return;
}

int fun(int x,int y){
    return x*x+y*y;
}

void solve(){
    int n;cin >> n;
    string s;cin >> s;
    int r=0;
    for(char c:s){
        if(c=='R')r++;
    }
    int ans=0;
    for(int i=0;i<r;i++){
        if(s[i]=='W')ans++;
    }
    cout << ans <<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    #ifndef ONLINE_JUDGE
    freopen("/home/harsha/Desktop/code/input.txt","r",stdin);
    freopen("/home/harsha/Desktop/code/output.txt","w",stdout);
    #endif

    // cin >> t;
    T = t;
    while(t--){
        solve();   
    }

    return 0;
}

/*

*/

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main(){
  int N = 0;
  cin >> N;
  set<int> s;
  s.insert(N);
  rep(i,1000000){
    if(N % 2 == 0){
      N /= 2;
    }
    else{
      N = N * 3 + 1;
    }
    s.insert(N);
    if(s.size() != i+2){
      cout << s.size() + 1;
      return 0;
    }
  }
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n, m, x;
	cin >> n >> m >> x;
	int up = 0;
	int dn = 0;  
	rep(i,m){
		int a;
		cin >> a;
		if(x<a) up++;
		else if(x>a) dn++;
	}
  
	cout << min(up, dn) << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
S = list(input())

i = len(S)-1
while i >= 4:
    if S[i-4:i+1] == ['d', 'r', 'e', 'a', 'm'] or S[i-4:i+1] == ['e', 'r', 'a', 's', 'e']:
        i -= 5
    elif i-5 >= 0 and S[i-5:i+1] == ["e", "r", "a", "s", "e", "r"]:
        i -= 6
    elif i-6 >= 0 and S[i-6:i+1] == ["d", "r", "e", "a", "m", "e", "r"]:
        i -= 7
    else:
        break
        
if i == -1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int N;
    int a[330000];
    cin>>N;
    for(int i=0;i<3*N;i++)cin>>a[i];
    sort(a,a+3*N);
    reverse(a,a+3*N);
    long long sum=0;
    for(int i=0;i<N;i++)sum+=a[2*i+1];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1408
# -*- coding:utf-8 -*-
pri = []
is_pri = [1 for i in range(100005)]
is_pri[0] = is_pri[1] = 0
sm = [0] * 100005

for i in range(2, 100005):
    if is_pri[i]:
        pri.append(i)
    for j in pri:
        if i * j < 100005:
            is_pri[i * j] = 0
        if i * j >= 100005 or i % j == 0:
            break

for i in range(100005):
    if is_pri[i] and is_pri[int((i + 1) / 2)]:
        sm[i] = 1

for i in range(1, 100005):
    sm[i] += sm[i - 1]

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


Measured memory_bytes: 7564
#include <stdio.h>
#define MAX_N 1000
#define MAX_W 1000

int dp[MAX_N + 1][MAX_W + 1];
int vin[MAX_N];
int win[MAX_N];
int count;

int max(int a, int b) {
  return (a > b) ? a : b;
}

void calcAns(int n, int w) {
  int i, j, wsum;
  for (j = 0; j < w + 1; j++)
    dp[n][j] = 0;

  for (i = n - 1; i >= 0; i--) {
    for (j = 0; j <= w; j++) {
      if (j < win[i]) {
	dp[i][j] = dp[i + 1][j];
      } else {
	dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - win[i]] + vin[i]);
      }
    }
  }

  for (j = w; j > 0; j--)
    if (dp[0][j] > dp[0][j - 1]) break;
  wsum = j;
  printf("Case %d:\n", count++);
  printf("%d\n", dp[0][w]);
  printf("%d\n", wsum);
}

int main(void) {
  int w, n, i;
  count = 1;
  while (1) {
    scanf("%d", &w);
    if (w == 0) return 0;
    scanf("%d", &n);

    for (i = 0; i < n; i++)
      scanf("%d,%d", &vin[i], &win[i]);

    calcAns(n, w);
  }
}

Measured memory_bytes: 4520
use proconio::input;

const MOD: usize = 2019;
fn main() {
  input! {
    l: usize,
    r: usize
  }

  let diff = if r - l > MOD {
    2100
  } else {
    r - l
  };
  
  let mut stack = vec![];
  let mut min = usize::max_value();
  for i in l..=l+diff {
    stack.push(i);
  }
  
  for i in 0..stack.len() {
    for ii in i+1..stack.len() {
      min = std::cmp::min(min, stack[i] * stack[ii] % MOD); 
    }
  }

  println!("{}", min);
}

Measured memory_bytes: 2068
#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>;

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main()
{
    int h, w;
    cin >> h >> w;
    int si, sj;
    cin >> si >> sj;
    int ti, tj;
    cin >> ti >> tj;
    --si;
    --sj;
    --ti;
    --tj;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    const int INF = 1e9;
    vector<vector<int>> dist(h, vector<int>(w, INF));
    deque<P> q;
    dist[si][sj] = 0;
    q.emplace_back(si, sj);
    while (!q.empty())
    {
        int i = q.front().first;
        int j = q.front().second;
        int d = dist[i][j];
        q.pop_front();
        if (dist[i][j] != d)
            continue;
        rep(v, 4)
        {
            int ni = i + di[v], nj = j + dj[v];
            if (ni < 0 || ni >= h || nj < 0 || nj >= w)
                continue;
            if (s[ni][nj] == '#')
                continue;
            if (dist[ni][nj] <= d)
                continue;
            dist[ni][nj] = d;
            q.emplace_front(ni, nj);
        }
        for (int ei = -2; ei <= 2; ++ei)
        {
            for (int ej = -2; ej <= 2; ++ej)
            {
                int ni = i + ei, nj = j + ej;
                if (ni < 0 || ni >= h || nj < 0 || nj >= w)
                    continue;
                if (s[ni][nj] == '#')
                    continue;
                if (dist[ni][nj] <= d + 1)
                    continue;
                dist[ni][nj] = d + 1;
                q.emplace_back(ni, nj);
            }
        }
    }
    int ans = dist[ti][tj];
    if (ans == INF)
        ans = -1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 9436
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        
        AtCoder problem = new AtCoder(sc);
        problem.solve(out);
        
        out.flush();
    }
    
}

class AtCoder {
    int a;
    String s;
    AtCoder(FastScanner sc) {
        a = sc.nextInt();
        s = sc.next();
    }

    void solve(PrintWriter out) {
        out.println(a >= 3200 ? s : "red");
    }
    
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
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());
    }
}


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

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

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

  vector<int> cost(N);
  cost.at(0) = 0;
  cost.at(1) = abs(h.at(1) - h.at(0));

  for (int i = 2; i < N; i++)
  {
    cost.at(i) =
        min(cost.at(i - 2) + abs(h.at(i) - h.at(i - 2)),
            cost.at(i - 1) + abs(h.at(i) - h.at(i - 1)));
  }

  cout << cost.at(N - 1) << endl;
}

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

#define ll long long
int n,x;
ll cnt=0;
vector<ll> a,b;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<=n;i++){
		cin>>x;
		a.push_back(x);
	}
	for(int i=0;i<n;i++){
		cin>>x;
		b.push_back(x);
	}
	for(int i=0;i<n;i++){
		if(b[i] <= a[i] + a[i+1]){
			if(a[i] > b[i])
				a[i] -= b[i];
			else
				a[i+1] -= abs(b[i] - a[i]);

			cnt += b[i];
		}
		else{
			cnt += a[i] + a[i+1];
			a[i] = 0; a[i+1] = 0;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 2548
integer(8) n, c, s
integer(8), allocatable :: a(:)
read *, n
allocate(a(n))
read *, a
c = count(a < 0)
a = abs(a)
s = sum(a)
print *, merge(s, s - minval(a) * 2, mod(c, 2) == 0)
end


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        deque<char> dq;
        for (char c : s) dq.push_back(c);

        int q;
        cin >> q;

        bool mode = true;
        REP(_, q) {
                int t;
                cin >> t;

                if (t == 1) {
                        mode = !mode;
                } else {
                        int f;
                        char c;
                        cin >> f >> c;

                        if (mode && f == 1 || !mode && f != 1) {
                                dq.push_front(c);
                        } else {
                                dq.push_back(c);
                        }
                }
        }

        if (!mode) reverse(dq.begin(), dq.end());

        for (char c : dq) cout << c;
        cout << endl;

        return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

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

int main() {
	int h, w;
	cin >> h >> w;
	vvs s(h + 2, vs(w + 2, "."));
	rep(i, 0, h) {
		string t;
		cin >> t;
		rep(j, 0, w) {
			s[i + 1][j + 1] = t[j];
		}
	}
	vvs ans(h, vs(w));
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (s[i + 1][j + 1] == "#") {
				ans[i][j] = "#";
			}
			else {
				int cou = 0;
				rep(k, 0, 8) {
					if (s[i + 1 + dx[k]][j + 1 + dy[k]] == "#") {
						cou++;
					}
				}
				ans[i][j] = to_string(cou);
			}
		}
	}
	rep(i, 0, h) {
		rep(j, 0, w) {
			cout << ans[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
	int n,i,j,s[100],ans=0,min=-1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&s[i]);
		ans+=s[i];
	}
	if(ans%10!=0)printf("%d\n",ans);
	else{
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				if(s[i]<s[j]){
					int tmp=s[i];
					s[i]=s[j];
					s[j]=tmp;
				}
			}
		}
		for(i=0;i<n;i++){
			if(s[i]%10!=0){
				min=s[i];
				break;
			}
		}
		if(min!=-1)printf("%d\n",ans-min);
		else puts("0");
	}
	return 0;
}

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

int main()
{
    string s;
    cin>>s;
    
    if(s[s.length()-1]=='s')
    s=s+"es";
    
    else
    s=s+'s';
    
    cout<<s<<endl;
    
    return 0;
}

Measured memory_bytes: 3604
//四則演算 #pragma GCC target("avx")
//並列計算 #pragma GCC optimize("O3")
//条件分岐を減らす #pragma GCC optimize("unroll-loops")
//浮動小数点演算 #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(i) sort(i.begin(),i.end())
#define rSORT(i) sort(i.rbegin(),i.rend())
#define fSORT(i,a) sort(i.begin(),i.end(),a)
#define all(i) i.begin(),i.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    string s; cin >> s;
    each(i, s)if (i == '?')i = 'D';
    print(s);

    return 0;
}


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


int main(){
    string abcd;
    cin >> abcd;
    
    vector<int> a(4);
    for(int i=0; i<4; i++){
        a[i] = abcd[i]-'0';
    }
    
    for(int bit=0; bit < (1<<4); bit++){
        vector<char> ans;
        int sum=a[0];
        ans.push_back(abcd[0]);
        for(int i=1; i<4; i++){
            if(bit & (1<<i)){
                sum += a[i];
                ans.push_back('+');
                ans.push_back(abcd[i]);
            }
            else {
                sum -= a[i];
                ans.push_back('-');
                ans.push_back(abcd[i]);
            }
        }
        if(sum==7){
            ans.push_back('=');
            ans.push_back('7');
            for(int i=0; i<(int)ans.size(); i++){
                cout << ans[i];
            }
            cout << endl;
            break;
        }
        while(!ans.empty())
            ans.pop_back();
    }
}

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

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VC vector<char>
#define VS vector<string>
#define FOREACH(x,a) for(auto& (x) : (a) )
using namespace std;

int main() {
	int n, m, x, y;
	cin >> n >> m >> x >> y;
	VI vx(n);
	VI vy(m);
	REP(i, n) cin >> vx[i];
	REP(i, m) cin >> vy[i];
	sort(ALL(vx));
	sort(ALL(vy));
	FOR(i, x + 1, y + 1) {
		if (vx[n - 1] < i&&vy[0] >= i) {
			cout << "No War" << endl;
			return 0;
		}
	}
	cout << "War" << endl;
	return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  A-regular_triangle
//
//  Created by david chong on 8/21/19.
//  Copyright © 2019 david chong. All rights reserved.
//

#include <iostream>
#include <string>
#include <limits>

using namespace std;


string solve(int a, int b, int c) {
    
    string result = "No";
    if(a > 0 && a == b && b == c) {
        result = "Yes";
    }
    return result;
}


int main(int argc, const char * argv[]) {
    
//    freopen("input.in", "r", stdin);
    
    int a, b, c;
    
    cin >> a >> b >> c;
    
    cout << solve(a, b, c) << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def popcount(n):
    ret = 0
    while n:
        ret += n & 1
        n >>= 1
    return ret


def main():
    N = readint()
    X = readstr()
    s = sum(tuple(map(int, X)))
    s1 = s + 1
    s2 = s - 1 if s != 1 else 1
    m1 = int(X, 2) % s1
    m2 = int(X, 2) % s2
    t1 = [1]
    t2 = [1]
    for i in range(N):
        t1.append(t1[i] * 2 % s1)
        t2.append(t2[i] * 2 % s2)
    for i in range(N):
        ans = 0
        if X[i] == '0':
            x = (m1 + t1[(N - i - 1)]) % s1
        else:
            if s == 1:
                print(0)
                continue
            else:
                x = (m2 - t2[(N - i - 1)]) % s2
        d = popcount(x)
        ans += 1
        while x:
            x %= d
            d = popcount(x)
            ans += 1
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 28076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const int MOD = 1e9 + 7;

ll dfs(const int &K, const vector<vector<int>> &graph, int now, int from){
    
    int can_use_color_num;
    if(from == -1) can_use_color_num = K - 1;
    else can_use_color_num = K - 2;

    if(graph[now].size() >= K ) return 0;
    
    ll case_num = 1;
    for(auto e: graph[now]){
        if(e == from) continue;
        
        case_num *= can_use_color_num;
        can_use_color_num--;
        case_num %= MOD;
    }
    for(auto e: graph[now]){
        if(e == from) continue;

        case_num *= dfs(K, graph, e, now);
        case_num %= MOD;
    }
    return case_num;
}
 
int main(){
    int N, K; cin >> N >> K;
    vector<vector<int>> graph(N);
    for(int i = 0; i < N-1; i++){
        int a, b; cin >> a >> b; a--, b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    ll res  =   K * dfs(K, graph, 0, -1) % MOD;
    cout << res << endl;
}

Measured memory_bytes: 11520
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N, K;

int main(void)
{
	cin >> N >> K;
	map<int, int>p;
	for (int i = 0; i < N; ++i) {
		int t;
		cin >> t;
		p[t]++;
	}
	vector<int>vec;
	for (auto& m : p) {
		vec.push_back(m.second);
	}
	if (vec.size() < K) {
		cout << "0\n";
		return 0;
	}
	sort(vec.begin(), vec.end());
	int ans = 0;
	for (int i = 0; i < ((int)vec.size() - K); ++i) {
		ans += vec[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 10748
#include<stdio.h>
int main(void)
{
	int N,X,Y,Z,i,k,g=0,a[101][3]={0};
	scanf ("%d",&N);
	scanf ("%d",&X);
	for (i=0;i<X;i++)
	{
		scanf ("%d",&k);
		a[k][0]=1;
	}
	scanf ("%d",&Y);
	for (i=0;i<Y;i++)
	{
		scanf ("%d",&k);
		a[k][1]=1;
	}
	scanf ("%d",&Z);
	for (i=0;i<Z;i++)
	{
		scanf ("%d",&k);
		a[k][2]=1;
	}
	for (i=0;i<=N;i++)
	{
		if (a[i][0]==0&&a[i][2]==1||a[i][1]==1&&a[i][2]==1)
		g=g+1;
	}
	printf ("%d\n",g);
	return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define pb emplace_back
#define fi first
#define se second
#define mp make_pair
#define all(x) x.begin(), x.end()
#define in(x); { for (auto &qwertyhgfdsa : x) cin >> qwertyhgfdsa; }
#define out(x); { for (auto qwertyhgfdsa : x) cout << qwertyhgfdsa << ' '; cout << endl; }
#define int long long

typedef long long ll;

using namespace std;

const int INF = 1e9;
const long long INFll = 2e18;
const long long base1 = 239;
const long long base2 = 653;
const long long mod = 1e9 + 7;
const double eps = 1e-6;
const int len = 140;



void solve() {
    unsigned long long a, b, c;
    cin >> a >> b >> c;
    if (a >= c || b >= c) {
        cout << "No"; return;
    }
    if (4 * a * b < (c - a - b) * (c - a - b))
        cout << "Yes";
    else
        cout << "No";
}

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

    solve();
}


Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll N,W,w[105]={},v[105]={},dp[105][100005]={};
  cin >> N >> W;
  for(int i=1; i<=N; i++) {
    cin >> w[i] >> v[i];
  }
  for(int i=1; i<=N; i++) {
    for(int j=0; j<=W; j++) {
      if(j-w[i]>=0) {
        dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
      }
      else {
        dp[i][j]=dp[i-1][j];
      }
    }
  }
  cout << dp[N][W] << endl;
}

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

n = [0]*(N+1)
for i in range(2, N+1):
    for j in range(2, i+1):
        while i%j == 0:
            i//=j
            n[j] += 1

def num(m):
    return len(list(filter(lambda x: x>=m-1, n)))

print(num(75)+num(25)*(num(3)-1)+num(15)*(num(5)-1)+num(5)*(num(5)-1)*(num(3)-2)//2)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstdlib>

#define SPACE string(" ")

using namespace std;

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

	int *i_ary = new int[n];

	string str;
	cin >> ws;
	getline(cin, str);

	string::size_type spos = 0;
	string::size_type epos = 0;
	int i = 0;

	while ((epos = str.find(SPACE, spos)) != string::npos) {
		if (str.substr(spos, epos - spos) != "") {
			i_ary[i++] = atoi(str.substr(spos, epos - spos).c_str());
		}
		spos = epos + SPACE.length();
	}
	i_ary[i] = atoi(str.substr(spos).c_str());

	for (int j = 0; j < ((i + 1) / 2); j++) {
		int tmp = i_ary[j];
		i_ary[j] = i_ary[i - j];
		i_ary[i - j] = tmp;
	}
	
	for (int k = 0; k < i; k++) {
		cout << i_ary[k] << SPACE;
	}
	cout << i_ary[i] << endl;

	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
#define PI 3.14159265358979
//const int64_t INF = 1LL << 60;
const int INF = 1 << 29;
//const int64_t MOD = 1000000007;
//const int64_t INF = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef pair<int64_t, int64_t> P;

int main(){
    int N;
    cin >> N;
    vector<vector<int>> c(11, vector<int>(11));
    rep(i, 1, N + 1){
        string S = to_string(i);
        int start = S.at(0) - 48;
        int end = S.at(S.size() - 1) - 48;
        //cout << start << " " << end << endl;
        c.at(start).at(end)++;
    }
    
    int64_t ans = 0;
    rep(i, 1, 9){
        rep(j, i + 1, 10){
            ans += c.at(i).at(j) * c.at(j).at(i) * 2;
        }
    }
    rep(i, 1, 10){
        ans += c.at(i).at(i) * c.at(i).at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
k = ri()
cur = 1
for _ in range(n):
  if cur < k:
    cur *= 2
  else:
    cur += k
print(cur)
  







Measured memory_bytes: 26888
#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, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i, m) {
    cin >> a[i] >> b[i];
    --a[i]; --b[i];
  }

  vector<int> cnt(n, 0);
  rep(i, m) {
    ++cnt[a[i]];
    ++cnt[b[i]];
  }
  bool exist = true;
  rep(i, n) if (cnt[i] % 2) exist = false;
  if (exist) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

Measured memory_bytes: 4508
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <array>
#include <bitset>
#include <assert.h>
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 ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

void calc(VI &x, VI y){
    REP(i,3) x[i] = y[x[i]];
}

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

    VI good(3);
    REP(i,3) good[i] = i;

    VVI p(n, VI(3));
    REP(i,n){
        int w = in();
        VI tmp(3);
        REP(j,3) tmp[j] = j;

        REP(j,w){
            int x = in();
            swap(tmp[x], tmp[x+1]);
        }

        if (tmp == good){
            cout << "yes" << endl;
            return 0;
        }

        REP(j,3){
            p[i][tmp[j]] = j;
        }
    }

    REP(i,n) REP(j,i){
        VI tmp(3);
        REP(k,3) tmp[k] = k;

        calc(tmp, p[i]);
        calc(tmp, p[j]);

        if (tmp == good){
            cout << "yes" << endl;
            return 0;
        }
    }

    // REP(i,n){
    //     REP(j,3) cout << p[i][j] << " ";
    //     cout << endl;
    // }

    REP(i,n) REP(j,n) REP(l,n){
        if (i == j || j == l || l == i) continue;
        VI tmp(3);
        REP(k,3) tmp[k] = k;

        calc(tmp, p[i]);
        calc(tmp, p[j]);
        calc(tmp, p[l]);


        if (tmp == good){
            cout << "yes" << endl;
            return 0;
        }
    }

    cout << "no" << endl;

    return 0;
}


Measured memory_bytes: 3236
n = int(input())
m = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
  nums = list(map(lambda x:int(x)-1, input().split()))
  f = nums[0]
  nums = nums[2:]
  for num in nums:
    m[f][num] = 1

for i in range(n):
  for j in range(n):
    if(j!=n-1):
      print(m[i][j], end=' ')
    else:
      print(m[i][j])


Measured memory_bytes: 6388
#include<iostream>
using namespace std;
int n,m,p,x,a;
int t[100];
int main()
{
  cin >> n;
  for (int i = 0;i<n;i++)
  {
    cin >> t[i];
  }
  cin >> m;
  for(int i=0;i<m;i++)
  {
    cin >> p >> x;
    int a = t[p - 1];
    t[p - 1] = x;
    int cnt=0;
    for (int j = 0; j < n;j++)
    {
      cnt += t[j];
    }
    cout << cnt << endl;
    t[p - 1] = a;
  }
}

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

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for (int i = 0; i < h; i++)
  {
    cin >> s[i];
  }
  int dh[] = {0,0,-1,1};
  int dw[] = {1,-1,0,0};
  int ans = 0;
  
  for (int i = 0; i < h; i++)
  {
    for (int j = 0; j < w; j++)
    {
      int sh,sw;
      if(s[i][j]=='#') continue;
      sh = i, sw = j;
      vector<vector<int>> dist(h,vector<int>(w,-1));
      queue<pair<int,int>> que;
      dist[sh][sw] = 0;
      que.emplace(sh,sw);
      while(!que.empty()){
        int ch = que.front().first;
        int cw = que.front().second;
        que.pop();
        for (int d = 0; d < 4; d++)
        {
          int nh = ch + dh[d];
          int nw = cw + dw[d];
          if(nh<0 || nh>=h || nw<0 || nw>=w) continue;
          if(s[nh][nw]=='#') continue;

          if(dist[nh][nw] == -1){
            dist[nh][nw] = dist[ch][cw] + 1;
            que.emplace(nh,nw);
          }
        }
      }
      int dis = 0;
      for (int hh = 0; hh < h; hh++)
      {
        for (int ww = 0; ww < w; ww++)
        {
          dis = max(dis,dist[hh][ww]);
        }        
      }
      ans = max(ans,dis);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;
int main(){
  string a,b,c;
  std::cin >> a>>b>>c;
  char turn ='a';
  int flag=0;
  
  do {
    switch (turn) {
      case 'a':{

        if(a.length()!=0){
          turn=a[0];
          a.erase(0,1);
          break;
        }
        else flag=1;
        break;
      }
      case 'b':{

        if(b.length()!=0){
          turn=b[0];
          b.erase(0,1);
          break;
        }
        else flag=2;
        break;
      }
      case 'c':{
        if(c.length()!=0){
          turn=c[0];
          c.erase(0,1);
          break;
        }
        else flag=3;
        break;
      }
    }

  } while(flag==0);

  if(flag==1)std::cout << "A" << '\n';
  if(flag==2)std::cout << "B" << '\n';
  if(flag==3)std::cout << "C" << '\n';


  return 0;
}


Measured memory_bytes: 256