akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;

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);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        public void solve(InputReader in, PrintWriter out) {
            int D = in.nextInt();
            int G = in.nextInt() / 100;
            int p[] = new int[D];
            int c[] = new int[D];
            for (int i = 0; i < D; i++) {
                p[i] = in.nextInt();
                c[i] = in.nextInt() / 100;
            }

            int ans = Integer.MAX_VALUE;
            for (int mask = 0; mask < 1 << D; mask++) {
                int sum = 0; int cnt = 0; int rest_max = -1;
                for (int i = 0; i < D; i++) {
                    if ((mask >> i & 1) == 1) {
                        sum += p[i]*(i + 1) + c[i];
                        cnt += p[i];
                    } else {
                        rest_max = i;
                    }
                }
                if (rest_max >= 0) {
                    for (int i = 1; i < p[rest_max]; i++) {
                        if (sum >= G) {
                            break;
                        } else {
                            sum += rest_max + 1;
                            cnt += 1;
                        }
                    }
                }
                if (sum >= G) {
                    ans = Math.min(cnt, ans);
                }
            }

            out.println(ans);
        }

    }

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

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

Measured memory_bytes: 23380
import java.util.*;
import java.io.*;

public class Main{
    static int INFTY = Integer.MAX_VALUE;
        
    public static void main (String args[]){
        //初期処理
        Scanner sc=new Scanner(System.in);
        int n=Integer.parseInt(sc.nextLine());
    //    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    //    try{
    //        int n = Integer.parseInt(br.readLine());

            //「最小経路木V」に頂点を一つずつ入れていく
            int[] color = new int[n];   //0:未探索, -1:探索中(周辺), +1:最小経路木に追加済
            int[][] M = new int[n][n];
            int[] d = new int[n];       //Vからの最短距離
            int[] p =new int[n];       //親(一意に定まる)を記録
            //初期化
            for (int i=0;i<n;i++){
                d[i]=INFTY;
                for (int j=0;j<n;j++){
                    M[i][j]=INFTY;
                }
            }
            p[0] =-1;
            d[0]=0;

            for(int i=0;i<n;i++){
                sc.nextInt();   //ノードIDはいったん捨てる
                int m=sc.nextInt();
                for (int j=0;j<m;j++){
                    int s = sc.nextInt();   //隣接ノード
                    int t = sc.nextInt();   //重さ
                    M[i][s]=t;

                }
            }

            int u=0;        //Vに追加する頂点
            while(true){
                int mincost=INFTY;
                for(int i=0;i<n;i++){
                    if (color[i]!=1 && d[i]<mincost){
                        mincost=d[i];
                        u=i;                            //Vから一番近い頂点を選択
                    }
                }
                if (mincost==INFTY){                    //すべて探索済みだったら終了
                    break;
                }
                color[u]=1;                             //uを探索済みにする

                for(int i=0;i<n;i++){
                    if(color[i]!=1&&M[u][i]!=INFTY){       //uと結ばれている頂点について、d[]が更新できるなら更新し、親をuとする
                        if(d[u]+M[u][i]<d[i]){              //新規にVに追加されたuを経由して最小経路が作れるならd[]を更新
                            d[i]=d[u]+M[u][i];
                            p[i]=u;
                            //color[i]=-1;　            ←本には載ってたけどこれいらなくない？
                        }
                    }
                }
            }
            for(int i=0;i<n;i++){
                System.out.println(i+" "+d[i]);
            }
        // } catch (IOException e) {
        //     e.printStackTrace();
        // }

        
    }
    
}


    


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

using namespace std;

int main() {
	int n;
	ignore = scanf("%d", &n);
	
	if ((n & (n - 1)) == 0) {
		printf("%s\n", "No");
		return 0;
	}
	
	printf("%s\n", "Yes");
	
	int k = n;
	while (k % 4 != 3) k--;
	
	printf("%d %d\n", k, n + 1);
	for (int i = 1; i < k; i++) {
		printf("%d %d\n", i, i + 1);
		printf("%d %d\n", n + i, n + i + 1);
	}
	
	if (n == k + 1) {
		int a = n & (n - 1);
		int b = n ^ a;
		printf("%d %d\n", a + 1, n);
		printf("%d %d\n", n + b, n + n);
	}
	else if (n > k + 1) {
		printf("%d %d\n", 2, k + 1);
		printf("%d %d\n", k + 1, k + 2);
		printf("%d %d\n", 3, n + k + 2);
		printf("%d %d\n", n + k + 2, n + k + 1);
		
		if (n == k + 3) {
			printf("%d %d\n", 2, k + 3);
			printf("%d %d\n", k + 1, n + k + 3);
		}
	}
	
	return 0;
}


Measured memory_bytes: 2816
#include<iostream>
#include<sstream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define mp make_pair
#define pb push_back
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

const int inf=1<<28;
const double INF=1e12,EPS=1e-9;

bool p[1000000];

int main()
{
  for(int i=2;i*i<1000000;i++)if(!p[i])for(int j=i+i;j<1000000;j+=i)p[j]=1;
  p[0]=p[1]=1;
  int n;
  while(cin>>n){
    int ans=0;
    rep(i,n)if(!p[i+1])ans++;
    cout<<ans<<endl;
  }
  return 0;
}

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

int main()
{
  int a, b, m;
  cin >> a >> b >> m;

  valarray<int> re(a);
  valarray<int> mw(b);
  for (auto&& e : re) cin >> e;
  for (auto&& e : mw) cin >> e;

  int ans = re.min() + mw.min();
  for (int i = 0; i < m; i++) {
    int x, y, c;
    cin >> x >> y >> c;
    x--;
    y--;
    ans = min(ans, re[x] + mw[y] - c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  t,i,x,j,k,n,m,ans=0,pwd;
    string s;
    cin>>n>>m;
    ans=(n-m)*100+m*1900;
    pwd=(1<<m);
    ans*=pwd;
    cout<<ans<<endl;
    return 0;
}





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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);
    int a,b,c; cin>>a>>b>>c;
    Yes(a==b+c||b==c+a||c==a+b);
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
const int N=210;
int n;
int a[N];
void readData(){
	scanf("%d",&n);
	for(int i=1;i<=n*2;i++) scanf("%d",&a[i]);
}
void solve(){
	sort(a+1,a+1+n*2);
	int ans=0;
	for(int i=n*2-1;i>=1;i-=2) ans+=a[i];
	printf("%d\n",ans);
}
int main(){
	readData();
	solve();
	return 0;
}


Measured memory_bytes: 128
data = input().split()
N = int(data[0])
T = int(data[1])
c = []
t = []
i = 0
j = 0
while i < N:
  sc = input().split()
  c.append(int(sc[0]))
  t.append(int(sc[1]))
  i += 1

mn = min(t)
if mn > T:
  print("TLE")
else:
  mn = c[0]
  while j < N:
    if t[j] <= T:
      
      if mn >= c[j]:
        mn = c[j]
        ind = j
        
    j += 1

  print(c[ind])
 
  
  

Measured memory_bytes: 3064
import java.util.Scanner;

class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int abCount = 0;
        int topBandendA = 0;//先頭がBで最後がA
        int topB = 0;//先頭がB
        int endA = 0;//最後がA
        Boolean addBfrag = false;
        String[] s = new String[N];
        //入力処理
        //入力ごとに文字列中のABの数を数える
        for (int i = 0; i < N; i++) {
            s[i] = sc.next();
            abCount += abCount(s[i]);
            if (s[i].startsWith("B") && endWith(s[i], 'A')) {
                topBandendA++;
            } else if (s[i].startsWith("B")) {
                topB++;
            } else if (endWith(s[i], 'A')) {
                endA++;
            }
        }

        if (endA > 0) {
            endA--;
            addBfrag = true;
        } else if (topBandendA > 0) {
            topBandendA--;
            addBfrag = true;
        }
        while (topBandendA > 0) {
            topBandendA--;
            abCount++;
        }
        if (topB > 0 && addBfrag) {
            topB--;
            abCount++;
        }
        while (endA > 0 && topB > 0) {
            endA--;
            topB--;
            abCount++;
        }

        System.out.println(abCount);
    }

    private static int abCount(String s) {
        int abNum = 0;
        int from = -1;
        Boolean frag = true;
        while (frag) {
            from = s.indexOf("AB", from);
            if (from != -1) {
                from++;
                abNum++;
            } else {
                frag = false;
            }
        }
        return abNum;
    }

    private static Boolean endWith(String s, char endChar) {
        Boolean frag;
        char check = s.charAt(s.length() - 1);
        if (endChar == check) {
            frag = true;
        } else {
            frag = false;
        }
        return frag;
    }
}

Measured memory_bytes: 31744
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}


macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let mut p: Vec<_> = (0..n).map(|_| {
        let x: i64 = sc.cin();
        let l: i64 = sc.cin();
        (x + l, x - l)
    }).collect();
    p.sort();
    // trace!(&p);

    let mut ans = 0;
    let mut x = -100000007;
    for &(end, begin) in p.iter() {
        if x > begin { continue }
        x = end;
        ans += 1;
    }
    put!(ans);
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a == 1){
    a = 14;
  }
  if(b == 1){
    b = 14;
  }
  if(a >  b){
    cout << "Alice" << endl;
  }else if(a < b){
    cout << "Bob" << endl;
  }else{
    cout << "Draw" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int x,t;
    cin>>x>>t;
    if(x-t>0)cout<<x-t<<endl;
    else cout<<0<<endl;

}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const int UF_MAX = 100010;

class UF{
	int x[UF_MAX];
	int co;
	
public:
	
	UF(){
		fill(x,x+UF_MAX,-1);
		co = 0;
	}
	
	int boss(int a){
		int s = a;
		while(x[s] > -1) s = x[s];
		if(s != a) x[a] = s;
		return s;
	}
	
	void uni(int a , int b){
		int s = boss(a);
		int t = boss(b);
		if(s != t){
			++co;
			if(x[s] < x[t]){
				x[s] += x[t];
				x[t] = s;
			} else {
				x[t] += x[s];
				x[s] = t;
			}
		}
	}
	
	bool find(int a , int b){
		return boss(a) == boss(b);
	}
	
	int count(){
		return co;
	}
	
	int member(int a){
		return -x[boss(a)];
	}
} uf;

int N,M;

int main(){
	cin >> N >> M;
	repp(i,0,M){
		int a,b;
		cin >> a >> b;
		uf.uni(a,b);
	}
	int x = min(uf.member(1),uf.member(2));
	cout << (LL)x * (x-1) / 2 + (LL)(N-x) * (N-x-1) / 2 - M << endl;
	return 0;
}


Measured memory_bytes: 640
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=5005;
int n,a,b;
ll dp[maxn];
int main(){
    ios::sync_with_stdio(0);
    memset(dp,0x3f,sizeof(dp));dp[0]=0;
    cin>>n>>a>>b;
    rep(i,1,n){
        int num;cin>>num;
        ll mi=1e18;
        rep(j,0,num)mi=min(mi,dp[j]);
        rep(j,0,num)dp[j]+=a;
        rep(j,num+1,n)dp[j]+=b;
        dp[num]=min(dp[num],mi);
    }
    ll ans=1e18;
    rep(i,1,n)ans=min(ans,dp[i]);
    cout<<ans;
    return 0;
}

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

/*

1. Problem (state).

2. Divide problem into subproblems

3. Merge solutions to solve the original problem.

*/
int n;
const int N = 100001;
int dp[N][3];
int a[N][3];
int solve(int i, int last_activity){ // solve for the last n days where the last activity is 'last_activity'
  if(i == n)
    return 0;

  if(last_activity != -1 && dp[i][last_activity] != -1)
    return dp[i][last_activity];
  int res = 0;
  if(last_activity != 0)
    res = max(res, a[i][0] + solve(i + 1, 0));

  if(last_activity != 1)
    res = max(res, a[i][1] + solve(i + 1, 1));

  if(last_activity != 2)
    res = max(res, a[i][2] + solve(i + 1, 2));
  dp[i][last_activity] = res;
  return res;
}
int main() {
//  freopen("transform.in", "r", stdin);
//  freopen("in.txt", "r", stdin);

  cin >> n;
  memset(dp, -1, sizeof(dp));
  for(int i = 0;i < n;i++)
    	cin >> a[i][0] >> a[i][1] >> a[i][2];
  cout << solve(0, -1);

  return 0;
}


Measured memory_bytes: 7296
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n+1];
        long[] b = new long[n];
        for (int i = 0; i < n+1; i++) {
            a[i] = sc.nextLong();
        }
        for (int i = 0; i < n; i++) {
            b[i] = sc.nextLong();
        }
        long ans = 0l;
        for (int i = 0; i < n/2 +1; i++) {
            if(b[i] <= a[i]){
                ans += b[i];
                a[i] -= b[i];
                b[i] = 0;
            }else{
                ans += a[i];
                b[i] -= a[i];
                a[i] = 0;
                if(b[i] <= a[i+1]){
                    ans += b[i];
                    a[i+1] -= b[i];
                    b[i] = 0;
                }else{
                    ans += a[i+1];
                    b[i] -= a[i+1];
                    a[i+1] = 0;
                }
            }
            if(i < n - 1 - i){
                if(b[n - 1 - i] <= a[n - i]){
                    ans += b[n - 1 - i];
                    a[i] -= b[n - 1 - i];
                    b[n - 1 - i] = 0;
                }else{
                    ans += a[n - i];
                    b[n - 1 - i] -= a[n - i];
                    a[n-i] = 0;
                    if(b[n - 1 - i] <= a[n - i - 1]){
                        ans += b[n - 1 - i];
                        a[n - i -1] -= b[n - 1 - i];
                        b[n - 1 - i] = 0;
                    }else{
                        ans += a[n-i-1];
                        b[n - 1 - i] -= a[n-i-1];
                        a[n-i-1] = 0;
                    }
                }
            }
        }

        System.out.println(ans);
        sc.close();

    }

}


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

using namespace std;
#define int long long
vector <int> rasl(int n)
{
    vector <int> v;
    if(n==1)
    {
        return v;
    }
    for(int i=2;i*i<=n;++i)
    {
        if(n%i==0)
        {
            v=rasl(n/i);
            v.push_back(i);
            return v;
        }
    }
    v.push_back(n);
    return v;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector <int> v=rasl(n);
    map <int,int> u;
    vector <int> keys;
    for(int i=0;i<v.size();++i)
    {
        if(!u.count(v[i]))
        {
            u[v[i]]=1;
            keys.push_back(v[i]);
        }
        else
        {
            u[v[i]]++;
        }
    }
    vector <int> g;
    for(int i=0;i<keys.size();++i)
    {
        g.push_back(u[keys[i]]);
    }
    int sum=0;
    for(int i=0;i<g.size();++i)
    {
        for(int j=0;j<10000;++j)
        {
            if((j*(j+1)/2)>g[i])
            {
                sum+=(j-1);
                break;
            }
        }
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3644
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main() {
    IOS;
    ll n;
    ll m = 3;
    cin >> n;
    vector<ll> a(m),b(m);
    REP(i,m){
        cin >> a[i];
    }
    REP(i,m){
        cin >> b[i];
    }
    vector<vector<ll>> dp(m + 1, vector<ll>(n + 1, 0));
    REP(i, m) {
        REP(j, n + 1) {
            chmax(dp[i+1][j],dp[i][j]);
            if (j >= a[i]) {
                chmax(dp[i+1][j],dp[i+1][j - a[i]] + b[i]);
            }
        }
    }
    ll t = dp[m][n];
    ll use = 0;
    REP(j, n + 1){
        if(dp[m][j]==t){
            use=j;
            break;
        }
    }
    t += n - use;
    chmax(t,n);
    vector<vector<ll>> dp2(m + 1, vector<ll>(t + 1, 0));
    REP(i, m) {
        REP(j, t + 1) {
            chmax(dp2[i+1][j],dp2[i][j]);
            if (j >= b[i]) {
                chmax(dp2[i+1][j],dp2[i+1][j - b[i]] + a[i]);
            }
        }
    }
    ll t2 = dp2[m][t];
    use = 0;
    REP(j, t + 1){
        if(dp2[m][j]==t2){
            use=j;
            break;
        }
    }
    t2 += t - use;
    chmax(t2,t);
    put(t2);
    return 0;
}



Measured memory_bytes: 977024
#include <bits/stdc++.h>
//#pragma GCC diagnostic error "-Wconversion"
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define mp(a, b) make_pair(a, b)
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
using namespace std;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
ll digits(ll x){
  ll length = 0;
  while (x > 0){
    x /= 10;
    length++;
  }
  return length;
  if (x == 0) return 0;
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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(){
  cout << fixed << setprecision(15);
  int ans = 0;
  //string ans;

  int n; cin >> n;
  ans = (n + 1) / 2;

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

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

int n, W;
int weight[105], value[105];
int dp[105][10005];

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    cin >> n >> W;
    for(int i=0;i<n;++i) cin >> value[i] >> weight[i];

    for(int i=0;i<=W;++i) dp[0][i] = 0;

    for(int i=0;i<n;i++){
        for(int j=0;j<=W;j++){
            if(j>=weight[i]){
                dp[i+1][j] = max(dp[i][j-weight[i]]+value[i], dp[i][j]);
            } else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    cout << dp[n][W] << "\n";
    return 0;
}


Measured memory_bytes: 7112
N, M = map(int, input().split())
MOD = 998244353

if N < M :
    one = N - (N - M) % 2
    two = (3 * M - one) // 2
else :
    one, two = M, M
    
L = M + M // 2 + N - 1

fac = [0] * (L + 1)
inv = [0] * (L + 1)
fac[0], inv[0] = 1, 1

for i in range(1, L + 1) :
    fac[i] = fac[i-1] * i % MOD
    inv[i] = pow(fac[i], MOD-2, MOD)

def comb(n, r) :
    if n <= 0 or r < 0 :
        return 0
    return fac[n]*inv[n-r]*inv[r]%MOD

ret = 0
while one >= 0 :
    ret += comb(N, one) * comb(two+N-1, N-1) % MOD
    ret %= MOD
    one -= 2
    two += 1
 
ret -= comb(3*M+N-1-(2*M+1), N-1) * N
print(ret % MOD)

Measured memory_bytes: 68080
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long A, long long B, long long T){
    int ans = 0;
    for (int i = A; i <= T; i+=A)
    {
        ans+=B;
    }
    cout << ans << endl;
    
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long T;
    scanf("%lld",&T);
    solve(A, B, T);
    return 0;
}


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

int main() {

  int n, i, b, f, r, v, count=0;
  int house[5][4][11] = {};
  // 0?????????????????????????????????????????§1???????????????????????????

  cin >> n;

  // ??\?±???????????????¨??????
  for(i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    house[b][f][r] += v;
  }

  //?????????????????¨???(??????version)
  // for(b = 1; b <= 4; b++){
  //   for(f = 1; f <= 3; f++){
  //     for(r = 1; r <= 10; r++){
  // 	cout << " " << house[b][f][r];
  //     }
  //     cout << endl;
  //   }
  //   if(count < 3) cout << "####################" << endl;
  //   count++;
  // }

  //?????????????????¨???(?§£???version)
  for( int f = 1; f <= 4; f++ ){
    if( f > 1 ) cout << "####################\n";
    for( int b = 1; b <= 3; b++ ){
      for( int r = 1; r <= 10; r++ ){
	cout << " " << house[f][b][r];
      }
      cout << endl;
    }
  }
  
  return 0;
  
}

Measured memory_bytes: 1164
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include <set>
#include<iomanip>
#include<map>
#include<unordered_map>

#include<stdio.h>
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

#define PI  3.141592
//----------------------------------------


int main(void)
{

	string s;
	cin >> s;

	if (s[0] == s[1]&&s[1] == s[2]) cout << "No" << endl;

	else cout << "Yes" << endl;

}

Measured memory_bytes: 256
n = int(input())
li = list(map(int, input().split()))

class Node():
  def __init__(self, data):
    self.data = data
    self.parent = None
    self.left, self.right = None, None

def all_print(node, key, parent, left, right):
  if node:
    print("node {}: ".format(node), end="")
  if key:
    print("key = {}, ".format(key), end="")
  if parent:
    print("parent key = {}, ".format(parent), end="")
  if left:
    print("left key = {}, ".format(left), end="")
  if right:
    print("right key = {}, ".format(right), end="")
  print("")
  


result = []
for i in range(n):
  x = Node(li[i])
  result.append(x)

for i in range(n):
  x = result[i]
  if 2 * (i+1) <= n:
    x.left = result[2*(i+1)-1]
  if 2 * (i+1) + 1 <= n:
    x.right = result[2*(i+1)]
  if i >= 1:
    x.parent = result[int((i+1)/2)-1]
  result.append(x)

for i in range(n):
  node = i+1
  key = result[i].data
  if node != 1:
    parent = result[i].parent.data
  else:
    parent = None
  if result[i].left:
    left = result[i].left.data
  else:
    left = None
  if result[i].right:
    right = result[i].right.data
  else:
    right = None
  all_print(node, key, parent, left, right)



Measured memory_bytes: 5788
#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 vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

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


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}


int main(){
	int n;
    cin>>n;
    vl x(n);
    FOR(i,0,n){
        cin>>x[i];
    }
    cmbset(101010);
    if(n==2){
        cout<<x[1]-x[0]<<endl;
        return 0;
    }
    LL ans=0,t=1,v=0;
    FOR(i,1,n){
        t=mul(t,i);
    }
    FOR(i,1,n){
        v=add(v,dvs(t,i));
        ans=add(ans,mul(v,x[i]-x[i-1]));
        
    }
    cout<<ans<<endl;




}


Measured memory_bytes: 1792
A,B=map(int,input().split())
S=input()
if "0"<=S[0:A] and S[0:A]<="9"*A:
  if S[A:A+1]=="-" :
    if "0"<=S[A+1:A+B+1] and S[A+1:A+B+1]<="9"*B :
      print("Yes")
      exit()
print("No")

Measured memory_bytes: 9096
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (1000000007LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

ll pwr(ll base, ll p, ll mod = MOD){
ll ans = 1;while(p){if(p&1)ans=(ans*base)%mod;base=(base*base)%mod;p/=2;}return ans;
}


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


int n;
ll a, b, arr[100005];


int main(){

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
        cin>>arr[i];

    ll ans = 0;
    for(int i=2;i<=n;i++)
        ans += min(b, a*(arr[i]-arr[i-1]));

    cout<<ans;
    return 0;
}





Measured memory_bytes: 1024
def slove():
    import sys
    input = sys.stdin.readline
    h, w, a, b = list(map(int, input().rstrip('\n').split()))
    for i in range(h):
        if i < b:
            print("".join(["0"] * a + ["1"] * (w - a)))
        else:
            print("".join(["1"] * a + ["0"] * (w - a)))


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39920
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
const ll INF = (1 << 30);
const ll inf = (1LL << 50LL);
const int  maxn = 1e5 + 5;
const int MOD = 1e9 + 7;
int n, m;
char mat[1005][1005];
int dp[1005][1005];
int rek(int i, int j){
    if(i == n - 1 and j == m - 1){
        return 1;
    }
    if(dp[i][j] != -1){
        return dp[i][j];
    }
    int ret = 0;
    if(i + 1  < n and mat[i + 1][j] == '.'){
        ret += rek(i + 1, j);
        ret %= MOD;
    }
    if(j + 1 < m and mat[i][j + 1] == '.'){
        ret += rek(i, j + 1);
        ret %= MOD;
    }
    return dp[i][j] = ret % MOD;
}
int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
//    ifstream cin("in.txt");
    cin >> n >> m;
    for(int i = 0; i < n; i ++){
        for(int j = 0; j < m; j ++){
            cin >> mat[i][j];
            dp[i][j] = -1;
        }
    }
    cout << rek(0, 0) << endl;
    return 0;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int mnx = 3e5 + 9;
const int mod = 1e9 + 7;

int n, c, k;
int t[mnx];

int main(){

cin >> n >> c >> k;

for(int i=0; i<n; i++) {
    cin >> t[i];
}

sort(t, t + n);

if(c == 1) {
    cout << n << endl;
    return 0;
}

int res = t[0], cnt = 1;
int ans = 1;

for(int i=1; i<n; i++){
    if(t[i] > res + k || cnt == c) {
        ans++;
        res = t[i];
        cnt = 1;
    } else {
        cnt++;
    }
}

cout << ans << endl;

return 0;

}


Measured memory_bytes: 640
// 2013/06/14 Tazoe

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	while(true){
		unsigned n;
		cin >> n;

		if(n==0)
			break;

		unsigned sum = 0;
		for(int i=0; i<n; i++){
			unsigned p;
			cin >> p;

			sum += p;
		}

		unsigned j[65000];
		for(int i=0; i<n-1; i++){
			cin >> j[i];
		}

		sort(j, j+(n-1));

		unsigned sal_max = n*sum;

		for(int i=n-1; i>=1; i--){
			sum += j[i-1];

			sal_max = max(sal_max, (unsigned)i*sum);
		}

		cout << sal_max << endl;
	}

	return 0;
}

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

const int N = 2005, INF = 1E9 + 7;

int n, v, bit[2 * N], pos[N][2], dp[N][N];
char c;

void upd(int u, int v)
{
    for (; u <= 2 * n; u += u & -u)
        bit[u] += v;
}

int que(int u)
{
    int ret = -1;
    for (; u > 0; u -= u & -u)
        ret += bit[u];
    return ret;
}

void init()
{
    fill(bit + 1, bit + 2 * n + 1, 0);
    for (int i = 1; i <= 2 * n; i++)
        upd(i, 1);
    for (int i = 1; i <= n; i++)
        upd(pos[i][1], -1);
}

int main()
{
    cin >> n;
    for (int i = 1; i <= 2 * n; i++)
    {
        cin >> c >> v;
        pos[v][c == 'B'] = i;
    }
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            dp[i][j] = INF;
    dp[0][0] = 0;
    for (int i = 0; i < 2 * n; i++)
    {
        init();
        int pw = 1, pb = n;
        for (int w = max(0, i - n); w <= n && w <= i; w++)
        {
            int b = i - w;
            for (; pw <= w; pw++)
                upd(pos[pw][0], -1);
            for (; pb > b; pb--)
                upd(pos[pb][1], 1);
            if (w < n)
                dp[w + 1][b] = min(dp[w + 1][b], dp[w][b] + que(pos[w + 1][0]));
            if (b < n)
                dp[w][b + 1] = min(dp[w][b + 1], dp[w][b] + que(pos[b + 1][1]));
        }
    }
    cout << dp[n][n];
}

Measured memory_bytes: 16000
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> p[i];
	}

	auto valid = true;
	auto swap = false;
	for (auto i = 0; i < N; ++i)
	{
		if (p[i] != i + 1)
		{
			if (p[p[i] - 1] != i + 1)
			{
				valid = false;
				break;
			}

			if (swap)
			{
				valid = false;
				break;
			}
			p[p[i] - 1] = p[i];
			p[i] = i + 1;
			swap = true;
		}
	}

	if (valid)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
N, M = [int(s) for s in input().split(' ')]
As = [int(s) for s in input().split(' ')]
CBs = []
for m in range(M):
    B, C = [int(s) for s in input().split(' ')]
    CBs.append((C, B))
As.sort(reverse=True)
CBs.sort(reverse=True)
CBs.append((0, 0))
ret = 0
a = 0
bc = 0
n = 0
while n < N:
    C, B = CBs[bc]
    if As[a] < C:
        bc += 1
        pick = min(N - n, B)
        ret += pick * C
        n += pick
    else:
        ret += As[a]
        a += 1
        n += 1
print(ret)



Measured memory_bytes: 20912
#include<iostream>
#include<cstdio>
#include<cassert>
#include<set>
#include<algorithm>
using namespace std;
const int N=100005;
int n;
int a[N],b[N];
pair<int,int> p[N];
int q[N];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]),p[i]=make_pair(a[i],i);
	sort(p+1,p+n+1,greater<pair<int,int> >());
	set<pair<int,int> >S;
	for(int i=1;i<=n;i++)
		scanf("%d",&b[i]),q[i]=i,S.insert(make_pair(b[i],i));
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		int u=p[i].second;
		if(a[u]<=b[q[u]])
		{
			S.erase(S.lower_bound(make_pair(b[q[u]],u)));
			continue;
		}
		set<pair<int,int> >::iterator A=S.lower_bound(make_pair(b[q[u]],u)),B=S.lower_bound(make_pair(a[u],0));
		if(B==S.end())
		{
//			cerr<<"now"<<u<<" "<<"\n";
			printf("No");
			return 0;
		}
		assert(A!=S.end());
		int v=B->second;
//		cerr<<"swap"<<u<<" "<<v<<"\n";
		S.erase(A);
		S.erase(B);
		swap(q[u],q[v]);
		S.insert(make_pair(b[q[v]],v));
		ans++;
	}
	if(ans<=n-2) printf("Yes");
	else printf("No");
//	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 10408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> adj(N);
    for (int i = 0, A, B; i < M; i++) {
        cin >> A >> B;
        adj[A - 1].push_back(B - 1);
        adj[B - 1].push_back(A - 1);
    }
    vector<int> guide(N, -1);
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
        int t = q.front();
        q.pop();
        for (int i : adj[t]) {
            if (guide[i] != -1) continue;
            guide[i] = t;
            q.push(i);
        }
    }
    cout << "Yes" << endl;;
    for (int i = 1; i < N; i++) cout << guide[i] + 1 << endl;
}

Measured memory_bytes: 10212
s = tuple(input())
t = tuple(input())
n = len(s)
m = len(t)

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

for i in range(1,n+1):
    for j in range(1,m+1):
        if s[i-1] == t[j-1]:
            dp[i][j] = dp[i-1][j-1]  + 1
        else:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])

res = ''
while n != 0 and m != 0:
    if dp[n][m] == dp[n-1][m]:
        n -= 1
    elif dp[n][m] == dp[n][m-1]:
        m -= 1
    else:
        n -= 1
        m -= 1
        res = s[n] + res
print(res)

Measured memory_bytes: 114908
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;
using ll = long long;

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

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

	vector<ll> vec(N);

	for (size_t i = 0; i < N; i++) {
		cin >> vec[i];
	}

	// まずは絶対値の合計を求める
	ll ans = accumulate(cbegin(vec), cend(vec), 0LL, [](auto sum, auto x) {
		return sum + abs(x);
	});


	// 0があれば合計が正解
	{
		auto it = find(cbegin(vec), cend(vec), 0);
		if (it != cend(vec)) {
			cout << ans << endl;
			return 0;
		}
	}
	// 0なしのとき・・・
	// 0なしでも、負の数が偶数個であれば合計で行ける
	// 奇数個だと最低の要素のみが負だと考えればよい

	auto minuscount = count_if(cbegin(vec), cend(vec), [](auto x) {
		return x < 0;
	});

	if (minuscount % 2 == 1) {
		// 全部を絶対値にする
		for_each(begin(vec), end(vec), [](auto&& x) {
			x = abs(x);
		});

		const auto elem = *min_element(cbegin(vec), cend(vec));
		ans -= elem * 2;
	}

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



Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int a[10],b=0,c,i,j,n;
  while(scanf("%d",&n)){
    if(n==0) break;
    for(i=0;i<10;i++) a[i]=0;
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        scanf("%d",&c);
        a[j]+=c;
        b+=c;
        printf("%5d",c);
      }
      printf("%5d\n",b);
      b=0;
    }
    for(i=0;i<n;i++){
      b+=a[i];
      printf("%5d",a[i]);
    }
    printf("%5d\n",b);
    b=0;
  }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,C,K;
	cin >> N >> C >> K;
	vector<int> T(N);
	rep(i,N)cin >> T[i];
	sort(ALL(T));
	int ans = 0;
	for(int i=0;i<N;i++){
		int now = T[i];
		int cnt = 1;
		ans++;
		while(cnt<C && i+1<N && T[i+1] <= now+K){
			i++;
			cnt++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
	int n, i;
	char s[200001][11]={};
	scanf("%d", &n);
	for(i=0;i<n;i++)	scanf("%s", s[i]);
	
	qsort(s, n, 11, strcmp);
	
	int nums[200001];
	nums[0]=1;
	for(i=1;i<n;i++){
		if(strcmp(s[i-1], s[i])==0){
			nums[i]=nums[i-1]+1;
		}else{
			nums[i]=1;
		}
	}
	int max=0;
	for(i=0;i<n;i++){
		if(nums[i]>max){
			max=nums[i];
		}
	}
	
	for(i=0;i<n;i++){
		if(nums[i]==max){
			printf("%s\n", s[i]);
		}
	}
	
	return 0;
}


Measured memory_bytes: 4988
#include <stdio.h>
int n,d[100001],a[100001],maxd,maxa,maxdi,maxai;
long long int ans=1;
int main() {
	scanf("%d",&n);
	for(int i=0;i<n;i++) {
		scanf("%d",&d[i]);
		if(maxd<d[i]) {
			maxd=d[i];
			maxdi=i;
		}
	}
	for(int i=0;i<n;i++) {
		scanf("%d",&a[i]);
		if(maxa<=a[i]) {
			maxa=a[i];
			maxai=i;
		}
	}
//	printf("maxd=%d maxdi=%d maxa=%d maxai=%d\n",maxd,maxdi,maxa,maxai);
	if(maxd!=maxa || maxdi>maxai){
		printf("0");
		return 0;
	} 
	for(int i=1;i<=maxdi;i++) {
		if(d[i]<d[i-1]) {
			printf("0");
			return 0;
		}
		if(d[i]==d[i-1])
			ans = ans * d[i] % 1000000007;
	}
	for(int i=n-2;i>=maxai;i--) {
		if(a[i]<a[i+1]) {
			printf("0");
			return 0;
		}
		if(a[i]==a[i+1])
			ans = ans * a[i] % 1000000007;
	}
	for(int i=maxdi+1;i<maxai;i++)
		ans = ans * d[i] % 1000000007;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[100005],flag,nn,cnt[100005],m1,m2,n1,n2,mx1=100001,mx2=100002,nx1=100003,nx2=100004;
int main() {
	scanf("%d",&n);for(int i=1;i<=n;++i) {scanf("%d",&a[i]);nn=a[1];if(nn!=a[i]) flag=1;}
	if(!flag) {printf("%d",n/2);return 0;}
	for(int i=1;i<=n;i+=2) cnt[a[i]]++;
	for(int i=1;i<=100000;i++) {
		if(m1<cnt[i]) {m2=m1;mx2=mx1;mx1=i;m1=cnt[i];}
		else if(m2<cnt[i]) {m2=cnt[i];mx2=i;}
	}
	for(int i=1;i<=100000;i++) cnt[i]=0;
	for(int i=2;i<=n;i+=2) cnt[a[i]]++;
	for(int i=1;i<=100000;i++) {
		if(n1<cnt[i]) {n2=n1;nx2=nx1;nx1=i;n1=cnt[i];}
		else if(n2<cnt[i]) {n2=cnt[i];nx2=i;}
	}
	if(nx1!=mx1) printf("%d",n-n1-m1);
	else printf("%d",min(n-n1-m2,n-n2-m1));
	return 0;
}

Measured memory_bytes: 2512
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long 
#define MAX 25 * 1e13


using namespace std;

int main(){
  int a,b;
  int has[4] = {0};

  cin >> a >> b;
  has[a] = 1;
  has[b] = 1;
  int ret = 0;
  for( int i = 1 ; i <= 3 ; i++ ){
    if( has[i] == 0 ) {
      ret = i;
      break;
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256