akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N - 1); for (auto &a : A) cin >> a;
    vector<vector<int>> B(N, vector<int>(M));
    for (auto &row : B) for (auto &b : row) cin >> b;
    vector<vector<int>> C(N, vector<int>(M, 1e9));
    for (int i = 0; i < M; i++) {
        set<pair<int, int>> S;
        for (int a = N - 1; a >= 0; a--) {
            auto it = S.lower_bound(make_pair(B[a][i] + 1, 0));
            if (it != S.end()) {
                C[a][i] = it->second;
            }
            while (it != S.begin()) {
                S.erase(prev(it));
            }
            S.emplace(B[a][i], a);
        }
    }
    vector<vector<bool>> used(N, vector<bool>(M));
    vector<Int> diff(N);
    for (int i = 1; i < N; i++) {
        diff[i] = -A[i - 1];
    }
    Int ans = 0;
    for (int start = 0; start < N; start++) {
        for (int i = 0; i < M; i++) {
            int a = start;
            int b = C[start][i];
            while (b < N && !used[b][i]) {
                diff[b] += B[b][i] - B[a][i];
                used[b][i] = true;
                a = b;
                b = C[b][i];
            }
        }
        Int tmp = 0;
        for (int i = 0; i < M; i++) {
            tmp += B[start][i];
        }
        ans = max(ans, tmp);
        for (int i = start + 1; i < N; i++) {
            tmp += diff[i];
            ans = max(ans, tmp);
        }
        for (int i = 0; i < M; i++) {
            int a = start;
            int b = C[start][i];
            if (b < N) {
                diff[b] -= B[b][i] - B[a][i];
                used[b][i] = false;
            }/*
            while (b < N) {
                diff[b] -= B[b][i] - B[a][i];
                used[b][i] = false;
                a = b;
                b = C[b][i];
            }*/
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 9088
while 1:
 m,f,r=map(int,input().split());s=m+f
 if m==f==r==-1:break
 if m==-1 or f==-1:print('F')
 elif s>79:print('A')
 elif s>64:print('B')
 elif s>49:print('C')
 elif s>29:print('C') if r>49 else print('D')
 else:print('F')

Measured memory_bytes: 5596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;

int main() {
  int p = 0, AN[101];
  int N = 0, h = 0;
  long long  tmp, min=200000000;
  cin >> N;
  while (p<N) {
    cin >> AN[p];
    p++;
  }
  for (p = -100;p < 101;p++) {
    tmp = 0;
    for (h = 0;h < N;h++) tmp += (AN[h]-p)*(AN[h]-p);
    if (tmp < min) min = tmp;
  }
  printf("%d\n", min);
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC164_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var S = new List<string>();

            for (int i = 0; i < N; i++)
            {
                S.Add(Console.ReadLine());
            }
            var group = S.GroupBy(s => s);

            Console.WriteLine(group.Count());
        }
    }
}


Measured memory_bytes: 60836
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

ll n;
vector<ll>a;
map<ll,ll>mp;
ll solve(){
   ll ans=0;
   rep(i,n){
       ll id=i+1;
       ll h=a[i];
       ans+=mp[id-h];
       mp[id+h]++;
   }

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

    cin>>n;
    a.resize(n);
    rep(i,n)cin>>a[i];
    cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 27404
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define FPEN2 freopen("out.txt", "w", stdout);
#else
#define FPEN
#define FPEN2
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 1e9 + 7;
class {
 public:
  i64 A[maxn], B[maxn];
  map<pair<i64, i64>, int> mp;
  i64 pw2[maxn];
  void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> A[i] >> B[i];
    pw2[0] = 1;
    for (int i = 1; i < maxn; ++i) pw2[i] = pw2[i - 1] * 2 % MOD;
    int A0 = 0, B0 = 0;
    i64 add = 0;
    for (int i = 1; i <= n; ++i) {
      if (A[i] == 0 && B[i] == 0) {
        add++;
        continue;
      }
      if (A[i] == 0)
        A0++;
      else if (B[i] == 0)
        B0++;
      else {
        int f = -1;
        if (A[i] > 0 && B[i] > 0)
          f = 1;
        else if (A[i] < 0 && B[i] < 0)
          f = 1;
        A[i] = abs(A[i]);
        B[i] = abs(B[i]);
        i64 gcd = __gcd(A[i], B[i]);
        A[i] /= gcd, B[i] /= gcd;
        mp[{A[i] * f, B[i]}]++;
      }
    }
    i64 ans = 1;
    for (auto i : mp) {
      if (i.second == 0) continue;
      pi64 j;
      if (i.first.first < 0)
        j = {i.first.second, -i.first.first};
      else
        j = {-i.first.second, i.first.first};
      // cout << i.first.first << " " << i.first.second << " " << j.first << " " << j.second << endl;
      if (mp.count(j)) {
        (ans *= (pw2[i.second] + pw2[mp[j]] + MOD - 1) % MOD) %= MOD;
        mp[j] = 0;
      } else {
        (ans *= pw2[i.second]) %= MOD;
      }
    }
    if (A0 == 0 && B0) {
      (ans *= pw2[B0]) %= MOD;
    } else if (A0 && !B0) {
      (ans *= pw2[A0]) %= MOD;
    } else if (A0 && B0) {
      (ans *= (pw2[A0] + pw2[B0] + MOD - 1) % MOD) %= MOD;
    }
    ans += add - 1;
    ans = (ans % MOD + MOD) % MOD;
    cout << ans << '\n';
  }
} NSPACE;
int main() {
  FPEN;
  FPEN2;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}

Measured memory_bytes: 20824
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j;
            cin>>n;
            string ar[n+1];
            for(i=1;i<=n;++i)
            {
                cin>>ar[i];
                sort(ar[i].begin(),ar[i].end());
            }
            sort(ar+1,ar+n+1);
            ll ct=1;
            ll ans=0;
            for(i=2;i<=n;++i)
            {
                if(ar[i]==ar[i-1])
                {
                    ++ct;
                }
                else
                {
                    ans=ans+ct*(ct-1)/2;
                    ct=1;
                }
            }
            ans=ans+ct*(ct-1)/2;
            ct=1;
            cout<<ans<<endl;
        }
        return 0;
    }


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 5003, mod = 1e9 + 7;
int n, head[N], to[N << 1], nxt[N << 1], siz[N], f[N][N], tmp[N], g[N];
inline void qmo(int &x){x += (x >> 31) & mod;}
inline void add(int a, int b){
    static int cnt = 0;
    to[++ cnt] = b; nxt[cnt] = head[a]; head[a] = cnt;
}
inline void dfs(int x, int fa = 0){
    f[x][1] = siz[x] = 1;
    for(Rint i = head[x];i;i = nxt[i]) if(to[i] != fa){
        dfs(to[i], x);
        memcpy(tmp + 1, f[x] + 1, siz[x] << 2);
        memset(f[x] + 1, 0, siz[x] << 2);
        for(Rint j = 1;j <= siz[x];++ j)
            for(Rint k = 0;k <= siz[to[i]];++ k)
                qmo(f[x][j + k] += (LL) tmp[j] * f[to[i]][k] % mod - mod);
        siz[x] += siz[to[i]];
    }
    for(Rint i = 2;i <= siz[x];i += 2)
        qmo(f[x][0] -= (LL) f[x][i] * g[i] % mod);
}
int main(){
    scanf("%d", &n);
    for(Rint i = 1, u, v;i < n;++ i){
        scanf("%d%d", &u, &v); add(u, v); add(v, u);
    }
    g[0] = 1;
    for(Rint i = 2;i <= n;i += 2) g[i] = (i - 1ll) * g[i - 2] % mod;
    dfs(1); printf("%d\n", mod - f[1][0]);
}

Measured memory_bytes: 96896
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P; 
const int N = 100005;
//////////////////////////////

int n;
string p;
Int dp[3300][3300];
Int dp_sum[3300][3300];

int main()
{
	cin >> n;
	cin >> p;
	dp[0][0] = 1;

	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= i - 1; j++) {
			dp_sum[i - 1][j] = dp[i - 1][j];
			if (j - 1 >= 0) dp_sum[i - 1][j] += dp_sum[i - 1][j - 1];
			dp_sum[i - 1][j] %= MOD;
		}
		for (int j = 0; j <= i; j++) {
			if (p[i - 1] == '<') {
				if (j - 1 >= 0) dp[i][j] = dp_sum[i - 1][j - 1];
			}
			else {
				dp[i][j] = dp_sum[i - 1][i - 1];
				if (j - 1 >= 0) dp[i][j] -= dp_sum[i - 1][j - 1];
				dp[i][j] %= MOD;
			}
		}
	}

	Int ans = 0;
	for (int i = 0; i < n; i++) {
		ans += dp[n - 1][i];
		ans %= MOD;
	}
	if (ans < 0) ans += MOD;
	cout << ans << endl;

	return 0;
}

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

int main() {
    std::string src = "Hoshino";
    std::string tar = "Hoshina";

    std::cin.tie(0);
    std::ios::sync_with_stdio(false);

    int n;
    std::cin >> n;
    std::cin.ignore();

    std::string s;
    for (int i = 0; i < n; i++) {
        std::getline(std::cin, s);
        auto pos = s.find(src);
        while (pos != std::string::npos) {
            s.replace(pos, tar.length(), tar);
            pos = s.find(src, pos + tar.length());
        }

        std::cout << s << std::endl;
    }
}

Measured memory_bytes: 3124
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(mut aa: Vec<i64>) -> i64 {
    use std::cmp::min;

    let n = aa.len();

    for i in 0..n {
        aa[i] -= (i+1) as i64;
    }

    let mut s = 0;
    for &a in aa.iter() {
        s += a as i64;
    }

    aa.sort();
    let avg = aa[n/2];

    let mut ret1 = 0;

    for &a in aa.iter() {
        ret1 += (a-avg).abs();
    }

    ret1
}


fn main() {
    read_line!();

    let aa = parse_vec!(i64);
    println!("{}", solve(aa));
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![2,2,3,5,5]), 2);
    assert_eq!(solve(vec![1,2,3,4,5,6,7,8,9]), 0);
    assert_eq!(solve(vec![6,5,4,3,2,1]), 18);
    assert_eq!(solve(vec![1,1,1,1,2,3,4]), 6);
    assert_eq!(solve(vec![1,1,1,5]), 4);
}


Measured memory_bytes: 10492
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long 
#define ret return
#define PB push_back
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define pii pair <int,  int>
#define pll pair <long long , long long>  
#define FAST ios::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const int maxn = 3e6 + 50 , K = 25;
vector <int> edges[maxn];
ll a[maxn] , n , ans;

void dfs(int v, int p = -1) {
    int b = 0;
    for (auto u : edges[v]) {
        if (u == p) continue;
        dfs(u , v);
        for (int i = b; i < K; ++i) {
            if ((a[v] & a[u]) & (1 << i)) {
                b = i + 1;
            }
        }
        a[v] |= a[u];
        while (a[v] & (1 << b)) {
            b++;
        }
    }
    for (int i = 0; i < b; ++i) {
        if (a[v] & (1 << i)) {
            a[v] -= (1 << i);
        }
    }
    a[v] |= (1 << b);
}
int main() {
    FAST
    cin >> n;
    for (int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        edges[u].PB(v);
        edges[v].PB(u);
    }
    dfs(1);
    for (int i = 0; i < K; ++i) {
        if (a[1] & (1 << i)) {
            ans = i;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;

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

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

int main()
{
    int n;

    while(cin>>n)
    {
        int ans=1;
        while(n--)
        {
            int a;
            cin>>a;
            ans=lcm(ans,a);
        }
        cout<<ans<<endl;
    }

    return 0;
}



Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        
        int max = Math.max(Math.max(A,B),C);
        int sum = A + B + C - max;
        
        for(int i = 0; i < K; i++){
            max *= 2; 
        }        
        
        System.out.println(max + sum);
    }
}


Measured memory_bytes: 20692
#include<stdio.h>
int m[]={1,5,10,50,100,500},i,r,n;
int main()
{
	for(i=r=0;i<6;i++)
	{
		scanf("%d",&n);
		r+=n*m[i];
	}
	printf("%d\n",r>999);
	return 0;
}

Measured memory_bytes: 600
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[]
C=[]
for i in range(Q):
  Bt,Ct=map(int,input().split())
  B+=[Bt]
  C+=[Ct]
num =[0 for i in range(10**5+3)]
for i in range(N):
  num[A[i]]+=1
S=0
for i in range(10**5+1):
  S+=num[i]*i
for i in range(Q):
  tmp=num[B[i]]
  num[B[i]] =0
  num[C[i]] += tmp
  S=S+tmp*(C[i]-B[i])
  print(S)

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


int main(){
  int n,x;
  int input;
  vector<int> l;
  int len=0;
  cin>>n>>x;
  int count=1;
  for(int i=0;i<n;i++){
    cin>>input;
    l.push_back(input);
    len+=l[i];
    if(len<=x){
      count++;
    }
  }
  cout<<count<<endl;

  return 0;
}




Measured memory_bytes: 256
# coding: utf-8
import math
N, K = map(int,input().split())
#N = int(input())
#K = int(input())
#S = input()
ans = 0
flg = True
#l = list(map(int,input().split()))
#A = list(map(int,input().split()))
if N%K == 0:
    print(0)
else:
    print(1)

Measured memory_bytes: 9160
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 200005
using namespace std;
typedef long long ll;
struct edge{
	int k,next;
}e[N<<1];
int home[N],cnt=-1,n,f[N][2],g[N],mx[N],mn[N],siz[N],tot;
ll ans=1;
char s[N];
void add(int x,int y){
	cnt++;
	e[cnt].k=y;
	e[cnt].next=home[x];
	home[x]=cnt;
}
void dfs(int k,int F){
	f[k][1]=-1e9; siz[k]=s[k]=='1';
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		dfs(e[i].k,k);
		if(f[e[i].k][0]+1>f[k][0])
			f[k][1]=f[k][0],f[k][0]=f[e[i].k][0]+1;
		else if(f[e[i].k][0]+1>f[k][1]) f[k][1]=f[e[i].k][0]+1;
		siz[k]+=siz[e[i].k];
	}
}
void dfs1(int k,int F){
	if(f[F][0]==f[k][0]+1) g[k]=f[F][1]+1;
	else g[k]=f[F][0]+1;
	g[k]=max(g[k],g[F]+1);
	if(!F) g[k]=0;
	mn[k]=1e9;
	if(tot>siz[k]) mn[k]=g[k];
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		if(siz[e[i].k]){
			mn[k]=min(mn[k],f[e[i].k][0]+1);
		}
	}
	if(g[k]>f[k][0]) f[k][1]=f[k][0],f[k][0]=g[k];
	else f[k][1]=max(f[k][1],g[k]);
	if(s[k]=='1') mn[k]=0;
	mx[k]=min(f[k][0]-1,f[k][1]+1);
	for(int i=home[k];~i;i=e[i].next) if(e[i].k!=F){
		dfs1(e[i].k,k);
	}
}
int main(){
	memset(home,-1,sizeof(home));
	scanf("%d",&n);
	for(int i=1,x,y;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) tot+=s[i]=='1';
	dfs(1,0);
	dfs1(1,0);
	for(int i=1;i<=n;i++) ans+=max(0,mx[i]-mn[i]+1);
	printf("%lld",ans);
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;
template <class T>
using VVV = V<V<V<T>>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    int n, m;
    cin >> n >> m;
    V<int> a(m);
    rep(i, m) cin >> a[i];
    V<int> dp(n + 1, INF);
    dp[0] = 0;
    rep(i, m) {
        rep2(j, a[i], n + 1) { dp[j] = min(dp[j], dp[j - a[i]] + 1); }
    }
    cout << dp[n] << endl;

    return 0;
}



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

using namespace std;

#define mp make_pair

char grid[55][55];
int red,stup;
int crni = 0;

int bfs(){
	bool bio[55][55];
	memset(bio,0,sizeof(bio));
	queue < pair<int,int> > q;
	queue <int> qh;
	q.push(mp(0,0));
	qh.push(1);
	while(!q.empty()){
		pair<int,int> node = q.front();
		int cnt = qh.front();
		q.pop();
		qh.pop();
		int x = node.first;
		int y = node.second;
		if(x == red-1 && y == stup-1) return cnt;
		for(int i = 0; i < 4; i++){
			int dx[] = {1,0,-1,0};
			int dy[] = {0,1,0,-1};
			int nx = x + dx[i];
			int ny = y + dy[i];
			if(grid[nx][ny] == '#' || bio[nx][ny] || nx < 0 || ny < 0 || nx >= red || ny >= stup) continue;
			q.push(mp(nx,ny));
			qh.push(cnt+1);
			bio[nx][ny] = 1;
		}
	}
	return -1;
}

int main(){
	cin >> red >> stup;
	for(int i = 0; i < red; i++){
		for(int j = 0; j < stup; j++){
			cin >> grid[i][j];
			if(grid[i][j] == '#') crni++;
		}
	}
	int put = bfs();
	if(put == -1){
		cout << -1 << endl;
		return 0;
	}
	else{
		cout << red*stup - crni - put << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N,M,X;
	cin >> N >> M >> X;
	std::vector<int> A(M);
	for (int i = 0; i < M; ++i)
	{
		cin >> A[i];
	}
	int costTo0 = 0;
	int costToN = 0;
	for (int i = X; i <= N; ++i)
	{
		if(find(A.begin(), A.end(),i) != A.end())costToN++;
	}
		for (int i = X; 0 <= i; --i)
	{
		if(find(A.begin(), A.end(),i) != A.end())costTo0++;
	}
	cout << min(costTo0,costToN) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
typedef int  i32;
typedef long long i64,ll;
#define BR "\n"

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

//config
#define MODE_DEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef MODE_DEBUG
#define LINE()    cerr<< " (L" << __LINE__ << ")"
#define LINELN()    LINE()<<endl

#define  DUMP(x)  cerr << #x << " = " << (x) <<endl
#define DEBUG(x) DUMP(x) << " (L" << __LINE__ << ")" << " " << __FILE__<<endl
#define CHECK(exp,act)  if(exp!=act){DUMP(exp);DEBUG(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#else
#define DUMP(x)
#define DEBUG(x)
#define CHECK(exp,act)
#define STOP(e)
#endif

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}
template<class T> inline string toString(const vector<vector<T>>& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}

const int INF=1<<28;
int main(){
	while(true){
		int H,W;cin >> H >> W;
		if(H==0 && W==0)break;
		vector<vector<int> > map(H,vector<int>(W));
		REP(y,H)REP(x,W)cin >>map[y][x];
		int mv=0;
		REP(bit,1<<H){
			int sum=0;
			REP(x,W){
				int sumH=0;
				REP(y,H)
					sumH+=map[y][x]^((bit>>y)&1);
				
				sum+=max(sumH,H-sumH);
			}
			mv=max(sum,mv);
		}
		cout << mv<<endl;
	}

	return 0;
}

Measured memory_bytes: 1592
#include<stdio.h>
main()
{
    char a[100],b[100];
    int i,j,k,l;
    scanf("%s%s",a,b);
    k=strlen(a);
    l=strlen(b);
    if(k==l)
        for(i=0;i<k;i++)
    {
        printf("%c%c",a[i],b[i]);
    }
    else
    {
       for(i=0;i<k;i++)
    {
        if(i==l)
             printf("%c",a[i]);
        else
        printf("%c%c",a[i],b[i]);
    }
    }

    return 0;
}


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

void chmax(int& a, int b){
    a = max(a, b);
}

int main(){
    int H, W;
    cin >> H >> W;
    string S[185];
    for(int i=0; i<H; i++) cin >> S[i];
    int sum[186][186] = {0};
    for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) sum[i][j] = (S[i-1][j-1] == '#');
    for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) sum[i][j] += sum[i-1][j];
    for(int i=1; i<=H; i++) for(int j=1; j<=W; j++) sum[i][j] += sum[i][j-1];

    static int dpX[2][187][187][187], dpY[2][187][187][187];
    for(int x1=1; x1<=H; x1++) for(int x2=x1; x2<=H; x2++) for(int y1=1; y1<=W; y1++){
        int ok = y1-1, ng = W+1;
        while(ng-ok>1){
            int y2 = (ok+ng)/2;
            int a = (x2-x1+1) * (y2-y1+1);
            int s = sum[x2][y2] - sum[x2][y1-1] - sum[x1-1][y2] + sum[x1-1][y1-1];
            ((s == 0 || s == a) ? ok : ng) = y2;
        }
        int y2 = ok;
        chmax(dpX[0][x1][x2][y1], y2);
        chmax(dpY[0][y1][y2][x1], x2);
    }

    for(int t=0; ; t++){
        int p = t%2, np = (t+1)%2;

        for(int d=H-1; d>=1; d--) for(int x1=1; x1+d-1<=H; x1++){
            int x2 = x1+d-1;
            for(int y1=1; y1<=W; y1++){
                chmax(dpX[p][x1][x2][y1], dpX[p][x1-1][x2][y1]);
                chmax(dpX[p][x1][x2][y1], dpX[p][x1][x2+1][y1]);
                chmax(dpX[p][x1][x2][y1], dpX[p][x1][x2][y1-1]);
            }
        }
        for(int d=W-1; d>=1; d--) for(int y1=1; y1+d-1<=W; y1++){
            int y2 = y1+d-1;
            for(int x1=1; x1<=H; x1++){
                chmax(dpY[p][y1][y2][x1], dpY[p][y1-1][y2][x1]);
                chmax(dpY[p][y1][y2][x1], dpY[p][y1][y2+1][x1]);
                chmax(dpY[p][y1][y2][x1], dpY[p][y1][y2][x1-1]);
            }
        }
        if(dpX[p][1][H][1] == W){
            cout << t << endl;
            return 0;
        }

        for(int x1=1; x1<=H; x1++) for(int x2=1; x2<=H; x2++) for(int y1=1; y1<=W; y1++){
            int ym = dpX[p][x1][x2][y1] + 1;
            int y2 = (ym <= W ? dpX[p][x1][x2][ym] : W);
            chmax(dpX[np][x1][x2][y1], y2);
            chmax(dpY[np][y1][y2][x1], x2);
        }
        for(int y1=1; y1<=W; y1++) for(int y2=1; y2<=W; y2++) for(int x1=1; x1<=H; x1++){
            int xm = dpY[p][y1][y2][x1] + 1;
            int x2 = (xm <= H ? dpY[p][y1][y2][xm] : H);
            chmax(dpX[np][x1][x2][y1], y2);
            chmax(dpY[np][y1][y2][x1], x2);
        }
    }
    return 0;
}


Measured memory_bytes: 102400
a = int(input())
b = list(map(int, input().split()))
b.sort()
while True:
    c = []
    c.append(b[0])
    for i in range(1, len(b)):
        if b[i] % b[0] != 0:
            c.append(b[i] % b[0])
    if len(b) == 1:
        print(b[0])
        exit()
    else:
        b = c
        b.sort()


Measured memory_bytes: 14252
#include <stdio.h>
#define MAX 2000000

int main(){
    int i,j,n,max,data;
    
    scanf("%d",&n);
    int B[MAX];
    
    for(i=0;i<MAX;i++){
        B[i]=0;
    }

    max=0;

    for(i=0;i<n;i++){
        scanf("%d",&data);
        B[data]++;
        if(max<data)max=data;
        
    }
    
    
    j=0;
    for(i=0;i<max||j<n;i++){
        while(B[i]>0){
            printf("%d",i);
            j++;
            B[i]--;
            if(j!=n)printf(" ");
        }
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 8416
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    A, B, C, K = map(int, read().split())
    for i in range(K):
        if A>=B:
            B *= 2
        elif B>=C:
            C *= 2
        else:
            break
    if A<B<C:
        print('Yes')
    else:
        print('No')
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 9184
# 2019/07/05
# AtCoder Beginner Contest 061 - C

# Input
n, k = map(int, input().split())
abl = list()
for i in range(n):
    a, b = map(int, input().split())
    abl.append([a, b])

abl.sort()

cnt = 0
idx = 0
# Search k
while cnt < k:
    cnt += abl[idx][1]
    idx += 1

ans = abl[idx - 1][0]

# Output
print(ans)

Measured memory_bytes: 20092
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int count = 0;
        for(int i =1;i <=n;i++ ) {
        	int a = sc.nextInt();
        	if((i%2==1) && (a%2==1)) {
        		count++;
        	}
        }
        System.out.println(count);
    }

}

Measured memory_bytes: 35792
#include <stdio.h>
int main(void){
  int row,column,i,j,rblack[100],cblack[100];
  char matrix[100][100];
  scanf("%d %d",&row,&column);
  for(i=0;i<100;i++){
    rblack[i] = 0;
    cblack[i] = 0;
  }
  for(i=0;i<row;i++){
    for(j=0;j<column;j++){
      scanf(" %c",&matrix[i][j]);
      if(matrix[i][j] == '#'){
        rblack[i] += 1;
        cblack[j] += 1;
      }
    }
  }
  for(i=0;i<row;i++){
    for(j=0;j<column;j++){
      if(rblack[i] != 0 && cblack[j] != 0){
        printf("%c",matrix[i][j]);
      }
    }
    if(rblack != 0){
      printf("\n");
    }
  }
  return 0;
}

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

using namespace std;

using ll = long long;

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(ll n, ll k){
  if (n < k) return 0;
  if (k == 0) return 1;
  if ((n == 0) && (k == 0)) return 1;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  ll n, k;
  cin >> n >> k;
  cin.ignore();

  ll ans;

  for(ll i = 1; i <= k; i++){
    if(n - k >= i - 1){
      ans = COM(n - k + 1, i) * COM(k - 1, i - 1) % MOD;
      cout << ans << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}
  


Measured memory_bytes: 12160
from math import floor
while(True):
    x,y,s=map(int,input().split())
    if (x,y,s)==(0,0,0):
        quit()
    ans=0
    for i in range(1,s):
        j=s-floor(i*(100+x)/100)
        if j<1:
            continue
        j=floor((j+1)*(100/(100+x)))
        for k in [j-1,j]:
            if floor(i*(100+x)/100)+floor(k*(100+x)/100)==s:
                ans=max(ans,floor(i*(100+y)/100)+floor(k*(100+y)/100))
    print(ans)



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

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

    vector<int> dp(2001);
    dp.at(0) = 1;
    dp.at(1) = 0;
    dp.at(2) = 0;

    for (int i = 3; i <= 2000; i++){
        dp.at(i) = dp.at(i-1) + dp.at(i-3);
        dp.at(i) %= 1000000007;
    }

    cout << dp.at(s);

    //
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  
  int res = 0;
  if (a + b == c || a + c == b || b + c == a) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
    
  return 0;
}

Measured memory_bytes: 3640
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String A = sc.nextLine();
    String B = sc.nextLine();
    String C = sc.nextLine();
    String turn = "A";
    
    while(true){
      if(turn.equals("A")){
        if(A.length() == 0){
          break;
        }
        
        char z = A.charAt(0);
        A = A.substring(1, A.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else if(turn.equals("B")){
        if(B.length() == 0){
          break;
        }
        
        char z = B.charAt(0);
        B = B.substring(1, B.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }else{
        if(C.length() == 0){
          break;
        }
        
        char z = C.charAt(0);
        C = C.substring(1, C.length());
        if(z == 'a'){
          turn = "A";
        }else if(z == 'b'){
          turn = "B";
        }else{
          turn = "C";
        }
      }
    }
    System.out.println(turn);
  }
}

Measured memory_bytes: 20688
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n; cin >> n;
  vd p(n);
  rep(i,n) cin >> p[i];

  vvd dp(n+1, vd(n+1, 0));
  dp[0][0] = 1;
  REP(i, 1, n+1) {
    dp[i][0] = dp[i-1][0] * (1.0 - p[i-1]);
    REP(j, 1, n+1) {
      dp[i][j] += dp[i-1][j-1] * p[i-1] + dp[i-1][j] * (1.0 - p[i-1]);
      // cout << dp[i][j] << " \n"[j==n];
    }
  }
  double ans = 0;
  REP(i, (n/2+1), n+1) {
    ans += dp[n][i];
  }
  printf("%.10lf\n", ans);
  return 0;
}


Measured memory_bytes: 70656
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

int main(){
  int n,num,q,b,e,t;
  vector<int> a;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num;
    a.push_back(num);
  }

  cin >> q;
  for (int i = 0; i < q; i++){
    cin >> b;
    cin >> e;
    cin >> t;
    for (int j = 0; j < e - b; j++){
      swap(a[b+j],a[t+j]);
    }
  }
  for (int i = 0; i < n; i++){
    if (i != n - 1){
      cout << a[i] << " ";
    }else{
      cout << a[i] << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3160
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int d[10000];
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int3(n, m, p);
    rep(i, m){
      scanf("%d", &d[i]);
      if(d[i] < p)d[i] += n;
    }
    sort(d, d + m);

    int res = 123456789;
    res = min(res, d[m - 1] - p);
    res = min(res, n - (d[0] - p));

    rep1(i, m){
      res = min(res, d[i - 1] - p + 2 * (n - (d[i] - p)));
      res = min(res, 2 * (d[i - 1] - p) + n - (d[i] - p));
    }
    pri(res * 100);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3220
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if (a%3==0){
		printf("Possible\n");
	}
	else if (b%3==0){
		printf("Possible\n");
	}
	else if ((a+b)%3==0){
		printf("Possible\n");
	}
	else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 128
import static java.lang.Integer.parseInt;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Longest Steps
 */
public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0 0")) {

			int n = parseInt(line.substring(0, line.indexOf(' ')));
			int k = parseInt(line.substring(line.indexOf(' ') + 1));

			boolean[] cards = new boolean[n + 1];
			for (int i = 0; i < k; i++) {
				cards[parseInt(br.readLine())] = true;
			}

			int sum = 0;
			List<Integer> list = new ArrayList<Integer>();
			list.add(0);
			for (int i = 1; i < n + 1; i++) {
				if (cards[i]) {
					sum += 1;
				} else {
					if (sum > 0) {
						list.add(sum);
					}
					list.add(0);
					sum = 0;
				}
			}
			if (sum > 0) {
				list.add(sum);
			}
			list.add(0);

			int max = 0;
			for (int i = 1; i < list.size() - 1; i++) {
				if (cards[0] && list.get(i) == 0) {
					if (list.get(i - 1) + 1 + list.get(i + 1) > max) {
						max = list.get(i - 1) + 1 + list.get(i + 1);
					}
				} else {
					if (list.get(i) > max) {
						max = list.get(i);
					}
				}
			}
			System.out.println(max);
		}

	}
}

Measured memory_bytes: 30344
/**
 *    author:  ykaka
 *    created: 01.08.2020 20:54:48       
**/
 
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i<(n);++i)
using namespace std;
using ll = long long;
 
int main(){
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  rep(i,n){
    ll x, y;
    cin >> x >> y;
    if(x*x + y*y <= d*d) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3600
while True:
    h, w = map(int, input().split())
    if h == 0 and w == 0:
        break
    else:
        for i in range (h):
            if i == 0 or i == h - 1:
                print("#" * w + "\n", end="") 
            else:
                print("#" + ("." * (w - 2)) + "#" + "\n", end="")
        print()


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

int main(){
    string S;
    cin >> S;
    if(S=="SUN")cout << 7 << endl;
    if(S=="MON")cout << 6 << endl;
    if(S=="TUE")cout << 5 << endl;
    if(S=="WED")cout << 4 << endl;
    if(S=="THU")cout <<3 << endl;
    if(S=="FRI")cout << 2 << endl;
    if(S=="SAT")cout <<1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define up(l,r,i) for(int i=l;i<=r;i++)
#define dn(l,r,i) for(int i=l;i>=r;i--)
using namespace std;

typedef long long LL;
const int INF =2147483647;
LL qread(){
	LL w=1,c,ret;
	while((c=getchar())> '9'||c< '0')
	w=(c=='-'?-1:1); ret=c-'0';
	while((c=getchar())>='0'&&c<='9')
	ret=ret*10+c-'0';
	return ret*w;
}
const int MAXN =1e5+3;
LL sum1[MAXN],sum2[MAXN],n,c,ans;
LL A[MAXN],B[MAXN],W1[MAXN],W2[MAXN];
LL pre1[MAXN],pre2[MAXN],scc1[MAXN],scc2[MAXN];
int main(){
	n=qread(),c=qread();
	up(1,n,i) A[i]=qread(),W1[i]=qread();
	up(1,n,i) B[i]=c-A[n-i+1],W2[i]=W1[n-i+1];
	up(1,n,i) sum1[i]=sum1[i-1]+W1[i],sum2[i]=sum2[i-1]+W2[i];
	up(1,n,i) scc1[i]=max(scc1[i-1],sum1[i]-A[i]);
	up(1,n,i) scc2[i]=max(scc2[i-1],sum1[i]-2*A[i]);
	up(1,n,i) pre1[i]=max(pre1[i-1],sum2[i]-B[i]);
	up(1,n,i) pre2[i]=max(pre2[i-1],sum2[i]-2*B[i]);
	ans=max(max(ans,pre1[n]),scc1[n]);
	up(1,n,i) ans=max(ans,pre2[i]+scc1[n-i]);
	up(1,n,i) ans=max(ans,pre1[i]+scc2[n-i]);
//	up(1,n,i) printf("%d %d\n",i,pre2[i]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 8064
n, m = map(int, input().split())

p = list(range(n))


def find(x):
    if p[x] != x:
        p[x] = find(p[x])
    return p[x]


def union(x, y):
    x, y = find(x), find(y)
    p[x] = p[y] = min(x, y)


for _ in range(m):
    x, y, z = [int(i) - 1 for i in input().split()]
    if find(x) != find(y):
        union(x, y)

ans = set()
for i in range(n):
    find(i)
print(len(set(p)))


Measured memory_bytes: 13256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  const int DIGIT = 4;            // 入力の桁数
  const int CONTINUE_LENGTH = 3;  // Good Integerと判定されるための桁数
  int N[DIGIT] = {-1};            // 入力Nを1桁ずつ格納する配列
  
  // 入力Nを受け取って配列に入れる
  int temp = 0;
  cin >> temp;  
  for(int i = 0; i < DIGIT; ++i){
    N[i] = temp % 10;
    temp /= 10;
  }
  
  // 連続性の判定
  for(int i = 0; i <= DIGIT - CONTINUE_LENGTH; ++i){
 
    bool bGood = true;
    for(int j = 1; j < CONTINUE_LENGTH; ++j){
      if(N[i] != N[i + j]){
        bGood = false;
        break;
      }
    }
    
    if(bGood){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
k=int(input())

pole = [A,B,C,D,E]
sw = 0
for i in range(5):
    if sw == 1:
        break
    for j in range(5):
        if pole[i]-pole[j] > k:
            print(":(")
            sw = 1
            break
if sw == 0:
    print("Yay!")

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

#define F first
#define S second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;
ll H, W, N;
vector<ll> fact, finv;
vector<pll> walls;
vector<vector<ll>> dp;

ll modpow(ll a, ll b) {
    ll result = 1;
    for (; b; b /= 2) {
        if (b % 2)
            result = result * a % MOD;
        a = a * a % MOD;
    }
    return result;
}

ll choose(ll n, ll k) {
    return fact[n] * finv[k] % MOD * finv[n - k] % MOD;
}

ll ways(int i, int j) {
    ll dr = walls[j].F - walls[i].F;
    ll dc = walls[j].S - walls[i].S;
    return dr < 0 || dc < 0 ? 0 : choose(dr + dc, dc);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> H >> W >> N;

    fact = {1};
    finv = {1};
    for (ll n = 1; n <= H + W - 2; n++) {
        fact.push_back(fact.back() * n % MOD);
        finv.push_back(modpow(fact.back(), MOD - 2));
    }

    walls.resize(N);
    for (int i = 0; i < N; i++)
        cin >> walls[i].F >> walls[i].S;
    walls.push_back({1, 1});
    walls.push_back({H, W});
    sort(walls.begin(), walls.end());

    int n = walls.size();
    dp.assign(n, vector<ll>(n));
    for (int j = 1; j < n; j++) {
        dp[0][j] = ways(0, j);
        for (int i = 1; i < j; i++) {
            dp[0][j] -= dp[0][i] * ways(i, j) % MOD;
            if (dp[0][j] < 0)
                dp[0][j] += MOD;
        }
    }
    cout << dp[0][n - 1] << endl;
}


Measured memory_bytes: 75072
import math

def f(a , x):
  ans = 0
  for i in range(len(x)):
    ans += (a - x[i]) ** 2
  return ans

n = int(input())
x = list(map(int, input().split()))
a = sum(x) / n
ans = min(f(math.floor(a) , x), f(math.ceil(a) , x))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll cal(ll k,ll n) {
    if(n<k) return n;
    if(n%k==0) return cal(k,n/k);
    return n%k;
}
int main() {
    //freopen("in.txt","r",stdin);
    ll n,m,ans=0;
    scanf("%lld",&n),m=n-1;
    for(ll i=1;i*i<=m;i++) {
        if(m%i==0) {
            ans++;
            if(i*i!=m) ans++;
        }
    }
    for(ll i=2;i*i<=n;i++) {
        if(n%i==0) {
            ans+=(cal(i,n)==1);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

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

ll single(ll X){
  if(X&1){return ((X+1)/2)&1;}
  else{return ((X/2)&1)^X;}
}

int main(){
  ll A,B;cin>>A>>B;
  if (A==0){cout << single(B) << endl;}
  else{
    ll ans=single(A-1)^single(B);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,m,M[100];
char N[100][9],B[9];
main(){
	int i,j,k,h,s;
	for(;scanf("%d%d",&n,&m),n;){
		for(i=0;i<n;i++)
			scanf("%s%d",N[i],M+i);
		s=0;
		for(i=0;i<m;i++){
			scanf("%s",B);
			for(j=0;j<n;j++){
				h=1;
				for(k=0;k<8;k++){
					if(N[j][k]!='*'&&N[j][k]!=B[k])
						h=0;
				}
				if(h)
					s+=M[j];
			}
		}
		printf("%d\n",s);
	}
	exit(0);
}

Measured memory_bytes: 0
N = int(input())
# 初期状態
T = [0]
X = [0]
Y = [0]
for i in range(N):
    t, x, y = map(int, input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

# パリティに着目せよ
count = 0
for i in range(N):
    distanceSum = abs(X[i+1]-X[i]) + abs(Y[i+1]-Y[i])
    T_parity = (T[i+1]-T[i]) % 2
    Distance_parity = distanceSum % 2
    if distanceSum <= (T[i+1]-T[i]) and T_parity == Distance_parity:
        count += 1

if count == N:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11732
S = input() + '#'
n = len(S)
for idx, s1 in enumerate(S[:-2], 1):
    s2 = S[idx]
    s3 = S[idx+1]
    if s1 == s2:
        print(idx, idx+1)
        exit()
    elif s1 == s3:
        print(idx, idx+2)
        exit()
    elif s2 == s3:
        print(idx+1, idx+2)
        exit()
    else:
        continue
print(-1, -1)

Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//dp注意点
//問題の種類	 初期化する値	 備考
//最小化問題 	INF	
//最大化問題	    -INF	 テーブル全体で 00 以上の値しかとらないことがわかっていれば −1−1 でもいいですし、00 でもいい場合もあります
//数え上げ問題	00	
//確率問題	      00	
//Yes/No 判定問題	False
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}

Measured memory_bytes: 3648
package main

import "fmt"

func main() {
	var K int
	fmt.Scan(&K)
	qs := make([]int, 0)
	for i := 1; i <= 9; i++ {
		qs = append(qs, i)
	}
	count := 0
	for len(qs) > 0 {
		count++
		q := qs[0]
		qs = qs[1:]
		if count == K {
			fmt.Println(q)
			return
		}
		if q%10 != 0 {
			qs = append(qs, 10*q+(q%10)-1)
		}
		qs = append(qs, 10*q+(q%10))
		if q%10 != 9 {
			qs = append(qs, 10*q+(q%10)+1)
		}
	}
}


Measured memory_bytes: 8320
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int tx[] = {0,1,1,1,0,-1,-1,-1};
const static int ty[] = {-1,-1,0,1,1,1,0,-1};
 
static const double EPS = 1e-8;

int gPos = 0;

void parse_CAT(const string& str){
  if(gPos >= str.size()) return;

  if(gPos < str.size() && str[gPos++] != 'm'){
    gPos--;
    return;
  }
  parse_CAT(str);
  if(gPos < str.size() && str[gPos++] != 'e'){
    gPos--;
    return;
  }

  parse_CAT(str);
  if(gPos < str.size() && str[gPos++] != 'w'){
    gPos--;
    return;
  }

  return;
}

int main(){
  string str;
  while(cin >> str){
    gPos = 0;
    parse_CAT(str);
    printf("%s\n",(gPos != str.size()) ? "Rabbit" : "Cat");
  }
}

Measured memory_bytes: 1160