akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b := iScan(), iScan()
	if a < b {
		for i := 0; i < b; i++ {
			fmt.Print(a)
		}
	} else {
		for i := 0; i < a; i++ {
			fmt.Print(b)
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 1772
#include<cstdio>
#include<queue>
const int N=2e5+5;
int p[N],head[N],cnt,n,deg[N],val[N];
bool vis[N],ur[N];
struct edge{
	int to,nxt;
}e[N];
std::queue<int>q;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",p+i);
		e[++cnt]=(edge){i,head[p[i]]},head[p[i]]=cnt,++deg[p[i]];
	}
	for(int i=1;i<=n;++i)if(!deg[i])q.push(i);
	while(!q.empty()){
		int u=q.front();q.pop();
		vis[u]=1;
		for(int i=head[u];i;i=e[i].nxt)if(vis[e[i].to])
			ur[val[e[i].to]]=1;
		int&v=val[u];
		while(ur[v])++v;
		for(int i=head[u];i;i=e[i].nxt)ur[val[e[i].to]]=0;
		if(!--deg[p[u]])q.push(p[u]);
	}
	int len=0,mn=0;
	for(int u=1;u<=n;++u)if(!vis[u]){
		for(int i=head[u];i;i=e[i].nxt)if(vis[e[i].to])
			ur[val[e[i].to]]=1;
		int&v=val[u];
		while(ur[v])++v;
		for(int i=head[u];i;i=e[i].nxt)ur[val[e[i].to]]=0;
	}
	for(int i=1;i<=n;++i)if(!vis[i]){
		++len;if(val[p[i]]<val[i])mn=p[i];
	}
	printf("%sPOSSIBLE\n",(len&1)&&!mn?"IM":"");
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N;
    cin >> N;
    vector<ll> A(N + 1), B(N + 1);
    rep(i, N + 1) cin >> A[i];
    rep(i, N) cin >> B[i + 1];
    ll ans = 0;
    rep2(i, 1, N + 1) {
        ll tmp = min(B[i], A[i - 1]);
        B[i] -= tmp;
        ll tmp2 = min(B[i], A[i]);
        A[i] -= tmp2;
        ans += tmp + tmp2;
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 1792
#!/usr/bin/env python3
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
m=[0]*n
L,R=[0]*(n+1),[0]*(n+1)
for i in range(1,n+1):
    L[i]=gcd(L[i-1],a[i-1])
    R[n-i]=gcd(R[n-i+1],a[n-i])
for i in range(n):
    m[i]=gcd(L[i],R[i+1])
print(max(m))

Measured memory_bytes: 16148
k, n = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
res = 10 ** 12
for i in range(n):
  if i == 0:
    res = min(res, max(A[i+1] - A[i], k - (A[i+1] - A[i])), max(A[n-1] - A[0], k - (A[n-1] - A[0])))
  if 0 < i < n-1:
    res = min(res, max(A[i+1] - A[i], k - (A[i+1] - A[i])), max(A[i] - A[i-1], k - (A[i] - A[i-1])))
  else:
    res = min(res, max(A[i] - A[0], k - (A[i] - A[0])), max(A[i] - A[i-1], k - (A[i] - A[i-1])))
print(res)
  

Measured memory_bytes: 26444
DBG = !true
n,x = gets.split.map{|z| z.to_i}
a = gets.split.map{|z| z.to_i}

a.sort!
print a if DBG
cnt = 0
for i in 0...a.size
  puts "i #{i} x #{x} cnt #{cnt}" if DBG
  x -= a[i]
  cnt += 1
  if x < 0
    cnt -= 1
    break
  end
end
print cnt - (x>0 ? 1 : 0)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  
  if(S.at(0) == S.at(1)){
    cout << "Bad" << endl;
    return 0;
  }
  if(S.at(1) == S.at(2)){
    cout << "Bad" << endl;
    return 0;
  }
  if(S.at(2) == S.at(3)){
    cout << "Bad" << endl;
    return 0;
  }
  
  cout << "Good" << endl;
}
  

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

int main() {
  int N, l, r, sum = 0;

  cin >> N; //組数Nの受付
  //ループの開始
  for (int i = 0; i < N; i++){
    cin >> l >> r; //l,rの受付

    sum += (r - l) + 1; //i組目の座席数
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
N, M = gets.chomp.split.map(&:to_i)
as = Array.new(N)
N.times do |i|
  as[i] = gets.chomp
end

bs = Array.new(M)
M.times do |i|
  bs[i] = gets.chomp
end

# 横を探索　
# N - M + 1 列目まで探索
0.upto(N - M) do |x|
  # i = 0
  # 縦を探索
  # N - M + 1 行目まで探索
  0.upto(N - M) do |y|
    # puts 'x:' + x .to_s
    # puts 'y:' + y .to_s
    # # puts 'i:' +  i .to_s
    # puts 'as:'  + as[y][x..(x+M-1)] .to_s
    # # puts 'bs:' + bs[i].to_s
    M.times do |i|
      if as[y + i][x..(x + M - 1)] != bs[i] 
        break
      end
      if i + 1 == M
        puts "Yes" 
        exit
      end  
    end
    # if as[y][x..(x + M - 1)] == bs[i] 
    #   i += 1
    # end 
    # if i == M
    #   puts "Yes" 
    #   exit
    # end
  end
end

puts "No"


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int count = 0;
  
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        int judge = 0;
        for (int l = 0; l < N; l++) {
          int A = S.at(l) - '0';
          if (A == k && judge == 2){
            judge++;
          }
          if (A == j && judge == 1){
            judge++;
          }
          if (A == i && judge == 0){
            judge++;
          }
          if (judge == 3){
            count++;
            break;
          }
        }
      }
    }
  }
  cout << count << endl;
}
          
            
          
    
    
      
      

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.Set;


public class Main {


    static void solve() {
        Scanner scan = new Scanner(System.in);
        String s = scan.next();
        String t = scan.next();
        t = t.substring(0, t.length()-1);
//        StringBuilder sb = new StringBuilder(s);
//        sb.append(t.charAt(t.length()-1));


        if(s.equals(t)) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//            int k = scan.nextInt();
//            scase(n,k);
////            System.out.println(res);
////            solveCase(i, x,y,s);
//        }
    }



//    static class Pair {
//        int a;
//        int b;
//    }




//    static void solveCase(int t, int x, String s) {
//
//    }



    static void scase(int n, int k) {

    }



    public static void main(String[] args) {

        solve();

        //        Main m = new Main();
        //        Scanner scan = new Scanner(System.in);

        //        long n = scan.nextLong();
        //        long r = scan.nextLong();
        //        List<Long> list = new ArrayList<>();
        ////        int[] arr = new int[n];
        //        for (long i=0;i<n;i++){
        //            list.add(scan.nextLong());
        //        }
//            System.out.println(ch);
        //        solve(n, arr);
        //        scan.close();
    }


//
//    class Counter extends HashMap<Integer, Integer> {
//        public int get(int k) {
//            return containsKey(k) ? super.get(k) : 0;
//        }
//
//        public void add(int k, int v) {
//            put(k, get(k) + v);
//        }
//    }


//    static class Node {
//        int val;
//        Node next;
//        Node random;
//
//        public Node(int val) {
//            this.val = val;
//            this.next = null;
//            this.random = null;
//        }
//    }

//    static class Node {
//        int key;
//        int data;
//        Node next;
//        Node prev;
//
//        Node(int key, int data) {
//            this.key = key;
//            this.data = data;
//        }
//    }

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
}


Measured memory_bytes: 27008
import sys
import math

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

for i in range(N):
    if A[i] == 1:
        ans = N
        for j in range(max(0, i-(K-1)), min(N, i+K-1)):
            ans = min(math.ceil(j/(K-1)) + math.ceil((N-j-1)/(K-1)), ans)
        break
print(ans)

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

int main() {
  int N;
  cin >> N;
  int sum=0;

  for(int i=0;i<N;i++){
    int l,r;
    cin >> l >> r;
    sum+= r-l+1;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include<string.h>
#include <math.h>
#include <stack>
#define ll long long
using namespace std;
int a[25][25];
int b[25];
int main() {
	int n, m, c;
	scanf("%d %d %d", &n, &m, &c);
	for (int i = 0; i < m; i++)
		scanf("%d", b + i);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	int cnt = 0;

	for (int i = 0; i < n; i++) {
		int res = 0;
		for (int j = 0; j < m; j++) {
			res += a[i][j] * b[j];
		}
		if (res +c > 0) {
			cnt++;
		}
	}
	printf("%d\n", cnt);
}

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

const long MOD = 1'000'000'007;

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

long gcd(long a, long b, long c) {
	return gcd(gcd(a, b), c);
}

int main() {
	long n; cin >> n;
	long ans = 0;
	for (long i = 1; i <= n; i++) {
		for (long j = 1; j <= n; j++) {
			for (long k = 1; k <= n; k++) {
				ans += gcd(i, j, k);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3196
#include<stdio.h>
#include<math.h>
int main()
{
    int n,m,i,k,x=0;
    while(scanf("%d",&n)!=EOF)
    {
        x=0;
        while(n--)
        {
            scanf("%d",&m);
            k=sqrt(m);
            for(i=2; i<=k; i++)
                if(m%i==0)
                    break;
            if(i>=k+1)
                x++;
        }
        printf("%d\n",x);
    }
    return 0;
}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
const int W = 29, N = 2e5 + 87;
void ct_sort(int *& a, int *& v,int k, int n)
{
    int c[2] = {};
    for (int i = 0; i < n; ++i)
        ++c[a[i]>>k&1];
    c[1] += c[0];
    for (int i = n - 1; i >= 0; --i)
        v[--c[a[i]>>k&1]] = a[i];
    swap(a, v);
}
int g(int x,int k) {return x & ((1 << (k + 1)) - 1);}
int mem[3][N], n;
int * a = mem[0], * b = mem[1], * v = mem[2];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];
    int ans = 0;
    for (int k = 0; k < W; ++k) {
        ct_sort(a,v,k,n);
        ct_sort(b,v,k,n);
        int l,r,p=1<<k,c=0;
        l = r = n;
        for (int i = 0; i < n; ++i) {
            while (l - 1 >= 0 && g(a[l-1],k) >= p - g(b[i],k))
                --l;
            while (r - 1 >= 0 && g(a[r-1],k) >= 2 * p - g(b[i],k))
                --r;
            c = (r - l + c) & 1;
        }
        l = r = n;
        for (int i = 0; i < n; ++i) {
            while (l - 1 >= 0 && g(a[l-1],k) >= 3LL * p - g(b[i],k))
                --l;
            while (r - 1 >= 0 && g(a[r-1],k) >= 4LL * p - g(b[i],k))
                --r;
            c = (r - l + c) & 1;
        }
        ans |= c<<k;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

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


void solve(){

	int n;
	cin >> n;

	string s;
	cin >> s;
	if(n%2){
		cout << "No" << endl;
		return;
	}
	n/=2;
	for(int i = 0;i< n;i++ ){
		if(s[i]!=s[i+n]){
			cout << "No" << endl;
			return;
		}
	}
	
	cout << "Yes" << endl;
}
	
	

signed main() 
{   
	IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 256
#include <bits/stdc++.h>
int n, ans;
inline void up(int &x, int y) { x < y ? x = y : 0; }
inline void down(int &x, int y) { x > y ? x = y : 0; }
inline int gcd(int x, int y) {
	if (y == 0) return x;
	else return gcd(y, x % y);
}
int main() {
    std::cin >> n;
    for (int i = 1; i <= n; ++i)
    	for (int j = 1; j <= n; ++j)
    		for (int k = 1; k <= n; ++k) ans += gcd(gcd(i, j), gcd(j, k));
	std::cout << ans << '\n';
}




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

using namespace std;

const int N = 100;

int n;

int a[N], ans;

int main () {
    cin >> n;
    for (int i = 1;i <= n;i ++) {
        cin >> a[i];
    }
    for (int i = 1;i <= n;i ++) {
        for (int j = i + 1;j <= n;j ++) {
            ans += a[i] * a[j];
        }
    }cout << ans;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int a,b,k;cin>>a>>b>>k;
    for(int i=0;i<k;i++){
        if(i%2==0){
            if(a%2==1)a--;
            a/=2;
            b+=a;
        }
        else{
            if(b%2==1)b--;
            b/=2;
            a+=b;
        }
    }
    cout<<a<<" "<<b<<endl;
}


Measured memory_bytes: 3596
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)

int dxy[] = {0, 1, 0, -1, 0};

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 123
#define MAX 3000LL
#else
#define SIZE 123
#define MAX 3000LL
#endif

int N,M,S;
struct Edge {
    int u,v,a,b;
};
vector<Edge> E;
// i番目の都市にいる時,銀貨j枚持っている→最短の時間
int DP[SIZE][MAX];
int C[SIZE],D[SIZE];

bool update(int i, int j, Edge e) {
    bool update = false;
    REP(k,MAX) {
        // 銀貨を増やす
        int nk = k+C[i];
        if (MAX <= nk) continue;
        int nt = DP[i][k]+D[i];
        if (DP[i][nk] > nt) {
            DP[i][nk] = nt;
            update = true;
        }
    }
    REP(k,MAX) {
        int nk = k-e.a;
        if (nk < 0 || MAX <= nk) continue;
        int nt = DP[i][k]+e.b;
        if (DP[j][nk] > nt) {
            DP[j][nk] = nt;
            update = true;
        }
    }
    return update;
}

void solve() {
    cin>>N>>M>>S;
    REP(i,M) {
        auto e = Edge();
        cin>>e.u>>e.v>>e.a>>e.b;
        e.u--;
        e.v--;
        E.push_back(e);
    }
    REP(i,N) cin>>C[i]>>D[i];
    REP(i,N)REP(k,MAX) DP[i][k]=1e15;
    REP(k,min(MAX-1,S)+1) DP[0][k] = 0; // 銀貨S枚
    bool upd = true;
    while(upd) {
        upd = false;
        for (auto e:E) {
            upd |= update(e.u, e.v, e);
            upd |= update(e.v, e.u, e);
        }
    }
    REP1(i,N-1) {
        int mi = 1e15;
        REP(k,MAX) {
            mi = min(mi, DP[i][k]);
        }
        cout << mi << endl;
    }
}

Measured memory_bytes: 4804
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int INF = 1e+18;

template<class T>
struct Edge{
	int from,to;
	T cost;
	Edge(int to,T cost) : to(to),cost(cost){}
	Edge(int from,int to,T cost) : from(from),to(to),cost(cost){}
};

template<class T>
using WeightedGraph = vector<vector<Edge<T>>>;
using Graph = vector<vector<int>>;
template<class T>
using Matrix = vector<vector<T>>;

template<class T>
vector<T> dijkstra(const WeightedGraph<T> &G,int source = 0){
	using P = pair<T,int>;
	vector<T> dist(G.size(),INF);
	priority_queue<P,vector<P>,greater<P>> que;
	dist[source] = 0;
	que.emplace(dist[source],source);
	while(!que.empty()){
		P p = que.top();que.pop();
		int v = p.second;
		if(dist[v] < p.first) continue;
		for(const auto &e : G[v]){
			if(dist[e.to] > dist[v] + e.cost){
				dist[e.to] = dist[v] + e.cost;
				que.emplace(dist[e.to],e.to);
			}
		}
	}
	return dist;
}

signed main(){
	int n,m;
	while(cin >> n >> m,n){
		int u[20010],v[20010],d[20010],c[20010];
		WeightedGraph<int> G(n);
		for(int i = 0;i < m;i++){
			cin >> u[i] >> v[i] >> d[i] >> c[i]; u[i]--;v[i]--;
			G[u[i]].emplace_back(v[i],d[i]);
			G[v[i]].emplace_back(u[i],d[i]);
		}
		auto dist = dijkstra(G);
		int minInCost[10010] = {};
		for(int i = 1;i < n;i++) minInCost[i] = INF;
		for(int i = 0;i < m;i++){
			if(dist[u[i]] > dist[v[i]]) swap(u[i],v[i]);
			if(dist[u[i]] + d[i] == dist[v[i]]){
				minInCost[v[i]] = min(minInCost[v[i]],c[i]);
			}
		}
		int ans = 0;
		for(int i = 0;i < n;i++) ans += minInCost[i];
		cout << ans << endl;
	}
}


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

using namespace std;

#define REPI(x) for(int i=0;i<(x);i++)
#define REPJ(x) for(int j=0;j<(x);j++)
#define SCANFD(x) scanf("%d",&x)

int main()
{
    int H,W,D,Q;
    int dist[90001];
    int px[90001],py[90001];
    int res,buf;
    int L,R;


    scanf("%d%d%d",&H,&W,&D);

    REPI(H)
    {
        REPJ(W)
        {
            scanf("%d",&buf);
            px[buf] = i; py[buf] = j;
        }
    }

    REPI(D+1)
    {
        dist[i] = 0;
    }

    for(int i=D+1;i<=H*W;i++)
    {
        dist[i] = dist[i-D] + abs(px[i]-px[i-D]) + abs(py[i]-py[i-D]);
    }
    
    scanf("%d",&Q);

    REPI(Q)
    {
        scanf("%d%d",&L,&R);
        res = dist[R] - dist[L];
        printf("%d\n",res);
    }

    return 0;
}



Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair< int, int > P;
typedef pair< int, P > iP;
typedef long long LL;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const int MOD = (10^9 + 7);

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

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

    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; i += 2) {
        --k;
    }
    if( k > 0 ) cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}



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

void Main()
{
  unordered_set<int> to, from;
  int N,M; cin >> N >> M;
  vector<int> a(M), b(M);
  rep(i,M) {
    cin >> a[i] >> b[i];
    if (a[i] == 1) to.insert(b[i]);
    if (b[i] == N) from.insert(a[i]);
  }
  for (int i = 2; i < N; i++) {
    if (from.find(i) != from.end() && to.find(i) != to.end()) {
      cout << "POSSIBLE" << endl; return;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

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


Measured memory_bytes: 10056
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<(a-c)*(b-d)<<endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[]args){
     Scanner sc = new Scanner(System.in);
     int N = sc.nextInt();
     int K = sc.nextInt();
     int C = sc.nextInt();
     String str = sc.next();
     boolean[] can_work = new boolean[N];
        for(int i=0;i<N;i++){
            if(str.charAt(i)=='o'){
                can_work[i] = true;
            }else{
                can_work[i]=false;
            }
        }

        int [] first = new int[K];
        int [] last = new int[K];
        
        for(int i=0,total=0;total<K;i++){
            if(can_work[i]){
                first[total]=i;
                i+=C;
                total++;
            }
        }
        for(int i=N-1,total=0;total<K;i--){
            if(can_work[i]){
                last[total]=i;
                i-=C;
                total++;
            }
        }
        for(int i=0;i<K;i++){
            if(first[i]==last[K-1-i])
            System.out.println(first[i]+1);
        }
    }
}

Measured memory_bytes: 46504
#include<bits/stdc++.h>
#define fi first
#define se second
#ifdef CX_TEST
#define Debug printf
#else
#define Debug(...)
#endif
#define LL long long
#define UL unsigned long long
using namespace std;
typedef pair<int, int> P;
const int maxn = 2e5 + 5;

LL x[maxn];

int main() {
#ifdef CX_TEST
    freopen("E:\\program--GG\\test_in.txt", "r", stdin);
#endif
    int n, i, j, k;
    UL ans = -1, w, res;
    scanf("%d", &n);
    scanf("%llu", &w);
    for(i = 1; i <= n; i++) scanf("%lld", &x[i]);
    for(i = 1; i <= n; i++) x[i] += x[i - 1];
    for(i = 1; i <= n; i++) {
        if(i * 2 >= n) {
            ans = min(ans, (UL)x[n] * 5 + w * i);
            break;
        }
        res = (x[n] - x[n - i * 2]) * 5 + w * i;
        for(j = n - i * 2, k = 7; j > 0; j -= i, k += 2) res += (x[j] - x[max(j - i, 0)]) * k;
        ans = min(ans, res);
    }
    cout << ans + n * w << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,ans;
  cin >> A >> B;
  
  ans = A - 2 * B;
  if(ans <= 0){
  	cout << 0 << endl;
  }else{
  	cout << ans << endl;
  }
}

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

int main() {
  int n, x = 0, max = 0;
  std::cin >> n;
  std::string s;
  std::cin >> s;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'I') {
      x++;
    }
    if (s[i] == 'D') {
      x--;
    }
    if (max < x) {
      max = x;
    }
  }
  std::cout << max << "\n";
  return 0;
}

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

int main() {
  int a,b,c; cin >> a >> b >> c;
  int x = a+b;
  int y = b+c;
  int z = c+a;
  cout << min(x, min(y,z)) << endl;
}

Measured memory_bytes: 3616
#include<stdio.h>
#define MAX 1000
int main(void)
{  

   int i,N,v,j,k;
   int A[MAX];
   
   scanf("%d",&N);
   for(i=1;i<=N;i++)
    {
	scanf("%d",&A[i]);
	}

	 printf("%d",A[1]);
	 for(i = 2;i <= N;i++)
	 {
	   printf(" %d",A[i]);
	 }
	
     printf("\n");
   for (i = 2 ; i< N+1; i++)
   {
     v = A[i];
     j = i - 1;
     while (j >= 0 && A[j] > v)
	 {
       A[j+1] = A[j];
       j--;
     A[j+1] = v;
	 }
	 
	 printf("%d",A[1]);
	 for(k = 2;k < N+1;k++)
	 {
	   printf(" %d",A[k]);
	 }
	 printf("\n");
   }
return 0;	
}

Measured memory_bytes: 608
#include <cstdlib>
#include <iostream>
#include <queue>

using namespace std;

class task{
public:
    string name;
    int remain_time;

    task(string input_name, int input_rt){
        name = input_name;
        remain_time = input_rt;
    }

    int active(int time){
        if(remain_time <= time){
            return remain_time;
        }
        remain_time -= time;
        //cout << name << ":" << remain_time << endl;
        return -1;
    }
};

int main(){
    int n, q;
    int cullent_time = 0;
    cin >> n >> q;
    queue<task> tasks;

    for(int i=0; i<n; i++){
        string input_name; 
        int input_rt;
        cin >> input_name >> input_rt;
        task newTask(input_name, input_rt);
        tasks.push(newTask);
    }

    while(tasks.size() > 0){
        task cullent_task = tasks.front();
        tasks.pop();

        int elapsed_time = cullent_task.active(q);

        if(elapsed_time == -1){
            cullent_time += q;
            tasks.push(cullent_task);
        }else{
            cullent_time += elapsed_time;
            cout << cullent_task.name << " " << cullent_time << endl;
        }
    }
   
    return 0;
}



Measured memory_bytes: 6228
def search(arr, x)
  left = 0
  right = arr.size - 1
  pos = arr.size / 2
  until arr[pos] > x && (arr[pos-1] <= x || pos == 0)
    if arr[pos] > x
      right = pos
    else
      left = pos + 1
      if left == arr.size
        pos = arr.size
        break
      end
    end
    pos = (left + right) / 2
  end
  return pos
end

N = gets.to_i
a = gets.split.map(&:to_i).sort
b = gets.split.map(&:to_i).sort
c = gets.split.map(&:to_i).sort

n_mid = Array.new(N)
b.reverse.each_with_index do |mid,i|
  pos = N - 1 - i
  ashi = search(c, mid)
  if i == 0
    n_mid[pos] = N - ashi
  else
    n_mid[pos] = (N - ashi) + n_mid[pos + 1]
  end
end
ans = 0
a.each do |top|
  mid = search(b, top)
  ans += mid == N ? 0 : n_mid[mid]
end
puts ans


Measured memory_bytes: 27112
INF = 10**18
def bellman_ford(s, n, g): # s: start, n: |V|, g; glaph 
    d = [INF]*n
    d[s] = 0
    for i in range(n-1): # max n-1 loops. if update d[] in n-th loop -> negative cycle
        update = False
        for v_from, v_to, cost in g:
            if d[v_from] != INF and d[v_to] > d[v_from] + cost:
                d[v_to] = d[v_from] + cost
                update = True
        if not update:
            break

    for i in range(n-1): # max n-1 loops. if update d[] in n-th loop -> negative cycle
        update = False
        for v_from, v_to, cost in g:
            if d[v_from] != INF and d[v_to] > d[v_from] + cost:
                d[v_to] = -INF
                update = True
        if not update:
            break

    return d
    


n,m,p =map(int, input().split())
g = []
for _ in range(m):
    a,b,c = map(int, input().split())
    c-=p
    g.append((a-1,b-1,-c))


d = bellman_ford(0,n,g)
if d[-1] == -INF: print(-1)
else:
    ans = -d[-1]
    ans = max(0,ans)
    print(ans)

Measured memory_bytes: 74892
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

#include <math.h>
using namespace std;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    bool a = true;
    bool b = true;
    for(int i=0; i<s.size(); i++){
        if(i%2 ==0){
            if(s.at(i)=='L'){
                a = false;
            }
        }else{
            if(s.at(i)=='R'){
                a = false;
            }
        }
    }
    if(a&&b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0;i<N;i++){
    cin >> L.at(i);
  }
  long long count=0;
  for(int i=0;i<N-2;i++){
    for(int j=i+1;j<N-1;j++){
      for(int k=j+1;k<N;k++){
        long long A=L.at(i),B=L.at(j),C=L.at(k);
        if(A==B || B==C || C==A){
          continue;
        }
        if(A<B+C && B<C+A && C<A+B){
          count++;
        }
      }
    }
  }
  cout << count << endl;
}         

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;
 
typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;
 
template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);
 
int fastpow(int x, int n, int m){
    int a = 1;
    IREP(i, 64){
        a = (a * a) % m;
        if(((n >> i) & 1) == 1) a = (a * x) % m;
    }
    return a;
}

class Combination
{
public:

    vec fact, invfact;
    int MAX_N, mod;

    Combination(int MAX_N, int mod): MAX_N(MAX_N), mod(mod) {
        fact = vec(MAX_N + 1);
        invfact = vec(MAX_N + 1);
        fact[0] = 1;
        FOR(i, 1, MAX_N + 1){
            fact[i] = (fact[i - 1] * i) % mod;
        }
        invfact[MAX_N] = fastpow(fact[MAX_N], mod - 2, mod);
        IREP(i, MAX_N){
            invfact[i] = (invfact[i + 1] * (i + 1)) % mod;
        }
    }

    int comb(int n, int r){
        if(r > n || r < 0 || n < 0) return 0;
        int a = fact[n];
        a = (a * invfact[r]) % mod;
        a = (a * invfact[n - r]) % mod;
        return a;
    }
};
 
signed main(){
 
    int K, N; cin >> K >> N;
    int mod = 998244353;
 
    Combination C(5000, mod);
 
    vec pow2(2001);
    REP(i, 2001) pow2[i] = fastpow(2, i, mod);
 
    FOR(i, 2, 2 * K + 1){
        int ans = 0;
        if(i % 2 == 1){
            int dmax = min(i / 2, (2 * K + 2 - i) / 2);
            int K2 = K - dmax * 2;
            FOR(d, 0, dmax + 1){
                int tmp = (C.comb(dmax, d) * C.comb(N + K2 - 1, N - d)) % mod;
                tmp = (tmp * pow2[d]) % mod;
                ans = (ans + tmp) % mod;
            }
        }
 
        if(i % 2 == 0){
            int dmax = min(i / 2, (2 * K + 2 - i) / 2) - 1;
            int K2 = K - dmax * 2 - 1;
            FOR(d, 0, dmax + 1){
                // (i/2,i/2)なし
                int tmp = (C.comb(dmax, d) * C.comb(N + K2 - 1, N - d)) % mod;
                tmp = (tmp * pow2[d]) % mod;
                ans = (ans + tmp) % mod;
                // (i/2,i/2)あり
                tmp = (C.comb(dmax, d) * C.comb(N + K2 - 2, N - d - 1)) % mod;
                tmp = (tmp * pow2[d]) % mod;
                ans = (ans + tmp) % mod;
            }   
        }
 
        cout << ans << endl;
        
    }
 
    
    return 0;
}
 
 
template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 384
N, A, B = map( int, input().split())
S = input()
ans = ""
ab = 0
b=0
AB = A+B
for i in range(N):
    if S[i] == "c":
        print("No")
        continue
    if S[i] == "a":
        if ab < AB:
            ab += 1
            print("Yes")
        else:
            print("No")
    else:
        if b < B and ab < AB:
            b += 1
            ab += 1
            print("Yes")
        else:
            print("No")


Measured memory_bytes: 4016
# coding: utf-8
import sys
from collections import Counter, defaultdict

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M, K = lr()

def find(A, x):
    parent = A[x]
    if parent == x: return x
    root = find(A, parent)
    A[x] = root
    return root

def union(A, x, y):
    root, second = find(A, x), find(A, y)
    if root > second:
        second, root = root, second
    A[second] = root

V = list(range(N+1))
friend = [[] for _ in range(N+1)]  # 1-indexed
for _ in range(M):
    a, b = lr()
    friend[a].append(b)
    friend[b].append(a)
    if find(V, a) != find(V, b):
        union(V, a, b)

V = [find(V, x) for x in V]
counter = Counter(V)
dic = defaultdict(int)
for k, v in counter.items():
    dic[k] = v

block = [[] for _ in range(N+1)]
for _ in range(K):
    c, d = lr()
    block[c].append(d)
    block[d].append(c)

answer = []
for i in range(1, N+1):
    root = V[i]
    x = dic[root] - 1
    x -= sum(1 for y in block[i] if V[y] == root)
    x -= sum(1 for y in friend[i] if V[y] == root)
    answer.append(x)

print(*answer)


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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  int l[n];
  int sum = 0;
  for(int i=0;i<n;i++){
    cin >> l[i];
    sum += l[i];
  }
  sort(l,l+n);
  if(l[n-1] < sum - l[n-1]){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>
#include <cstdio>
#include <iomanip>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  std::cout << std::fixed << std::setprecision(10);
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  long double res = 0;
  string aru = "0";
  if (h % 2 == 0 && w % 2 == 0 && w / 2 == x && h / 2 == y)
  {
    res = w * h / 2.0L;
    aru = "1";
  }
  res = (w * h) / 2.0L;
  cout << res << " " << aru << endl;
  return 0;
}


Measured memory_bytes: 256
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let n = scan "%d" id
let arr = scan_array ~sep:' ' Int.of_string

let () =
  let l = ArrayL.mapi arr ~f:(fun i a -> i + a) in
  let h = Hashtbl.create n in
  ArrayL.iteri arr ~f:(fun j a ->
      Hashtbl.find_option h (j-a)
      |> Option.map_default succ 1
      |> Hashtbl.add h (j - a));
  ArrayL.map l ~f:(fun a ->
      Hashtbl.find_option h a |> Option.map_default id 0)
  |> Array.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 33096
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}


const int MAXN=200000;
int par[MAXN], rnk[MAXN];

void init(int n){
	REP(i,n){
		par[i] = i;
		rnk[i] = 0;
	}
}
int find(int x){
	if(par[x]==x){
		return x;
	}else{
		return par[x]=find(par[x]);
	}
}
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x==y) return;
	if(rnk[x] < rnk[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rnk[x]==rnk[y]) rnk[x]++;
	}
}
bool same(int x,int y){
	return find(x)==find(y);
}


int main(){
	int n,m;
	cin >> n >> m;
	init(n);
	REP(i,m){
		int a,b;
		cin >> a >> b;
		a--; b--;
		unite(a,b);
	}
	
	map<int,int> s;
	REP(i,n){
		s[find(i)]++;
	}
	int ans=0;
	for(auto x:s){
		chmax(ans, x.second);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 14416
h,w=map(int,input().split())
C=[list(map(int,input().split())) for i in range(h)]

def Largest_Rectangle(grid,h,w):
    re=0
    hist=[[0]*(w+1) for i in range(h)]
    for j in range(w):
        if C[0][j]==0:
            hist[0][j]=1
    for j in range(w):
        for i in range(1,h):
            if C[i][j]==1:continue
            hist[i][j]=hist[i-1][j]+1
    for i in range(h):
        re=max(re,stack_processing_of_rectangle(hist[i]))
    return re

def stack_processing_of_rectangle(hist):
    # スタック処理
    maxrect=0
    stack=[]
    for j in range(w+1):
        if not stack:
            stack.append((hist[j],j))
        elif stack[-1][0]<hist[j]:
            stack.append((hist[j],j))
        elif stack[-1][0]>hist[j]:
            while stack and stack[-1][0]>hist[j]:
                hi,wi=stack.pop()
                maxrect=max(maxrect,hi*(j-wi))
            stack.append((hist[j],wi))
    return maxrect

print(Largest_Rectangle(C,h,w))
# hist=[[0]*(w+1) for i in range(h)]
# for j in range(w):
#     if C[0][j]==0:
#         hist[0][j]=1
# for j in range(w):
#     for i in range(1,h):
#         if C[i][j]==1:continue
#         hist[i][j]=hist[i-1][j]+1

# # スタック処理
# maxrect=0
# stack=[]
# for i in range(h):
#     for j in range(w+1):
#         if not stack:
#             stack.append((hist[i][j],j))
#         elif stack[-1][0]<hist[i][j]:
#             stack.append((hist[i][j],j))
#         elif  stack[-1][0]==hist[i][j]:
#             pass
#         elif stack[-1][0]>hist[i][j]:
#             while stack and stack[-1][0]>hist[i][j]:
#                 hi,wi=stack.pop()
#                 maxrect=max(maxrect,hi*(j-wi))
#             stack.append((hist[i][j],wi))
# print(maxrect)
            

        
        



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

int main(){
	int n, d;
	cin >> n >> d;
	int cnt = 0;
	while(n--){
		double x, y;
		cin >> x >> y;
		if(sqrt(x * x + y * y) <= (double)d) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define ll long long int 
#define double /*long*/ double
#define endl '\n'
#define vll vector<ll>
#define vvll vector<vll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vppll vector<pair<pll,pll>>
#define mp make_pair
#define pb push_back
#define mapll map<ll,ll>
#define fir first
#define sec second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define fo(i,b) for(i=0;i<b;i++)
#define repa(i,a,b) for(i=a;i<b;i++)
#define repb(i,a,b) for(i=a;i>=b;i--)
#define all(x) (x).begin(), (x).end()
#define s(v) v.size()
const long long int MAX = (ll)(1e18+1);
const long long int MIN = (ll)(-1e18-1);
const long long int mod = (ll)(1e9+7);
using namespace std;

ll max(ll a,ll b,ll c) {return max(max(a, b), c);}
ll min(ll a,ll b,ll c) { return min(min(a, b), c);}
ll max(ll a,ll b) {return (a>b) ? a : b;}
ll min(ll a,ll b) {return (a<b) ? a : b;}
ll power(ll a, ll n) {ll p = 1;while (n > 0) {if(n%2) {p = p * a;} n >>= 1; a *= a;} return p;}
ll power_mod(ll a, ll n, ll mod_){ ll p=1; while(n){ if(n%2){ p=(p*a)%mod_;} n/=2; a=(a*a)%mod_;} return p%mod_;}
                                                 /*Code Begins*/



int main(){
    _cin;
    // cout << setprecision(22);
    ll mn = MAX, mx = MIN;
    ll n, t, m, k, i, j,  sum=0,  prev, flag=0, cnt=0;
    ll x=0, y=0, fx, diff, tot=0, l , r;
    int TC=1;
    // cin >> TC;
while(TC--){
    // int n;
    cin >> n;
    ll a[n][n];
    fo(i,n) fo(j,n) cin >> a[i][j];
    // fo(i,n) fo(j,n) cout << a[i][j];
    // cout << endl;
    vll dp(1LL<<n);
    // fo(i,1LL<<n) dp[i]=0;
    dp[0]=1;
    fo(fx,1LL<<n){
        x = __builtin_popcountll(fx);
        // cout << x << ' ';
        fo(i,n){
            if(a[x][i]==1 and !(fx & 1LL<<i)){
                // cout << "re\n";
                y = fx|1LL<<i;
                // cout << dp[fx] << ' ' << y << ' ' << dp[y] << endl;
                dp[y] = (dp[y] + dp[fx]) % mod;
            }
        }
    }
    // cout << endl;
    // fo(i,1LL<<n) cout << dp[i] << ' ';
    // cout << endl;
    cout << dp[(1LL<<n)-1];

}
 return 0;      
}

Measured memory_bytes: 16768
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ld pi = 3.14159265358;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll nCk(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);

//const ll dx[] = {1,0,0,-1};const ll dy[] = {0,1,-1,0};
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    rep(i,100005){
        if(i * i > N){
            cout << (i - 1) * (i - 1) << endl;
            return 0;
        }
    }
}

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int diff(const string &a, const string &b) {
    int ret = 0;
    for (int i=0; i<(int)a.length(); i++)
        ret += (a[i] != b[i]);
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    string s, t;
    cin >> s >> t;

    int ret = INT_MAX;
    for (int i=0; i+(int)t.length()<=(int)s.length(); i++)
        ret = min(ret, diff(s.substr(i, t.length()), t));
    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
int main(void){   
    int i, x;    
    for(i = 1; i <= 10000; i++)  {   
        scanf("%d", &x);    
        if(x == 0) {   
            break;   
        }   
        printf("Case %d: %d\n",i,x); 
    }
    return 0;
    }


Measured memory_bytes: 2028
n = int(input())
s = list(map(str, input().split()))
dic = {'P':0, 'W':0, 'G':0, 'Y':0}
for i in range(n):
    dic[s[i]] += 1
cnt = 0
for i in dic.keys():
    if dic[i] > 0:
        cnt += 1
if cnt == 3:
    print("Three")
elif cnt == 4:
    print("Four")

Measured memory_bytes: 61672
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import Data.List

readIntsLine :: IO [Int]
readIntsLine = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

main :: IO ()
main = do
  getLine
  as <- readIntsLine
  putStrLn . unwords . map (show . fst) . sortOn snd $ zip [1..] as

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

int main()
{
  int n,w;
  cin>>n>>w;
  vector<vector<int>> arr(n,vector<int> (2,0));
  for(int i=0;i<n;i++)
  cin>>arr[i][0]>>arr[i][1];
  vector<vector<long long int>> dp(n+1,vector<long long int> (w+1,0));
  for(int i=0;i<=n;i++)
  {
      for(int j=0;j<=w;j++)
      {
          if(i==0||j==0)
          dp[i][j]=0;
          else if(arr[i-1][0]<=j)
          dp[i][j]=max(arr[i-1][1]+dp[i-1][j-arr[i-1][0]],dp[i-1][j]);
          else
          dp[i][j]=dp[i-1][j];
      }
  }
  cout<<dp[n][w];
 return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
bool comp(int a, int b) 
{ 
    return (a < b); 
} 
int main(){
  int dp[100001][3]={0}, n, a[100001][3], k;
  cin>>n;
  for(int i=0;i<n;i++){
  	for(int j=0;j<3;j++)
    	cin>>a[i][j];
  }
  dp[0][0]=a[0][0];
  dp[0][1]=a[0][1];
  dp[0][2]=a[0][2];
  for(int i=1;i<n;i++){
  	dp[i][0]=max({dp[i][0],dp[i-1][1]+a[i][0],dp[i-1][2]+a[i][0]},comp);
  	dp[i][1]=max({dp[i][1],dp[i-1][0]+a[i][1],dp[i-1][2]+a[i][1]},comp);
  	dp[i][2]=max({dp[i][2],dp[i-1][1]+a[i][2],dp[i-1][0]+a[i][2]},comp);
  }
  cout<<std::max({dp[n-1][0],dp[n-1][1],dp[n-1][2]},comp)<<"\n";
}
  

Measured memory_bytes: 2560