akhauriyash/Code-Regression huggingface dataset:
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;
import java.util.AbstractMap.SimpleEntry;

public class Main {

    static final int modnum = 1000000000 + 7;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        ArrayList<AbstractMap.SimpleEntry<Integer, Integer>> list = new ArrayList<AbstractMap.SimpleEntry<Integer, Integer>>();
        for (int i = 0; i < N; i++) {
            int work = sc.nextInt();
            int limit = sc.nextInt();
            list.add(new AbstractMap.SimpleEntry<Integer, Integer>(limit, work));
        }
        Collections.sort(list, Comparator.comparing(AbstractMap.SimpleEntry<Integer, Integer>::getKey));
        long time = 0;
        for (int i = 0; i < N; i++) {
            AbstractMap.SimpleEntry<Integer, Integer> working = list.get(i);
            if (time + working.getValue() <= working.getKey()) {

                // System.out.println(time + "   " + working.getKey() + "   " + working.getValue() + "   "
                //         + (working.getKey() + working.getValue()));
                time += working.getValue();
            }else{
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
        // long time = list.get(list.size() - 1).getKey() + list.get(list.size() -
        // 1).getValue();
        // while (!list.isEmpty()) {
        // int i;

        // for (i = list.size() - 1; i >= 0; i--) {
        // AbstractMap.SimpleEntry<Integer, Integer> working = list.get(i);
        // if (working.getKey() + working.getValue() <= time) {

        // System.out.println(time + " " + working.getKey() + " " + working.getValue() +
        // " "
        // + (working.getKey() + working.getValue()));
        // time -= working.getValue();
        // list.remove(i);
        // break;
        // }
        // }
        // if (i < 0) {
        // System.out.println("aaa");

        // AbstractMap.SimpleEntry<Integer, Integer> working = list.get(list.size() -
        // 1);
        // time = working.getKey() + working.getValue();
        // }
        // }

        // if (time < 0) {
        // System.out.println("No");
        // } else {
        // System.out.println("Yes");
        // }
    }
}

Measured memory_bytes: 117368
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m; cin>>n>>m;
    cout << (n*(n-1))/2+(m*(m-1))/2 << '\n';
    return 0;
}

Measured memory_bytes: 3632
n = int(input())
d = dict()

for i,x in enumerate(input().split(" ")):
    d[str(i+1)] = int(x)


d_sorted = sorted(d.items(), key=lambda x:x[1])
ans = []
for i in range(n):
    ans.append(d_sorted[i][0])
print(' '.join(ans))


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

#define iosx ios_base::sync_with_stdio(false);cin.tie(0);cout.precision(20)
#define hell 1000000007LL
#define INF 100000000000000000LL
#define hmap unordered_map
#define hset unordered_set
#define PQ priority_queue
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define lld long double
#define ll int
#define all(C) begin(C),end(C)
#define rep(i,a,b) for(ll i = (a); i < (b); ++(i))
#define pb push_back
#define vi vector<ll>
#define vs vector<string>
#define pii pair<ll,ll>
#define len(C) (ll)(C).size()
#define lexcmp lexicographical_compare
#define whats(C,n) 	rep(i,0,n) cout<<(C)[i]<<" \n"[i+1==n]
#define what(V)     cout<<(V)<<'\n'

void solve(int tm){
	lld n,k;
	cin>>n>>k;

	lld ans=0;

	for(lld i=1; i<=n; i += 1)
		if (i >= k)
			ans += 1;
		else
			ans += 1.0/(1<<((int)ceil(log2(k/i))));

	cout<<(ans/n);
}


	// rep(i,0,n)
		// cout<<a[i]<<" \n"[i+1==n];

// g++.exe -static -DONLINE_JUDGE -lm -s -x c++ -Wl,--stack=268435456 -O2 -std=c++14 sol.cpp & a.exe & del a.exe
// vim cli: !g++ -static -lm -s -x c++ -O2 -std=c++14 sol.cpp -o out; ./out; 
int main(){ 
	iosx; 
	int t=1;
    // cin >> t;

	for(int i=1; i<=t; ++i)
        solve(i);

	return 0;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  
  cout<<(b-1+a-2)/(a-1)<<endl;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    string S; cin >> S;
    bool isGu = false;
    S.pop_back();
    while (!isGu)
    {
        int ssize = S.size();
        if (ssize % 2 == 0)
        {
            string S1, S2;
            S1 = S.substr(0, ssize/2);
            S2 = S.substr(ssize/2, ssize/2);
            if (S1==S2)
            {
                isGu = true;
            }
            else
            {
                S.pop_back();
            }
        }
        else
        {
            S.pop_back();
        }
    }
    cout << S.size() << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
	int n,k,sum=0;
	cin>>n>>k;
	vector <int> v1 (n);
	for (int i=0;i<n;i++)
		cin>>v1[i];
	sort(v1.begin(),v1.end());
	for (int i=0;i<k;i++)
		sum+=v1[i];
	cout<<sum<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 1000000007
#define bitcnt(a) (ll) __builtin_popcount((a))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll n;
  cin >> n;
  vector<ll> v;
  ll cnt = 0;

  REP(i, n) {
    ll h;
    cin >> h;
    v.pb(h);
  }
  if (n == 1) {
    if (v[0] == 0) {
      return !printf("%d\n", 0);
    } else {
      return !printf("%d\n", -1);
    }
  }
  REP(i, n - 1) {
    if (v[i + 1] == v[i] + 1)
      cnt++;
    if (v[i + 1] - v[i] > 1 || v[0] != 0)
      return !printf("%d\n", -1);
  }
  REP(i, n - 1) {
    if (v[i] - v[i + 1] >= 0 && v[i + 1] != 0) {
      if (v[i + 1 - v[i + 1]] >= 0) {
        cnt += v[i + 1];
      } else {
        return !printf("%d\n", -1);
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 2548
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <string.h>
#include <string>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;
int a[111];
int n;

void god(void)
{
	printf("Possible");
	exit(0);
}

void nope(void)
{
	printf("Impossible");
	exit(0);
}

bool chk(int val)
{
	int i;
	bool pos=false;
	for(i=2 ; i<=n-1 ; i++)
	{
		if(a[i]==val && a[i+1]==val)
		{
			pos=true;
			return true;	
		}
	}
	return false;
}
int main(void)
{
	int i, j;
	cin>>n;
	for(i=1 ; i<=n ; i++)
	{
		scanf("%d",&a[i]);
	}
	if(n==2)
	{
		if(a[1]==a[2] && a[1]==1)
		{
			god();
		}
		else
		{
			nope();
		}
	}
	sort(a+1,a+n+1);
	bool pos=true;
	if((a[1]==a[n]/2 && a[n]%2==0 && a[1]!=a[2]) || (a[1]==(a[n]+1)/2 && a[n]%2==1 && a[1]==a[2] && a[2]!=a[3]))
	{
		for(i=a[1]+1 ; i<=a[n] ; i++)
		{
			if(chk(i))
			{
				continue;
			}
			else
			{
				nope();
			}
		}	
	} 
	else
	{
		nope();
	}
	god();
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()
	K := sc.NextInt()
    ev := K / 2
    od := (K + 1) / 2
	fmt.Println(ev * od)
}

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &Scanner{sc: sc}
}

func (r *Scanner) SetBufferSize(size int) {
	buf := make([]byte, size)
	r.sc.Buffer(buf, size)
}

func (r *Scanner) NextToken() string {
	r.sc.Scan()
	return r.sc.Text()
}

func (r *Scanner) NextInt64() int64 {
	n, e := strconv.ParseInt(r.NextToken(), 10, 64)
	if e != nil {
		panic(e)
	}
	return n
}

func (r *Scanner) NextInt() int {
	n, e := strconv.ParseInt(r.NextToken(), 10, 32)
	if e != nil {
		panic(e)
	}
	return int(n)
}

func (r *Scanner) NextInt64Array(size int) []int64 {
	a := make([]int64, size)
	for i := 0; i < size; i++ {
		a[i] = r.NextInt64()
	}
	return a
}

func (r *Scanner) NextIntArray(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = r.NextInt()
	}
	return a
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Solution sol = new Solution();
		sol.solve(in, out);
		out.close();
	}

	private static class Solution {
		private void solve(InputReader in, PrintWriter out) {
			int n = in.ni(), k = in.ni();
			int[] a = new int[n];
			for (int i = 0; i < n; ++i) a[i] = in.ni();
			Arrays.parallelSort(a);
			int ans = 0;
			for (int i = 0; i < k; ++i) ans += a[i];
			out.println(ans);
		}
	}

	private static class InputReader {
		private BufferedReader reader;
		private StringTokenizer tokenizer;

		private InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		private String n() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		private int ni() {
			return Integer.parseInt(n());
		}
	}

}


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

for fs in ["SS","SW","WW","WS"]:
    ANS=["A"]*N
    ANS[0],ANS[1]=fs[0],fs[1]
    for i in range(2,N):
        if ANS[i-1]=="S":
            if S[i-1]=="o":
                if ANS[i-2]=="S":
                    ANS[i]="S"

                else:
                    ANS[i]="W"

            else:
                if ANS[i-2]=="S":
                    ANS[i]="W"

                else:
                    ANS[i]="S"

        else:
            if S[i-1]=="o":
                if ANS[i-2]=="S":
                    ANS[i]="W"

                else:
                    ANS[i]="S"

            else:
                if ANS[i-2]=="S":
                    ANS[i]="S"

                else:
                    ANS[i]="W"

    if ANS[0]=="S":
        if S[0]=="o":
            if ANS[-1]!=ANS[1]:
                continue
        else:
            if ANS[-1]==ANS[1]:
                continue
    else:
        if S[0]=="o":
            if ANS[-1]==ANS[1]:
                continue
        else:
            if ANS[-1]!=ANS[1]:
                continue

    if ANS[-1]=="S":
        if S[-1]=="o":
            if ANS[-2]!=ANS[0]:
                continue
        else:
            if ANS[-2]==ANS[0]:
                continue
    else:
        if S[-1]=="o":
            if ANS[-2]==ANS[0]:
                continue
        else:
            if ANS[-2]!=ANS[0]:
                continue

    print("".join(ANS))
    break
else:
    print(-1)

Measured memory_bytes: 4852
#include<iostream>

using namespace std;

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a, max, min, sum;
		min = 1000001;
		max = -1000001;
		sum = 0;
		for(int i = 0; i < n; i++) {
			a = sc.nextInt();
			if(a < min)	min = a;
			if(a > max)	max = a;
			sum += a;
		}
		System.out.printf("%d %d %d\n",min,max,sum) ;
	};
}



Measured memory_bytes: 42020
#include <iostream>
#include <string>
#include <cstring>
#include <map>
using namespace std;

typedef pair<int,int>xy;
typedef pair<xy,int>xyz;

#define X first.first
#define Y first.second
#define Z second


int main(){
	int n,h;
	while(cin>>n>>h,(n+h)){
		map<xyz,int>MP;
		int ans=n*n*n;
		
		string s;
		int a,b;
		for(int i=0;i<h;i++){
			cin>>s>>a>>b;
			int A,B,C;
			for(int i=1;i<=n;i++){
				if(s=="xy"){
					A=a;
					B=b;
					C=i;
				}
				if(s=="xz"){
					A=a;
					B=i;
					C=b;
				}
				if(s=="yz"){
					A=i;
					B=a;
					C=b;
				}
				
				if(MP[xyz(xy(A,B),C)]==0){
					ans--;
					MP[xyz(xy(A,B),C)]=1;
				}
				
			}
		}
		
		cout<<ans<<endl;
	}
	
	
	return 0;
}


Measured memory_bytes: 4332
#include<stdio.h>
void dfs(int a);
int n,go[101],back[101],link[101],keep[101][101],count=1;
 
int main(){
  int i,j,num;
 
  scanf("%d",&n);
 
  for(i=1;i<=n;i++){
    go[i]=back[i]=0;
    scanf("%d",&num);
    scanf("%d",&link[num]);
    for(j=1;j<=link[num];j++) scanf("%d",&keep[num][j]);
  }
  for(i=1;i<=n;i++){
    if(go[i]==0)dfs(i);
  }
 
  for(i=1;i<=n;i++){
    printf("%d %d %d\n",i,go[i],back[i]);
  }
  return 0;
}
 
void dfs(int a){
  int i;
  go[a]=count++;
 
  for(i=1;i<=link[a];i++){
    if(go[keep[a][i]]==0){
      dfs(keep[a][i]);
    }
  }
  back[a]=count++;
   
}


Measured memory_bytes: 2120
import math
A, B, H, M = map(int, input().split())
cho = 6 * M
tan = 30 * H
gap = 0.5 * M
kakudo = tan + gap - cho
if kakudo == 180:
    print(A+B)
    exit()
if kakudo > 180:
    kakudo = 360 - kakudo
ans = A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(kakudo))
print(ans ** 0.5)

Measured memory_bytes: 9436
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
inline void read(rel &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  x=f?x:-x;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;

int main(){
int a[3]={read(),read(),read()},k=read();
sort(a,a+3);
for (;k--;) a[2]*=2;
write(a[2]+a[0]+a[1]); 
}

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

int main() {
	int A,B,K;
    cin >> A >> B >> K;
    int count=0;
   	for(int i=min(A,B);i>=1;i--){
      if(A%i==0 && B%i==0){
        count++;
      }
      if(count==K){
        cout << i << endl;
        break;
      }
    }
}


Measured memory_bytes: 256
from math import inf

Q,H,S,D=map(int,input().split())
N=int(input())

L=inf
M=inf
for a in range(8+1):
    for b in range(4+1):
        for c in range(2+1):
            for d in range(1+1):
                if a+2*b+4*c+8*d==8:
                    L=min(L,a*Q+b*H+c*S+d*D)
                    
            if a+2*b+4*c==4:
                M=min(M,a*Q+b*H+c*S)

if N%2:
    print(L*(N//2)+M)
else:
    print(L*(N//2))


Measured memory_bytes: 62232
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
d = {'AC':0,'WA':0,'TLE':0,'RE':0}
for i in range(n):
    s = ns()
    d[s]+=1

print('AC x',d['AC'])
print('WA x',d['WA'])
print('TLE x',d['TLE'])
print('RE x',d['RE'])

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

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

	std::vector<std::string> vec = {"Sunny", "Cloudy", "Rainy"};
	for(int i = 0; i < s.size(); i++) {
		if(s != vec[i]) continue;
		printf("%s\n", vec[(i + 1) % 3].c_str());
		break;
	}
	return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>

using namespace std;
using pii = pair<int, int>;
using piii = pair<pii, int>;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;

#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,b) for(int i=a; i<b; i++)
#define fi first
#define se second

vint primes(101);
bool is_prime[202];

void furui() {
    rep2(i, 2, 202) {
        is_prime[i] = true;
    }
    for(int i=2; i*i <= 202; i++) {
        if (is_prime[i]) {
            for(int j=i*i; j<202; j+=i) {
                is_prime[j] = false;
            }
        }
    }
}

void cnt(int n) {
    int nn = n;
    rep(i, nn+1) {
        if (is_prime[i]) {
            while(n % i == 0) {
                primes[i]++;
                n /= i;
            }
        }
    }
}

int main() {
    furui();
    int n;
    cin >> n;
    rep2(i, 1, n+1) {
        cnt(i);
    }

    vector<ll> dp(80);
    dp[1] = 1;
    rep(i, 101) {
        vector<ll> next = dp;
        rep2(j, 1, primes[i]+1) {
            rep(k, 101) {
                if (k*(j+1) < 80) {
                    next[k*(j+1)] += dp[k];
                }
            }
        }
        dp = next;
    }
    cout << dp[75] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll N; cin >> N;
    string S; cin >> S;
    ll mod = 1000000007;
    map<char,ll> alp;
    for(char s = 'a'; s <= 'z'; s++)
    {
        for(ll i = 0; i < N; i++)
        {
            if(S.at(i) == s)
            {
                alp[s] += 1; //Sにおける文字毎の出現回数
            }
        }
    }
    vector<ll> sum(26);
    for(char s = 'a'; s <= 'z'; s++)
    {
        ll A = alp[s]; //例えばs=aならa(b+1)(c+1)...を求めていく
        for(char t = s + 1; t <= 'z'; t++)
        {
            A = (A*(alp[t] + 1)) % mod;
        }
        sum.at(s-97) = A; //sの出現回数とsから後の各文字の（出現回数+1）を掛け合わせたもの
    }
    ll ans = 0;
    for(int i = 0; i < 26; i++)
    {
        ans += sum.at(i); //上のsumの総和が条件を見たす部分列の個数になる
    }
    cout << ans % mod << endl;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int n = 0;
    rep(i, s.size()){
        if(s[i] != t[i]) n++;
    }
    cout << n << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    string t="2019/04/30";
    if(s>t) cout << "TBD" << "\n";
    else cout << "Heisei" << "\n";

    return 0;
}

Measured memory_bytes: 3652
#!/usr/bin/env -S JULIA_VERSION=0.5.0 julia
# contest: abc155, problem: abc155_d, alphabet: D

function cnt(x, P, M)
  ans = 0

  ei = length(M)
  for p in reverse(P)
    while ei >= 1 && M[ei] * p > x
      ei -= 1
    end
    ei >= 1 || break
    ans += ei
  end
  x < 0 && return ans

  ei = length(P)
  for (pi, p) in enumerate(P)
    while ei >= pi+1 && P[ei] * p > x
      ei -= 1
    end
    ei >= pi+1 || break
    ans += length(pi+1:ei)
  end

  revM = reverse(M)
  ei = length(revM)
  for (mi, m) in enumerate(revM)
    while ei >= mi+1 && revM[ei] * m > x
      ei -= 1
    end
    ei >= mi+1 || break
    ans += length(mi+1:ei)
  end

  ans
end

function solve(N::Int, K::Int, A::Vector{Int})
  P = [x for x in A if x >= 0]
  M = [x for x in A if x < 0]
  sort!(P)
  sort!(M)

  bottom = -10^18 - 100
  top = 10^18 + 100
  while bottom < top
    mid = div(top + bottom, 2)
    cmid = cnt(mid, P, M)
    if bottom == top - 1
      println(top)
      return
    elseif cmid < K
      bottom = mid
    else
      top = mid
    end
  end
end

function main()
  tokens = Channel{String}(32)
  Task() do
    for line in eachline(@static VERSION < v"0.6" ? STDIN : stdin)
      startswith(line, '\0') && break
      for token in split(chomp(line))
        put!(tokens, token)
      end
    end
    close(tokens)
  end |> schedule
  N = parse(Int, take!(tokens))
  K = parse(Int, take!(tokens))
  A = similar(Vector{Int}, N)
  for i in 1:N
    A[i] = parse(Int, take!(tokens))
  end
  solve(N, K, A)
end

if isempty(get(ENV, "ATCODER_LOCAL", ""))
  isempty(ARGS) && main()
else
  @eval begin
    const samples = [("4 3\n3 3 -4 -2", "-6"), ("10 40\n5 4 3 2 -1 0 0 0 0 0", "6"), ("30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0", "448283280358331064")]
    function test(sampleids...)
      isempty(sampleids) && return test(collect(1:length(samples))...)
      ostdin, ostdout = @static VERSION < v"0.6" ? (STDIN, STDOUT) : (stdin, stdout)
      rd, wr = first(redirect_stdout()), last(redirect_stdin())
      try
        map(sampleids) do sampleid
          input, output = samples[sampleid]
          print(ostdout, "Testing sample #$(sampleid)..."); flush(ostdout)
          println(wr, input)
          println(wr, "\0")
          t = @elapsed main()
          println()
          result = strip(String(readavailable(rd)))
          if result == output
            println(ostdout, "OK ($t sec).")
            true
          else
            println(ostdout, "ERROR ($t sec)")
            println(ostdout, "== expected ==\n$output")
            println(ostdout, "== actual ==\n$result\n")
            false
          end
        end |> all
      finally
        redirect_stdin(ostdin)
        redirect_stdout(ostdout)
      end
    end
    submit() = test() && (prog = @__FILE__; run(`atcoder-submit $prog`))
    !isinteractive() && submit()
  end
end


Measured memory_bytes: 181036
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

string eval(string s, string t, int init) {
	int n=s.size(), m=t.size();
	string u=s.substr(init,m);
	if(u.size()!=m)
		return "@";
	for (int i=0; i<m; i++) {
		if(s[init+i]=='?') {
			s[init+i]=t[i];
			continue;
		}
		if(s[init+i]!=t[i])
			return "@";
	}
	for (int i=0; i<n; i++)
		if(s[i]=='?')
			s[i]='a';
	return s;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string S,T; cin>>S>>T;
	set<string> st;
	int n=S.size();
	for (int i=0; i<n; i++) {
		string res=eval(S,T,i);
		if(res=="@")
			continue;
		st.insert(res);
	}
	if(st.empty()) cout<<"UNRESTORABLE\n";
	else cout<<*st.begin()<<"\n";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
ans = 0
max_L = 0
for i in range(n-1):
    if h[i] >= h[i+1]:
        ans += 1
    else:
        max_L = max(ans,max_L)
        ans = 0
print(max(max_L,ans))


Measured memory_bytes: 14228
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
   
    string str;
    cin>>str;
    ll rn=0;
    for(ll i=0;i<3;i++)
     if(str[i]=='R')
     rn++;
     if(rn!=2)
      cout<<rn<<endl;
      else
      {
          if(str[0]=='S' || str[2]=='S')
           cout<<2<<endl;
           else
           cout<<1<<endl;
      }
}


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

const int MOD = 1e9 + 7;

int n;
int adj[21][21];
int memo[21][1 << 21];

int dp(int x, int mask) {
  if (x == n) return mask == 0;
  if (memo[x][mask] != -1) return memo[x][mask];
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    if (adj[x][i] && mask >> i & 1) {
      ret += dp(x + 1, mask ^ 1 << i);
      if (ret >= MOD) ret -= MOD;
    }
  }
  return memo[x][mask] = ret;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      cin >> adj[i][j];
    }
  }
  memset(memo, -1, sizeof memo);
  cout << dp(0, (1 << n) - 1) << '\n';
}


Measured memory_bytes: 172288
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;

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

signed main(){
    
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int ans = INF;
    for(int t = 0; t < n; t++){
        int s1 = 0;
        int s2 = 0;
        for(int j = 0; j < n; j++){
            if(j <= t) s1 += a[j];
            else s2 += a[j];
        }
        int tmp = (int)abs(s1 - s2);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {
  val max = 1000000000
  val n = readInt()
  var graph = collection.mutable.Seq.fill(n, n)(max)

  for (i <- 1 to n) {
    val input = readLine().split(" ").toList.map(_.toInt)
    val u = input.head - 1
    val k = input(1)
    for (j <- 1 to k) {
      graph(u)(input(1 + j) - 1) = 1
    }
  }

  graph.head(0) = 0

  for (k <- 0 until n) {
    for (i <- 0 until n) {
      for (j <- 0 until n) {
        graph(i)(j) = math.min(graph(i)(j), graph(i)(k) + graph(k)(j))
      }
    }
  }

  graph.head.zipWithIndex.foreach {
    case (v, i) => println(s"${i + 1} ${if (v == max) -1 else v}")
  }
}

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

using namespace std;

int main ()
{
	int a,b;
	cin>>a>>b;
	if (a+b<10)
	{
		cout<<a+b;
	}
	else
	{
		cout<<"error";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 1000005
using namespace std;
int a,b,c;

int main()
{
  cin>>a>>b>>c;
  int xx = a - b;
  int yy = c - xx;
  if(yy < 0) yy = 0;
  cout<<yy<<endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np

def gcd(a,b):    
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
    
N = int(input())
A_list = list(map(int, input().split()))

# =====
# initialize L and R
# =====
L = np.zeros(N+1)
R = np.zeros(N+1)

for idx, element in enumerate(A_list):
    if L[idx] == 0:
        L[idx+1] = element
    else:
        L[idx+1] = gcd(L[idx], element)

for idx, element in enumerate(A_list[-1::-1]):
    idx = N-idx
    if R[idx] == 0:
        R[idx-1] = element
    else:
        R[idx-1] = gcd(R[idx], element)

ans = 0
for i in range(N):
    if L[i] == 0:
        M = R[i+1]
    elif R[i+1] == 0:
        M = L[i]
    else:
        M = gcd(L[i], R[i+1])
    if ans < M:
        ans = M

print(int(ans))



Measured memory_bytes: 23148
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,m;
	cin>>n>>m;
	int g[11][11]={};
  	int p[11]={};
  	FOR(i,0,m){
      int k;
      cin>>k;
      FOR(j,0,k){
      	int t;
        cin>>t;
        g[i][t-1]=1;
      }
    }
    FOR(i,0,m){
		cin>>p[i];
    }
  	int ans=0;
  	FOR(i,0,1<<n){
      int cnt[11]={};
      int f=1;
      FOR(j,0,m){
        FOR(k,0,n){
	      if(i&(1<<k)){
            if(g[j][k]){
              cnt[j]^=1;
            }
          }          
        }
        if(cnt[j]!=p[j]){
          f=0;
          break;
        }
      }
      ans+=f;
    }

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


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

int main() {
  long long H,W;
  cin >> H >> W;
  
  if (H == 1 || W == 1){
    cout << 1 << endl;
  } 
  else if (H * W % 2 == 1){
    cout << H * W / 2 + 1 << endl;
  }
  else {
    cout << H * W / 2 << endl;
  }
}

Measured memory_bytes: 256
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
void swap(int *x,int *y){int tmp=*x;*x=*y;*y=tmp;}
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
//next_permutation
//from https://qiita.com/Nikkely/items/0ddca51b3c0e60afbaab
int next_permutation(int *a,int n){
    int x=-1,y=-1;
    for(int i=n-2;i>=0;i--)if(a[i]<a[i+1]){x=i;break;}
    for(int i=n-1;x!=-1&&i>=0;i--)if(a[x]<a[i]){y=i;break;}
    if(x==-1||y==-1)return 1;
    swap(&a[x],&a[y]);
    qsort(&a[x+1],n-(x+1),sizeof(int),asc_cmp);
    return 0;
}

int main(){
    int n;scanf("%d",&n);
    int p[20];for(int i=0;i<n;i++)scanf("%d",&p[i]);
    int q[20];for(int i=0;i<n;i++)scanf("%d",&q[i]);

    char p_str[20],q_str[20];
    for(int i=0;i<n;i++)p_str[i]=p[i]+'0';
    for(int i=0;i<n;i++)q_str[i]=q[i]+'0';
    p_str[n]=q_str[n]='\0';

    int a[n];for(int i=1;i<=n;i++)a[i-1]=i;

    int list_n;
    static char list[100000][20];
    for(int i=0;1;i++){
        for(int j=0;j<n;j++)list[i][j]='0'+a[j];
        list[i][n]='\0';
        //printf(">%s\n",list[i]);
        list_n=i+1;
        if(next_permutation(a,n))break;
    }
    
    int index[2];
    for(int i=0;i<list_n;i++){
        if(!strcmp(list[i],p_str))index[0]=i;
        if(!strcmp(list[i],q_str))index[1]=i;
    }
    printf("%d\n",abs(index[0]-index[1]));
    return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <ios> 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
ll ans=1;
int n,k;
vector <int> g[100004];
void dfs(int x,int par,int dep,int now){
	if (k<=now){
		cout<<"0";exit(0);
	}
	ans=ans*(k-now)%MOD;
	int op;
	if (dep>2) op=2;
	else op=dep;
	for (int i=0;i<g[x].size();i++) if (g[x][i]!=par){
		dfs(g[x][i],x,dep+1,op);
		op++;
	}
}
int main(){
	cin>>n>>k;
	for (int i=0;i<n-1;i++){
		int x,y;cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);  
	}
	dfs(1,-1,1,0);
	cout<<ans;
}

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

int n;
vector<int> a;
vector<vector<bool>> vis;
vector<vector<int64_t>> dp;
int64_t go(int i, int j, int p) {
    if (vis[i][j])
        return dp[i][j];
    if (i == j) 
        return dp[i][j] = p * a[i];
    vis[i][j] = true;
    int64_t x = go(i + 1, j, -p) + p * a[i];
    int64_t y = go(i, j - 1, -p) + p * a[j];
    return dp[i][j] = p * x > p * y ? x : y;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin >> n;
    a.resize(n);
    vis.assign(n, vector<bool>(n, false));
    dp.assign(n, vector<int64_t>(n));
    for (int& it : a) cin >> it;
    // int64_t ans = go(0, n - 1, 1);
    cout << go(0, n - 1, 1) << '\n';
    return 0;
}

Measured memory_bytes: 75280
now=False
lst=[]
N=int(input())
for k in range(N):lst.append(input())
M=int(input())
for t in range(M):
    ID=input()
    if ID in lst:
        now=not(now)
        if now:
            print("Opened by",ID)
        else:
            print("Closed by",ID)
    else:
        print("Unknown",ID)

Measured memory_bytes: 7668
N = int(input())
P = list(map(int, input().split()))
R = list(range(N))
L = list(range(N))
I = [-1] * (N+1)
for i, p in enumerate(P):
    I[p] = i

ans = 0
for n, idx in enumerate(I[1:], 1):
    #print(f"n={n}, idx={idx}")
    l = idx-1
    while l>=0 and l!=L[l]:
        l = L[l]
    r = idx+1
    while r<N and r!=R[r]:
        r = R[r]
    L[idx] = l
    R[idx] = r

    if l != -1:
        l2 = l-1
        while l2>=0 and l2!=L[l2]:
            l2 = L[l2]
        #print(f"n * (l-l2) * (r-idx) = {n * (l-l2) * (r-idx)}")
        #print(l, l2)
        ans += n * (l-l2) * (r-idx)
        #L[l] = l2
    if r != N:
        r2 = r+1
        while r2<N and r2!=R[r2]:
            r2 = R[r2]
        #print(f"n * (idx-l) * (r2-r) = {n * (idx-l) * (r2-r)}")
        ans += n * (idx-l) * (r2-r)
        #R[r] = r2
print(ans)


Measured memory_bytes: 76564
// author: arshit_babariya

#include <bits/stdc++.h>

using namespace std;
#define fast			ios::sync_with_stdio(0);cin.tie(0);
#define ll 				long long int
#define INF 			1e18L
#define precision(x)	fixed << setprecision(x)
const ll mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	if (b == 0)  return a;
	return gcd(b , a % b);
}


ll powm(ll a, ll b) {
	ll res = 1;
	while (b) {
		if (b & 1)
			res = (res * 1LL * a) % mod;
		b >>= 1LL;
		a = (a * 1LL * a) % mod;
	}
	return res;
}

//--------------------------------------------------------------------------------------------------------------------------//



int main() {
	fast
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	double a[n + 1], dp[n + 1][n + 1];
	for (int i = 0; i < n; i++) cin >> a[i + 1];
	a[0] = 0;
	memset(dp, 0, sizeof dp);
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			if (j == 0) {
				dp[i][j] = dp[i - 1][j] * (1 - a[i]);
				continue;
			}
			dp[i][j] = a[i] * dp[i - 1][j - 1] + (1.0 - a[i]) * dp[i - 1][j];

		}
	}
	double ans = 0;
	for (int i = n; i >= (n + 1) / 2; i--) {
		ans += dp[n][i];
	}
	cout << precision(10) << ans << endl;
	return 0;
}




Measured memory_bytes: 74084
#include<iostream>
#include<algorithm>
#define maxn 200010
using namespace std;
int n;
int num[maxn];
struct ti{
	int x,id;
}a[maxn]; 
bool cmp(ti aa,ti bb){
	return aa.x <bb.x ;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i].x;
		a[i].id =i;
	}
	for(int i=1;i<=n;i++)num[i]=1;
	sort(a+1,a+1+n,cmp);
	//for(int i=1;i<=n;i++)cout<<a[i].id <<" ";cout<<endl;
	
	int cnt=1,ans;
	for(int i=1;i<=n;i++){
		 ans=a[i].id ;
	//	cout<<ans<<endl;
		while(ans<a[i+1].id&&i<n){
			num[cnt]++;
			ans=a[++i].id;
		}
	//	cout<<num[cnt]<<endl;
		cnt++;
	}
//	for(int i=1;i<cnt;i++)cout<<num[i]<<" ";cout<<endl;;
	
	int sum=1;
	for(int i=1;i<cnt;i++){
		if(sum<num[i])sum=num[i];
	}
	cout<<n-sum<<endl;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
string S, T;
int dp[3010][3010];
pi pre[3010][3010];

void upd(int ni, int nj, int i, int j, int v) {
	if(dp[ni][nj] < dp[i][j] + v) {
		dp[ni][nj] = dp[i][j] + v;
		pre[ni][nj] = pi(i, j);
	}
}

void solve() {
	cin >> S >> T;
	N = sz(S); M = sz(T);
	pre[0][0] = pi(-1, -1);
	rep(i, 0, N + 1) {
		rep(j, 0, M + 1) {
			dp[i][j] = -inf;
		}
	}
	dp[0][0] = 0;
	rep(i, 0, N + 1) {
		rep(j, 0, M + 1) {
			if(i < N) upd(i + 1, j, i, j, 0);
			if(j < M) upd(i, j + 1, i, j, 0);
			if(i < N && j < M && S[i] == T[j]) upd(i + 1, j + 1, i, j, 1);
		}
	}
	string ans;
	pi now = pi(N, M);
	while(true) {
		pi p = pre[now.fst][now.sec];
		// debug(p, now, S, T, dp[1][1]);
		if(p == pi(-1, -1)) break;
		if(p.fst != now.fst && p.sec != now.sec) ans += S[p.fst];
		now = p;
	}
	reverse(all(ans));
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

struct UnionFind {
    vector<long long> par;
    UnionFind(long long size) : par(size + 1, -1) {}
    bool unite(long long x, long long y){
        x = root(x);
        y = root(y);
        if(x != y) {
            if(par[y] < par[x]) swap(x, y);
            par[x] += par[y];
            par[y] = x;
        }
        return x != y;
    }
    bool same(long long x, long long y) { return root(x) == root(y); }
    int root(long long x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    int size(long long x) { return -par[root(x)]; }
};

int main()
{
    int n, q;
    cin >> n >> q;
    UnionFind tree(n);
    for(int i = 0; i < q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if(t == 0) tree.unite(u, v);
        else cout << (tree.same(u, v) ? 1 : 0) << endl;
    }
    return 0;
}


Measured memory_bytes: 4564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int a,b; cin>>a>>b;
    cout<<max(a+b,max(a-b,a*b))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
 
int main() {
  string s;
  cin >> s;

  rep(i, 1<<3){
    int ans=s.at(0)-'0';
    bitset<3> bi(i);

    if(bi.test(0)) ans+=s.at(1)-'0';
    else ans-=s.at(1)-'0';

    if(bi.test(1)) ans+=s.at(2)-'0';
    else ans-=s.at(2)-'0';

    if(bi.test(2)) ans+=s.at(3)-'0';
    else ans-=s.at(3)-'0';

    if(ans==7){
      cout << s.at(0);

      if(bi.test(0)) cout << "+" << s.at(1);
      else cout << "-" << s.at(1);

      if(bi.test(1)) cout << "+" << s.at(2);
      else cout << "-" << s.at(2);

      if(bi.test(2)) cout << "+" << s.at(3);
      else cout << "-" << s.at(3); 

      cout << "=7" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n, c;
    cin >> n >> c;

    //価値jをどんだけの重さで実現できるか
    vector<int> r(100001, 1 << 30);
    r[0] = 0;

    for (int i = 0; i < n; i++) {
        int w, v;
        cin >> w >> v;

        for (int j = 100000; j >= v; j--) {
            r[j] = min(r[j], r[j - v] + w);
        }
    }

    int s = 0;
    for (int j = 0; j <= 100000; j++) {
        if (r[j] <= c) s = j;
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(void){

  int n,k;
  int s[150];
  int b[150][150];
  int a,f;

  for( ; ; ){

    cin >> n >> k;
    if(!n && !k) break;

    f = 0;

    for(int i = 0;i < k; i++) cin >> s[i];

    for(int i = 0;i < n; i++){
      for(int j = 0;j < k; j++){
	cin >> a;
	s[j] -= a;
      }
    }

    for(int i = 0;i < k; i++){
      if(s[i] < 0) f = 1;
    }

    cout << (f? "No" : "Yes") << endl;
  }
}


Measured memory_bytes: 1152
from collections import deque
N, M = map(int,input().split())
graph = [[] for i in range(N + 1)]
for _ in range(M):
    A, B = map(int,input().split())
    graph[A].append(B)
    graph[B].append(A)

queue = deque([1]) 
flag = [-1] * (N + 1)

while queue: 
    node = queue.popleft()
    children = graph[node] 
    for child in children:
        if flag[child] == -1:
            flag[child] = node
            queue.append(child)

if -1 in flag[2:]:
    print('No')
else:
    print('Yes')
    print(*flag[2:], sep='\n')

Measured memory_bytes: 36068
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    ll n;
    cin >> n;
    map<ll, ll> cnt;
    for (int i = 0; i < n; ++i) {
        ll a;
        cin >> a;
        cnt[a]++;
    }
    vector<ll> as(n + 1, 0);
    for (auto &p : cnt) {
        as[p.second]++;
    }
    for (int i = n - 1; i >= 0; --i) {
        as[i] += as[i + 1];
    }
    vector<ll> ret(n, 0);
    for (int i = as[1] - 1; i >= 0; --i) {
        ll temp = 0;
        while (as[ret[i] + 1] == i + 1) {
            ret[i]++;
            as[ret[i]]--;
            temp++;
        }
        for (int j = 1; j <= n; ++j) {
            ll add = min(temp, as[1] - as[j]);
            as[j] += add;
            temp -= add;
            if (temp == 0)
                break;
        }
    }
    for (auto &r : ret) {
        cout << r << "\n";
    }
    return 0;
}

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

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	char matrix[n][m];
	for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            cin >> matrix[i][j];
        }
	}
	for(int i = -1; i < n * 2 - 1; ++i){
        for(int j = 0; j < m; ++j){
            cout <<  matrix[(i + 1)/2][j];
        }
        cout << "\n";
	}

	return 0;

}


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

int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  
  char c = s.at(k-1);
  for(int i = 0; i < n; i++){
    if(s.at(i) == c) continue;
    s.at(i) = '*';
  }
  
  cout << s << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

typedef long long ll;

const int INF = 1e9;

int main() {
    double R;
    cin >> R;

    cout << fixed << setprecision(3) << 2.0*R*M_PI << "\n";
}


Measured memory_bytes: 3788