akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int M = 1005;
const int N = 13;

int i,j,n,m,a[M],b[M],dp[1<<N];
set<int> key[M];

void solve()
{
    cin>>n>>m;
    for(i=1;i<=m;++i)
    {
        cin>>a[i]>>b[i];
        for(j=1;j<=b[i];++j)
        {
            int x;
            cin>>x;
            key[i].insert(x-1);
        }
    }
    for(i=0;i<(1<<n);++i)
    {
        dp[i]=INF;
    }
    dp[0]=0;
    for(i=1;i<=m;++i)
    {
        for(j=0;j<(1<<n);++j)
        {
            int box=0;
            for(int k:key[i])
            {
                box|=(1<<k);
            }
            int mask=j;
            dp[mask|box]=min(dp[mask|box],dp[mask]+a[i]);
        }
    }
    if(dp[(1<<n)-1]==INF)
        dp[(1<<n)-1]=-1;
    cout<<dp[(1<<n)-1];
}

signed main()
{
    fastio;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  vector<ll> v(n);
  rep(i, n) cin >> v[i];
  ll ans = 0;
  for(int i=0; i<=k; i++) { // push
    int j = k-i; // pop
    if(j >= n) {
      priority_queue<ll, vector<ll>, greater<ll>> q;
      rep(l, n) q.push(v[l]);
      rep(l, i) {
        if(q.empty()) break;
        if(q.top() >= 0) break;
        q.pop();
      }
      ll tmp = 0;
      while(!q.empty()) {
        tmp += q.top();
        q.pop();
      }
      chmax(ans, tmp);
    } else {
      for(int l=0; l<=j; l++) {
        priority_queue<ll, vector<ll>, greater<ll>> q;
        rep(m, l) q.push(v[m]);
        rep(m, j-l) q.push(v[n-1-m]);
        rep(m, i) {
          if(q.empty()) break;
          if(q.top() >= 0) break;
          q.pop();
        }
        ll tmp = 0;
        while(!q.empty()) {
          tmp += q.top();
          q.pop();
        }
        chmax(ans, tmp);
      }
    }
  }
  cout << ans << endk;
  return 0;
}


Measured memory_bytes: 3604
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
 
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
 
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
 
const int MOD = 1000000007;
 
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"  << " " << __FILE__ << endl;
 
vector<int> sieve_of_eratosthenes(int n) {
    vector<int> primes(n);
    for (int i = 2; i < n; ++i)
        primes[i] = i;
    for (int i = 2; i*i < n; ++i)
        if (primes[i])
            for (int j = i*i; j < n; j+=i)
                primes[j] = 0;
    primes.erase(std::remove(primes.begin(), primes.end(), 0), primes.end());
    return primes;
}
 
signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);
 
    int n;
    cin >> n;
 
    VI prime = sieve_of_eratosthenes(n+1);
    VI count(prime.size(),0);
    FOR(i,2,n+1){
        int t = i;
        while(t!=1){
            for (int j = 0; j < prime.size(); ++j) {
                if(t%prime[j]==0){
                    count[j]++;
                    t/=prime[j];
                    break;
                }
            }
        }
    }
 
    int ans = 1;
    REP(i,count.size()){
        ans*=count[i]+1;
        ans%=MOD;
    }
 
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 888
def calc_t(i,j):
    global t,c
    if i<0 or j<0:
        return n+2
    #print("get t["+str(i)+","+str(j)+"]")
    if t[i][j]==n+1:
        t[i][j]=min(calc_t(i-1,j),calc_t(i,j-c[i])+1)
    return t[i][j]

ri=raw_input().split(" ")
n=int(ri[0])
m=int(ri[1])
ri=raw_input().split(" ")
c=[0]*m
t=[0]*m
for i in range(m):
    c[i]=int(ri[i])
    t[i]=[0]+[n+1]*n if i!=0 else range(n+1)
c=sorted(c)
#print(c)
#print(t)
for a in range(n+1):
    for b in range(m):
        calc_t(b,a)
print(calc_t(m-1,n))

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

int ctoi(const char c){
    if('0' <= c && c <= '9')
        return (c-'0');
    return -1;
}
 
int main(){
    string S;
    cin >> S;
    
    int a = ctoi(S[0])*10 + ctoi(S[1]), b =ctoi(S[2])*10 + ctoi(S[3]);

    if(1 <= a && a <= 12 && 1 <= b && b <= 12)
        cout << "AMBIGUOUS" << endl;
    else if(1 <= a && a <= 12)
        cout << "MMYY" << endl;
    else if(1 <= b && b <= 12)
        cout << "YYMM" << endl;
    else
        cout << "NA" << endl;

}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var a string
	fmt.Scan(&a)
	chars := strings.Split(a,"")

	for k,char := range chars {
		if k % 2 != 0 {
			if char == "R" {
				fmt.Println("No")
				return
			}
		} else {
			if char == "L" {
				fmt.Println("No")
				return
			}
		}
	}

	fmt.Println("Yes")
}

Measured memory_bytes: 640
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; 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;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int t[64];
int d[100100];
ll rec(int num) {
	if (num == 0) return 0;
	return rec(num - 1) + num;
}

void Solve() {

	ll c, k;
	int n;
	cin >> n >> c >> k;
	ll lim = 0;
	ll res = 0;
	ll cc = 0;
	ll t[100010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> t[i];
	}
	sort(t, t + n);
	for (size_t i = 0; i < n; i++)
	{
		if (cc + 1 > c) {
			lim = 0;
			cc = 0;
		}

		if (lim < t[i]) {
			lim = t[i] + k;
			cc = 1;
			res++;
		}
		else {
			cc++;
		}
	}

	cout << res << endl;
}


int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 6784
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int B[100];
  int n;
  
  scanf("%d",&n);
 
  for(int i=0;i<n-1;i++){
    scanf("%d",&B[i]);
  }
  int ans;
  ans=B[0]+B[n-2];
  for(int i=1;i<n-1;i++){
    ans+=B[i-1]<B[i]?B[i-1]:B[i];
  }
  
  printf("%d\n",ans);
  
  return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    a, b = list(map(int, input().rstrip('\n').split()))
    s = str(input().rstrip('\n'))
    d = collections.defaultdict(int)
    for i in range(10):
        d[str(i)]

    b = True
    for i in range(a + b + 1):
        if i < a:
            if s[i] not in d:
                b = False
                break
        elif i == a:
            if s[i] != "-":
                b = False
                break
        else:
            if s[i] not in d:
                b = False
                break
    if b:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <string>
#include <sstream>
int fix()
{
    //example to format floating point numbers.
    double pi = 3.141592653589793;
    double r = 3.141592653589793 * 128;
    std::ios_base::fmtflags f(std::cout.flags()); //[1]
    std::cout << "default:\n  " << pi << " " << r << "\n";
    std::cout << std::setprecision(4) << "setprecision(4):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout << std::setiosflags(std::ios::fixed) << "setiosflags(std::ios::fixed):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout << std::setprecision(5) << "setprecision(5):\n  " //[2]
              << pi << " " << r << "\n";
    std::cout.flags(f);
    std::cout << "reset:\n  " << pi << " " << r << "\n";
    //[1] https://stackoverflow.com/questions/2273330/restore-the-state-of-stdcout-after-manipulating-it
    //[2] https://stackoverflow.com/questions/4217510/how-to-cout-the-correct-number-of-decimal-places-of-a-double-value
    return 0;
}
void multipleLines()
{
    //example to parse multiple lines input.
    std::istringstream isin("1 2 3\n3 2 4\n0 0 0");

    for (std::string str; std::getline(isin, str);)
    {
        std::istringstream tisin(str);
        int a, b, c;
        tisin >> a >> b >> c;
        std::cout << a << " " << b << " " << c << "\n";
    }
    //[1]  https://stackoverflow.com/questions/19767644/c-parsing-input-string-to-variables
}
#include <vector>
#include <set>
#include <map>

int main()
{
    int64_t n, m, l;
    std::vector<int64_t>  vMml, vMbm;
    std::cin >> n >> m >> l;
    vMbm.resize(n * m);
    vMml.resize(m * l);

    for (auto &it : vMbm)
    {
        std::cin >> it;
    }
    for (auto &it : vMml)
    {
        std::cin >> it;
    }

    for (int64_t i = 0; i < n; i++)
    {
        for (int64_t j = 0; j < l; j++)
        {
            int64_t sij = 0;
            for (int k = 0; k < m; k++)
            {
                sij += vMbm[i*m + k] * vMml[k*l + j];
            }
            std::cout << sij;
            if(j != l-1)
            {
                std::cout << " ";
            }
        }
        std::cout << "\n";
    }
}


Measured memory_bytes: 3216
#include <stdio.h>
#include <string.h>

int main() {

    char s[200001];
    scanf("%s", s);
    char *p1;
    char *p2;
    
    p1 = strchr(s, 'A');    
    int sposi = p1 - s;
    
    p2 = strrchr(s, 'Z');
    int eposi = p2 - s;
    
    printf("%d",eposi-sposi+1);


    return 0;
} 

Measured memory_bytes: 384
from sys import stdin
input = stdin.buffer.readline

n, t = map(int, input().split())

cost = 10000

for _ in range(n):
    c, i = map(int, input().split())
    if i <= t and c < cost:
        cost = c

if cost == 10000:
    print('TLE')
else:
    print(cost)

Measured memory_bytes: 62012
import java.io.*;

/**
 * Copyright © 2018 Chris. All rights reserved.
 *
 * @author Chris
 * 2018/6/23 11:55
 * @see meituan.n2018.Bturn
 */
public class Main {


    private static BufferedReader br;
    private static StreamTokenizer st;
    private static PrintWriter pw;

    private static void solve() throws IOException {
        String s = nextLine();
        int n = s.length();

        if (s.charAt(0) != 'A' || s.charAt(1) < 'a') {
            pw.print("WA");
            return;
        }
        boolean flag = false;
        for (int i = 2; i < n; i++) {
            if (s.charAt(i) < 'a') {
                if (flag || s.charAt(i) != 'C') {
                    pw.print("WA");
                    return;
                } else {
                    if (i == n - 1) {
                        pw.print("WA");
                        return;
                    }
                    flag = true;
                }
            }
        }
        if (!flag) {
            pw.print("WA");
        } else {
            pw.print("AC");
        }
    }

    public static void main(String args[]) throws IOException {
//        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//        if (!oj) {
//            System.setIn(new FileInputStream("src/in.txt"));
//        }
        br = new BufferedReader(new InputStreamReader(System.in));
        st = new StreamTokenizer(br);
        pw = new PrintWriter(new OutputStreamWriter(System.out));
        st.ordinaryChar('\''); //指定单引号、双引号和注释符号是普通字符
        st.ordinaryChar('\"');
        st.ordinaryChar('/');

        long t = System.currentTimeMillis();
        solve();
//        if (!oj) {
//            pw.println("[" + (System.currentTimeMillis() - t) + "ms]");
//        }
        pw.flush();
    }


    private static int nextInt() throws IOException {
        st.nextToken();
        return (int) st.nval;
    }

    private static long nextLong() throws IOException {
        st.nextToken();
        return (long) st.nval;
    }

    private static double nextDouble() throws IOException {
        st.nextToken();
        return st.nval;
    }

    private static String[] nextSS(String reg) throws IOException {
        return br.readLine().split(reg);
    }

    private static String nextLine() throws IOException {
        return br.readLine();
    }
}

Measured memory_bytes: 21204
n = int(input())
l = list(map(int,input().split()))

ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i] != l[j] and l[j] != l[k] and l[k] != l[i] and abs(l[i] - l[j])< l[k] < l[i]+l[j]:
                ans +=1

print(ans)


Measured memory_bytes: 9136
#include <stdio.h>
#include <string.h>
#define rep(i, n) for(int i = 0; i < n; ++i)

class dice {
  private:
    int f[6];
  public:
    dice(int *a){
      int i;
      rep(i, 6) f[i] = a[i];
    }
    void n(){
      int t;
      t = f[0];
      f[0] = f[1];
      f[1] = f[5];
      f[5] = f[4];
      f[4] = t;
    }
    void s() {
      int t;
      t = f[0];
      f[0] = f[4];
      f[4] = f[5];
      f[5] = f[1];
      f[1] = t;
    }
    void w() {
      int t;
      t = f[0];
      f[0] = f[2];
      f[2] = f[5];
      f[5] = f[3];
      f[3] = t;
    }
    void e() {
      int t;
      t = f[0];
      f[0] = f[3];
      f[3] = f[5];
      f[5] = f[2];
      f[2] = t;
    }
    int print(int num) {
      return f[num];
    }
};

int main(void) {
  int a[6], i;
  char s[150];
  rep(i, 6) scanf("%d", &a[i]);
  dice d(a);
  scanf("%s", s);
  rep(i, strlen(s)) {
    if(s[i] == 'S') d.s();
    else if(s[i] == 'N') d.n();
    else if(s[i] == 'W') d.w();
    else if(s[i] == 'E') d.e();
  }
  printf("%d\n", d.print(0));
  return 0;
}


Measured memory_bytes: 2752
package main

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

type UnionFindTree struct {
	parent []int
	rank   []int
}

func NewUnionFindTree(n int) *UnionFindTree {
	u := &UnionFindTree{}
	u.parent = make([]int, n)
	u.rank = make([]int, n)
	for i := 0; i < n; i++ {
		u.parent[i] = i
	}
	return u
}

func (u *UnionFindTree) Find(x int) int {
	p := u.parent[x]
	if p == x {
		return p
	} else {
		u.parent[x] = u.Find(p)
		return u.parent[x]
	}
}

func (u *UnionFindTree) Union(x, y int) {
	p := u.Find(x)
	q := u.Find(y)
	if u.rank[p] > u.rank[q] {
		u.parent[q] = p
	} else {
		u.parent[p] = q
		if u.rank[p] == u.rank[q] {
			u.rank[q]++
		}
	}
}

func (u *UnionFindTree) IsSameSet(x, y int) bool {
	return u.Find(x) == u.Find(y)
}

func main() {
	defer stdout.Flush()
	N := readInt()
	M := readInt()
	p := make([]int, N+1)
	uf := NewUnionFindTree(N + 1)
	for i := 1; i < N+1; i++ {
		p[i] = readInt()
	}
	for i := 0; i < M; i++ {
		x := readInt()
		y := readInt()
		uf.Union(p[x], p[y])
	}
	count := 0
	for i := N; i > 0; i-- {
		if uf.IsSameSet(p[i], i) {
			count++
		}
	}
	println(count)
}

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	i, err := strconv.Atoi(readString())
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}


Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

int cal(vector<int> onoff,int now,int num,int bulb,vector<vector<int>> swit,vector<int> extra){
  if(now < num){
    int p = cal(onoff,now+1,num,bulb,swit,extra);
    onoff[now] = 1;
    return p+cal(onoff,now+1,num,bulb,swit,extra);
  }
  for(int i = 0;i < bulb;i ++){
    int p = 0;
    int z = swit[i].size();
    for(int j = 0;j < z;j ++){
      if(onoff[swit[i][j]] == 1){
        p++;
      }
    }
    if(p % 2 != extra[i]){
      return 0;
    }
    
  }
  return 1;
  
}


int main(void){
  int num,bulb;
  vector<vector<int>> swit;
  cin >> num >> bulb;
  for(int i = 0;i < bulb;i ++){
    int p,q;
    cin >> p;
    swit.insert(swit.end(),vector<int>(p));
    for(int j = 0;j < p;j ++){
      cin >> q;
      swit[i][j] = q-1;
    }
  }
  vector<int> extra(bulb);
  for(int i = 0;i < bulb;i ++){
    cin >> extra[i];
  }
  vector<int> onoff(num,0);
  int ans = cal(onoff,0,num,bulb,swit,extra);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
import sys

N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(N - M + 1):
    for j in range(N - M + 1):
        for k in range(M):
            if A[i + k][j:j + M] != B[k]:
                break
        else:
            print("Yes")
            sys.exit()
else:
    print("No")

Measured memory_bytes: 3064
n=int(input())
cnt=[]
for i in range(1,int(n**(1/2))+1000):
    if n%i==0:
        cnt.append(n//i)
        cnt.append(i)
#print(cnt)
ans=[]
for j in range(len(cnt)//2):
    a=list(str(cnt[2*j]))
    b=list(str(cnt[2*j+1]))
    ans.append(max(len(a),len(b)))
print(min(ans))

Measured memory_bytes: 3064
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
mod = 10 ** 9 + 7

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

for i, es in enumerate(s, 1):
    for j, et in enumerate(t, 1):
        dp[i][j] += dp[i-1][j]
        dp[i][j] += dp[i][j-1]
        dp[i][j] -= dp[i-1][j-1]
        if es == et:
            dp[i][j] += dp[i-1][j-1]

        dp[i][j] %= mod

ans = dp[n][m]
print(ans)


Measured memory_bytes: 73436
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef double db;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

namespace Geometry{
	const db eps = 1e-9;
	struct point{
		db x,y;
		inline point operator + (const point &p){return (point){x+p.x,y+p.y};}
		inline point operator - (const point &p){return (point){x-p.x,y-p.y};}
		inline db operator * (const point &p){return x*p.x+y*p.y;}
		inline point operator / (const db &v){return (point){x/v,y/v};}
		inline point operator * (const db &v){return (point){x*v,y*v};}
	};
	typedef point vec;
	inline db dot(vec a,vec b){return a.x*b.x+a.y*b.y;}
	inline db sqr(db x){return x*x;}
	inline db dis(point a,point b){return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));}
	inline db dis2(point a,point b){return sqr(a.x-b.x)+sqr(a.y-b.y);}
	inline db cross(vec a,vec b){return a.x*b.y-a.y*b.x;}
	struct line{
		point a,b;
	};
	inline point projection(point A,line b){
		point B=b.a,C=b.b;
		vec BA=A-B,BC=C-B,BD=BC*(BA*BC/dis2(B,C));
		return B+BD;
	}
	inline point reflection(point A,line b){
		point D=projection(A,b);
		return (point){D.x*2-A.x,D.y*2-A.y};
	}
};
using namespace Geometry;

int main(){
	//freopen("data.in","r",stdin);
	line a;scanf("%lf%lf%lf%lf",&a.a.x,&a.a.y,&a.b.x,&a.b.y);
	int T;scanf("%d",&T);
	while (T--){
		point b,c;scanf("%lf%lf",&b.x,&b.y);
		c=reflection(b,a);
		printf("%.10lf %.10lf\n",c.x,c.y);
	}
}


Measured memory_bytes: 3224
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<map>
#include<cmath>
using namespace std;

typedef long long LL;

const int N=100005;

int n;
LL a[N],b[N];
map<LL,int> ma;

LL sqr(LL x)
{
	return x*x;
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		LL x;scanf("%lld",&x);
		for (LL j=2;j*j*j<=x;j++)
			while (x%(j*j*j)==0) x/=j*j*j;
		ma[x]++;a[i]=x;
		LL y=1;
		for (LL j=2;j*j*j<=x;j++)
			if (x%j==0)
			{
				y*=(x%(j*j)==0)?j:j*j;
				while (x%j==0) x/=j;
			}
		if (sqr((LL)sqrt(x))==x) y*=(LL)sqrt(x);
		else y*=x*x;
		b[i]=y;
	}
	int ans=0;
	if (ma[1]) ans++,ma[1]=0;
	for (int i=1;i<=n;i++) ans+=max(ma[a[i]],ma[b[i]]),ma[a[i]]=ma[b[i]]=0;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 14336
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

string A[1100];

int main(){
    int H, W;
    cin >> H >> W;
    queue<P> que;
    for(int i = 0; i < H; i++){
        cin >> A[i];
        for(int j = 0; j < W; j++){
            if(A[i][j] == '#'){
                que.push(P(i, j));
                A[i][j] = '.';
            }
        }
    }
    for(int loop = 0; loop < 10000; loop++){
        int sz = que.size();
        if(sz == 0){
            cout << loop - 2 << endl;
            break;
        }
        for(int i = 0; i < sz; i++){
            P p = que.front();
            int y = p.first, x = p.second;
            que.pop();
            if(y < 0 || x < 0 || y >= H || x >= W){
                continue;
            }
            if(A[y][x] == '#'){
                continue;
            }
            A[y][x] = '#';
            que.push(P(y + 1, x));
            que.push(P(y - 1, x));
            que.push(P(y, x + 1));
            que.push(P(y, x - 1));
        }
    }
    return 0;
}

Measured memory_bytes: 66880
#include <iostream>

using namespace std;

int main()
{
    long long int X, K, D;

    cin >> X >> K >> D;

    long long int absX = (X >= 0) ? X : (-X);

    long long int q = absX / D;

    if (q >= K)
    {
        cout << absX - K * D << endl;
        return 0;
    }

    // 以下、q < K    q 回のとき最小値
    long long int r = absX - q * D;
    long long int r2 = D - r;

    if ((K - q) % 2 == 0)
    {
        cout << r << endl;
        return 0;
    }
    else
    {
        cout << r2 << endl;
        return 0;
    }

    return 0;
}


Measured memory_bytes: 3632
N=int(input())
D=list(map(int, input().split()))
M=int(input())
T=list(map(int, input().split()))
if N<M:
  print('NO')
  exit()
  
A={}
B={}
for i in D:
  if i not in A:
    A[i]=0
  A[i]+=1
  
for i in T:
  if i not in B:
    B[i]=0
  B[i]+=1
  
for i in B.keys():
  if not i in A:
    print('NO')
    exit()
  if A[i]<B[i]:
    print('NO')
    exit()
print('YES')


Measured memory_bytes: 58708
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d; cin >> a >> b >> c >> d;
	if(a+b==c+d){
		cout << "Balanced" << endl;
		return 0;
	}if(a+b>c+d){
		cout << "Left" << endl;
		return 0;
	}else{
		cout << "Right" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

P f(int x) {
  int a = x % 10;
  int b = 0;
  while(x) {
    b = x;
    x /= 10;
  }
  return P(a, b);
}

int main() {
  int n; cin >> n;
  map<P, int> mp;
  for(int i = 1; i <= n; i++) {
    P p = f(i);
    mp[p]++;
  }
  ll ans = 0;
  for(int i = 1; i <= n; i++) {
    P p = f(i);
    P q(p.second, p.first);
    ans += mp[q];
  }
  cout << ans << endl;
  return 0;
}


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


for i in range(w):
    for j in range(h):
        if s[i][j] == '#':
            if j-1<0 and i+1>=w and j+1>=h and i-1>=0:
                if s[i-1][j] == '#' or s[i+1][j] == '#'  or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit()        
            elif i-1<0 and j-1>=0 and j+1<h and i+1>=w:
                if  s[i+1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit() 
            elif j-1>=0 and i+1<w and j+1>=h and i-1 >=0:
                if s[i-1][j] == '#' or s[i+1][j] == '#' or s[i][j-1] == '#' :
                    continue
                else:
                    print("No")
                    exit() 
            elif j-1>=0 and i+1>=w and j+1<h and i-1 >=0 :
                if s[i-1][j] == '#'  or s[i][j-1] == '#' or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit()  
            elif j-1>=0 and i+1<w and j+1<h and i-1 >=0 :
                if s[i-1][j] == '#' or s[i+1][j] == '#' or s[i][j-1] == '#' or s[i][j+1] == '#':
                    continue
                else:
                    print("No")
                    exit()        

print("Yes")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
multiset<int>s;
int main(){
	int n; scanf("%d",&n);
	for(int i=1; i<=n; ++i){
		int x; scanf("%d",&x); s.insert(x);
	}
	int ans=0;
	for(int i=1; i<=n&&!s.empty(); ++i){
		int k=*(--s.end());
		s.erase(--s.end());
		for(int j=1; j<32; ++j)
			if(s.find((1<<j)-k)!=s.end()){
				++ans; s.erase(s.find((1<<j)-k)); break;
			}
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;cin>>s;
    int n=s.size();
    int ans=0;
    rep(i,0,n/2){
        if(s[i]!=s[n-i-1])ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
        #define tani_nachi_ke  ios_base::sync_with_stdio(false); cin.tie(NULL);
        #define M_PI 3.14159265358979323846
        #define data data_
        #define ff first
        #define ss second
        #define pb push_back
        #define ld long double
        #define int long long
        #define print(t) cout << "Case #" << t << ": ";
        int32_t main()
        {
            tani_nachi_ke  
            
            
            int a,b,c,k;
            cin >> a >> b >> c >> k;

            if(k <= a)
                cout << k << endl;
            else if(k <= a + b)
                cout << a << endl;
            else
            {
                cout << a - (k - b - a) << endl;
            }



           return 0;
        }
          

Measured memory_bytes: 3640
#include<stdio.h>
int main(){
  int a,b,sum,n,m;

  while(scanf("%d %d",&a,&b)!=EOF){
    sum=a+b;
    m = 1;
    for ( n = 1; n <= 1000000; n = n*10){
      if(n<=sum && sum<n*10){printf("%d\n", m);}
      m = m+1;
    }
    
  }
  return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for(long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for(long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                                                            \
    (upper_bound((V).begin(), (V).end(), X) -                                  \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                                                               \
    {                                                                          \
        cerr << #v << ':';                                                     \
        for(auto xv : v) cerr << xv << ' ';                                    \
        cerr << endl;                                                          \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2> inline bool chmin(T1 &a, const T2 &b) {
    if(a > b) a = b;
    return a > b;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, const T2 &b) {
    if(a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* liblary */

/* main */

ll N;

ll calc(ll x) {
    if(x == 1) {
        return 0;
    }
    ll m = x - 1;
    if(N / m == N % m) {
        return m;
    }
    return 0;
}

signed main() {
    cin >> N;
    ll ans = 0;
    for(ll i = 1; i * i <= N; i++) {
        if(N % i == 0) {
            if(i * i != N) {
                ans += calc(N / i);
            }
            ans += calc(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 255;
int n,cnt[N];int vis[N];//0..23
int s[N],sz,res;
int calc(){
	int mn=24,mx=0,res=0;
	rep(i,0,23)if(vis[i])mx=i;
	per(i,23,0)if(vis[i])mn=i;
	res=mn+24-mx;
	rep(i,0,mx-1)if(vis[i]){
		int j=i+1;while(!vis[j])j++;
		umin(res,j-i);
	}
	return res;
}
int main() {
	read(n);vis[0]++;
	rep(i,1,n){int x;read(x);cnt[x]++;}
	rep(i,0,12)if(cnt[i]>=3){puts("0");return 0;}
	if(cnt[0]){puts("0");return 0;}
	rep(i,1,12)if(cnt[i]==2)vis[i]=vis[24-i]=1;
	else if(cnt[i])s[++sz]=i;
//	if(!sz)res=calc();
	rep(S,0,(1<<sz)-1){
		rep(i,1,sz)vis[S>>i-1&1?s[i]:24-s[i]]++;
		umax(res,calc());
		rep(i,1,sz)vis[S>>i-1&1?s[i]:24-s[i]]--;
	}
	cout<<res;
	return 0;
}


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

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

	string S;

	cin >> S;
	
	int l=S.size();
	
	long long num,sum,ans=0;;
	
	rep(bit,(1<<l-1)){
		string s=S;
		num=0;
		sum=0;
		rep(i,l-1){
			if(bit & 1<<i){
				s.insert(l-i-1,"+");///////////////
			}
		}
		//cout << s << endl;
		rep(i,20){
			if(s[i]=='\0'){
				sum+=num;
				break;
			}
			if(s[i]=='+'){
				s=s.substr(i+1);
				i=0;
				sum+=num;
				//cout << num << endl;
				num=0;
			}
			num=num*10+(s[i]-'0');
			//cout << i << num << endl;
		}
		ans+=sum;
	}
					

	cout << ans << "\n";

    }

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

const int N = (20) + 5;
int b[N];

int main() { // claudio van
  int n, m, c; scanf("%d %d %d", &n, &m, &c);
  for (int i = 0; i < m; ++i) {
    scanf("%d", &b[i]);
  }
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int j = 0; j < m; ++j) {
      int a; scanf("%d", &a);
      sum += a * b[j];
    }
    sum += c;
    cnt += (sum > 0);
  }
  printf("%d\n", cnt);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	forn(i, n-1){
		int x;
		cin >> x;
		a[--x]++;
	}
	forn(i, n)
		cout << a[i] << endl;
	return 0;
}



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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
	ost<<"{"<<p.first<<","<<p.second<<"}";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N;cin>>N;
	double denom=0;
	rep(i,N){
		int a;cin>>a;
		denom+=1.0/a;
	}
	printf("%.20f\n",1.0/denom);
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#define int  long long int
	#define pb push_back
	#define fe first
    #define lb lower_bound
    #define ub upper_bound
    #define pii pair<pair<int,int>,pair<int,int> >
	#define se second
	#define endl "\n"
	#define pi pair<int, int>
	#define vi vector<int>
	#define vvi vector<vi>
    #define bs   binary_search
	#define rep(i,a,b) for(int i=a;i<b;i++)
	#define rep1(i,a,b) for(int i=a;i<=b;i++)
    #define all(c) (c).begin(),(c).end()
    #define sz(x)       (int)x.size()
	#define PI 3.14159265358979323846

	const int N =2e5+5;

     int mod= 998244353;
     int dx[4]={0,0,+1,-1};
     int dy[4]={+1,-1,0,0};

      int maxi;
      
    void solve(){
         int a,b;
         cin>>a>>b;
         
         int f1=a+b;
         int f2=a-b;
         int f3=a*b;
         
         int mx=max({f1,f2,f3});
         cout<<mx<<endl;
     }
       
       
	int32_t main() {

	  cool;
	  int t=1;
     // cin>>t;


	  while (t--)
		 solve();

	  return 0;
	}


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

typedef long long ll;

int digitSum(int n) {
    if (n / 10 == 0)
        return n;
    return (n % 10) + digitSum(n / 10);
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    ll ss = 0;
    for (int i = 1; i <= n; i++) {
        int ds = digitSum(i);
        if (a <= ds && ds <= b) {
            ss += i;
        }
    }
    cout << ss << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int H,W,N;
int X[1000][1000];
int DP[1000][1000];
int main()
{
	while(true){
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				DP[i][j]=0;
			}
		}
		scanf("%d%d%d",&H,&W,&N);
		if(H==0&&W==0&&N==0)break;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				scanf("%d",&X[i][j]);
			}
		}
		DP[0][0]=N-1;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(i==0&&j==0)continue;
				if(i==0){
					if(DP[i][j-1]&1){
						if(X[i][j-1]==1){
							DP[i][j]=(DP[i][j-1]>>1)+1;
						}
						else DP[i][j]=DP[i][j-1]>>1;
					}
					else{
						DP[i][j]=DP[i][j-1]>>1;
					}
				}
				else if(j==0){
					if(DP[i-1][j]&1){
						if(X[i-1][j]==0){
							DP[i][j]=(DP[i-1][j]>>1)+1;
						}
						else DP[i][j]=DP[i-1][j]>>1;
					}
					else{
						DP[i][j]=DP[i-1][j]>>1;
					}
				}
				else{
					if(DP[i-1][j]&1){
						if(X[i-1][j]==0){
							DP[i][j]+=(DP[i-1][j]>>1)+1;
						}
						else DP[i][j]+=DP[i-1][j]>>1;
					}
					else{
						DP[i][j]+=DP[i-1][j]>>1;
					}
					if(DP[i][j-1]&1){
						if(X[i][j-1]==1){
							DP[i][j]+=(DP[i][j-1]>>1)+1;
						}
						else DP[i][j]+=DP[i][j-1]>>1;
					}
					else{
						DP[i][j]+=DP[i][j-1]>>1;
					}
				}
			}
		}
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				X[i][j]=(X[i][j]+DP[i][j])&1;
			}
		}
		int XX=0;int YY=0;
		while(XX<W&&YY<H){
			if(X[YY][XX])XX++;
			else YY++;
		}
		printf("%d %d\n",YY+1,XX+1);
	}
	return 0;
}

Measured memory_bytes: 9000
import java.util.Scanner;

/**
 *
 * @author Ivan Eka
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int count = 0;
        int c = 0, t;
        int N = sc.nextInt();
        int T = sc.nextInt();
        int[][] Route = new int[N][2];
        for (int c1 = 0; c1 < N; c1++) {
            Route[c1][0] = sc.nextInt();
            Route[c1][1] = sc.nextInt();
            if (Route[c1][1] > T) {
                count++;
            }
        }
        if (count == N) {
            System.out.println("TLE");
        } else {
            c = Route[0][0];
            for (int c2 = 0; c2 < N; c2++) {
                if (T >= Route[c2][1]) {
                    if (c > Route[c2][0]) {
                        c = Route[c2][0];
                    }
                }
            }
            System.out.println(c);
        }
    }
}

Measured memory_bytes: 22868
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
int expression(string &exp, int &pos);
int term(string &exp, int &pos);
int factor(string &exp, int &pos);
int expression(string &exp, int &pos) {
	int ret = term(exp, pos);
	while (pos < exp.size() && exp[pos] == '+') {
		pos++;
		(ret += term(exp, pos));
	}
	return ret;
}
int term(string &exp, int &pos) {
	int ret = factor(exp, pos);
	while (pos < exp.size() && exp[pos] == '*') {
		pos++;
		(ret *= term(exp, pos));
	}
	return ret;
}
int factor(string &exp, int &pos) {
	int num = exp[pos] - '0';
	pos++;
	return num;
}
int main() {
	string exp;
	cin >> exp;
	int bobs_ans;
	cin >> bobs_ans;
	int pos = 0;
	int true_ans = expression(exp, pos);
	int false_ans = exp[0] - '0';
	for (int i = 1; i < exp.size(); i += 2) {
		if (exp[i] == '+') {
			false_ans += exp[i + 1] - '0';
		}
		else {
			false_ans *= exp[i + 1] - '0';
		}
	}
	if (bobs_ans == true_ans && bobs_ans == false_ans) {
		cout << "U" << endl;
	}
	else if (bobs_ans == true_ans) {
		cout << "M" << endl;
	}
	else if (bobs_ans == false_ans) {
		cout << "L" << endl;
	}
	else {
		cout << "I" << endl;
	}
}


Measured memory_bytes: 3208
/// a.cpp
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
const pair < int , int > DD[] = {{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < decltype(v.x) > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pll pair < ll , ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define fail puts("-1")
# define yes puts("YES")
# define no puts("NO")
# define PP puts("Possible")
# define II puts("Impossible")
# define vii vector < pii >
# define vll vector < pll >
# define pb push_back
# define pdd pair < db , db >
# define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    int n;
    fi>>n;
    static ll s[1 << 20];
    for (int i = 1;i <= n;++i)
        fi>>s[i],s[i] += s[i - 1];
    ll ans = 1e18;
    for (int i = 1;i < n;++i)
        smin(ans,abs(s[i] - (s[n] - s[i])));
    fo << ans << '\n';
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
TA = []
for i in range(N):
    TA.append(list(map(int, input().split())))

t_real = [TA[0][0]]
a_real = [TA[0][1]]

for i in range(1,N):
    t_cand = (t_real[i-1]//TA[i][0] + bool(t_real[i-1]%TA[i][0])) * TA[i][0]
    a_cand = (a_real[i-1]//TA[i][1] + bool(a_real[i-1]%TA[i][1])) * TA[i][1]
    
    if t_cand//TA[i][0] * TA[i][1] >= a_real[i-1]:
        t_real.append(t_cand)
        a_real.append(t_cand//TA[i][0] * TA[i][1])
        
    elif a_cand//TA[i][1] * TA[i][0] >= t_real[i-1]:
        a_real.append(a_cand)
        t_real.append(a_cand//TA[i][1] * TA[i][0])
        
    else:
        print("error")
        
print(t_real[-1]+a_real[-1])

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;

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

    vector<int> x(n);
    vector<int> y(n);

    rep(i, n){
        cin >> x[i];
    }
    rep(i, n){
        cin >> y[i];
    }

    double d1 = 0.0;
    double d2 = 0.0;
    double d3 = 0.0;
    double di = 0.0;

    rep(i, n){
        d1 += abs(x[i] - y[i]);
    }

    rep(i, n){
        d2 += (x[i] - y[i]) * (x[i] - y[i]);
    }

    d2 = sqrt(d2);

    rep(i, n){
        d3 += abs(x[i] - y[i]) * abs(x[i] - y[i]) * abs(x[i] - y[i]);
    }

    double a = 1.0 / 3.0;

    d3 = pow(d3, a);

    rep(i, n){
        double dd = abs(x[i] - y[i]);
        if(dd > di) di = dd;
    }

    printf("%f\n%f\n%f\n%f\n",d1, d2, d3, di);

    return 0;
}


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

int next_index[26][200010];

int main() {
	string A;
	cin >> A;
	A="?"+A;
	vector<string> v(26, "a");
	for(int i=0; i<26; ++i){
	    v[i][0] += i;
	}
	for(int p=A.size()-2; p>=0; --p){
	    int now=0;
	    for(int i=1; i<26; ++i){
	        if(v[i].size()<v[now].size()) now=i;
	    }
	    v[A[p+1]-'a']=A[p+1]+v[now];
	}
	int ans=0;
	for(int i=1; i<26; ++i){
	    if(v[i].size()<v[ans].size()) ans=i;
	}
	cout << v[ans] << endl;
	return 0;
}


Measured memory_bytes: 772