akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*
 *  JUST KEEP GOING
 */
#define endl			'\n'
#define ll				long long
#define all(v)			((v).begin()), ((v).end())
#define allr(v)			((v).rbegin()), ((v).rend())
#define sz(v)			((int)((v).size()))
#define clr(v, d)		memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define For(i,s)        for(auto i:s)
#define Forr(i,s)        for(auto &i:s)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define vi				vector <int>
#define vl				vector <ll>
#define ii				pair <int,int>
#define vii				vector <ii>
#define vll				vector <pair<ll,ll>>
#define PI				double PPPPPP = 3.14159265358979323846;
#define bit(mask,i) ((mask>>i)&1)

void run() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
}
const int N = 3000+5,mod=1e9+7;
int r,c,k;

ll dp[N][N][5],arr[N][N];
ll solve(int i,int j,int cnt){
    if(i>=r || j>=c){
        return -1e17;
    }
    if(i==r-1 && j==c-1){
        return (cnt<3?arr[i][j]:0);
    }
    ll &ret=dp[i][j][cnt];
    if(~ret)
        return ret;
    ret=0;
    if(cnt<3) {
        ret = max(ret, solve(i, j + 1, cnt + 1) + arr[i][j]);
        ret = max(ret, solve(i + 1, j, 0) + arr[i][j]);
    }
    ret = max(ret,solve(i+1,j,0));
    ret=max(ret,solve(i,j+1,cnt));
    return ret;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    run();
    cin>>r>>c>>k;
    for (int i = 0; i < k; ++i) {
        int a, b, v;
        cin >> a >> b >> v;
        arr[a - 1][b - 1] = v;
    }
    clr(dp,-1);
    cout<<solve(0,0,0)<<endl;
}


Measured memory_bytes: 427400
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int maxn = 1e2 + 10 , N = 1e4 + 10 ; 

int n , ar [ maxn ] , dp [ N ] ; 

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n ;
	for ( int i = 1 ; i <= n ; ++ i )
		cin >> ar [ i ] ;
	dp [ 0 ] = 1 ;
	for ( int i = 1 ; i <= n ; ++ i ) {
		for ( int j = N - 1 ; j >= ar [ i ] ; j -- )
			dp [ j ] |= dp [ j - ar [ i ] ] ; 
	}
	int res = 0 ; 
	for ( int want = 0 ; want < N ; ++ want )
		if ( want % 10 && dp [ want ] )
			smax ( res , want ) ;
	cout << res << '\n' ; 
}


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

int main( )
{
    int n;
    long long int mod = 1000000007, ans = 1, i;
    cin >> n;
    for (i = 1; i <= n; i++) {
        ans = (ans * i) % mod;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 9999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
vector<lli> divisor(lli N){
  vector<lli>res;
  for(lli i=1;i*i<=N;i++){
    if(N%i==0){
      res.push_back(i);
      if(i!=N/i)res.push_back(N/i);
    }
  }
  Sort(res);
  return res;
}
lli modpow(lli n,lli k,lli m){
  if(k==0)return 1;
  else if(k%2==1)return modpow(n,k-1,m)*n%m;
  else{
    lli temp=modpow(n,k/2,m);
    return temp*temp%m;
  }
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> K;
  Vec(dp,lli,K,0);//dp[i]:=gcd{A_i}=i+1となる場合の数mod1e9+7
  rrep(i,K,0){
    num=K/(i+1);
    dp[i]+=modpow(num,N,mod);
    dp[i]=(dp[i]+mod)%mod;
    for(auto v:divisor(i+1)){
      if(v!=i+1)dp[v-1]-=dp[i];
      dp[v-1]=(dp[v-1]+mod)%mod;
    }
    sum+=dp[i]*(i+1);
    sum%=mod;
  }
  Out(sum);
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int R=in(),C=in();
	vector<vector<int>> T(R+1,vector<int>(C+1,0));

	REP(i,R){
		int sum = 0;
		REP(j,C){
			T[i][j]=in();
			sum += T[i][j];
		}
		T[i][C] = sum;
	}
	REP(i,C+1){
		int sum = 0;
		REP(j,R){
			sum += T[j][i];
		}
		T[R][i] = sum;
	}

	REP(i,R+1){
		REP(j,C){
			cout << T[i][j] << ' ';
		}
		out(T[i][C]);
	}
	return 0;
}



Measured memory_bytes: 3172
using System;

class plogram
{
    static void Main()
    {
        var line = new int[6];
        for(var i =0;i<6;i++)
        {
            line[i] = int.Parse(Console.ReadLine());
        }

        string str = "Yay!";
        for (var i = 0; i < 5; i++)
        {
            for (var j = 0; j < 5; j++)
            {
                if (Math.Abs(line[i] - line[j]) > line[5])
                {
                    str = ":(";
                }
            }
        }
        Console.WriteLine(str);
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(1){
        int n,m;
        cin >> n >> m;
        if(n == 0 && m == 0){
            break;
        }
        vvi vec(n,vi(m));
        string s;
        rep(i,n){
            cin >> s;
            rep(j,m){
                vec[i][j] = s[j]-'0';
            }
        }
        int ans = 0;
        if(n <= 18){
            rep(i,(1 << n)){
                vi v(m,0);
                rep(j,n){
                    if((i >> j)&1){
                        rep(k,m){
                            v[k] ^= vec[j][k];
                        }
                    }
                }
                bool flag = true;
                rep(j,m){
                    if(v[j] != 0){
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    cmx(ans,__builtin_popcount(i));
                }
            }
            cout << ans << "\n";
        }else{
            vl val(n);
            rep(i,n){
                // svec(vec[i]);
                rep(j,m){
                    val[i] += ((ll)vec[i][j] << j);
                }
            }
            // svec(val);
            map<ll,int> mp;
            mp[0] = 0;
            rep(i,n){
                map<ll,int> mp2;
                each(it,mp){
                    mp2[it.fi] = max(mp[it.fi],mp2[it.fi]);
                    mp2[it.fi^val[i]] = max(it.se+1,mp2[it.fi^val[i]]);
                }
                mp = mp2;
            }
            cout << mp[0] << "\n";
        }
    }
    return 0;
}



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

using namespace std;
typedef long long ll;

int n;
string s, ans = "-1";

char rev(char c) {
  return c == 'S' ? 'W' : 'S';
}

void f(string t) {
  string w = s;
  w[0] = t[0];
  w[1] = t[1];
  for (int i = 1; i < n - 1; i++) {
    if (w[i] == 'S') {
      if (s[i] == 'o') w[i + 1] = w[i - 1];
      else w[i + 1] = rev(w[i - 1]);
    } else {
      if (s[i] == 'o') w[i + 1] = rev(w[i - 1]);
      else w[i + 1] = w[i - 1];
    }
  }
  
  bool ok = true;
  for (int i = 0; i < n; i++) {
    int l = (i - 1 + n) % n, r = (i + 1) % n;
    if (w[i] == 'S') {
      if (s[i] == 'o' && w[l] != w[r]) ok = false;
      if (s[i] == 'x' && w[l] == w[r]) ok = false;
    } else {
      if (s[i] == 'o' && w[l] == w[r]) ok = false;
      if (s[i] == 'x' && w[l] != w[r]) ok = false;
    }
  }
  if (ok) ans = w;
}

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

  f("SS");
  f("SW");
  f("WS");
  f("WW");
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var r, c int
	fmt.Scan(&r, &c)
	// fmt.Println("r", r, "c", c)
	grid := make([][]int, r)
	for i := range grid {
		grid[i] = make([]int, c)
		for j := range grid[i] {
			fmt.Scan(&grid[i][j])
		}
	}
	// fmt.Println(grid)
	for i := 0; i < len(grid); i++ {
		rsum := 0
		for j := 0; j < len(grid[i]); j++ {
			fmt.Print(grid[i][j], " ")
			rsum += grid[i][j]
		}
		fmt.Println(rsum)
	}
	tsum := 0
	for j := 0; j < c; j++ {
		csum := 0
		for i := 0; i < r; i++ {
			csum += grid[i][j]
		}
		if j > 0 {
			fmt.Print(" ")
		}
		tsum += csum
		fmt.Print(csum)
	}
	fmt.Print(" ", tsum)
	fmt.Println()
}



Measured memory_bytes: 1816
import java.io.*;
import java.util.*;
import java.math.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	String s = sc.next();
      
      	int res = 0;
        	
      	char[] c = s.toCharArray();
      	int left = 0;
      	int right = c.length-1;
      	while ( left < right ){
        	if ( c[left] != c[right] ){
            	res++;
            }
         	left++;
          	right--;
        }
      	System.out.println( res );
      	
    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>
#include <tuple>

using namespace std;

//最大公約数
template<class T>
inline T GCD(T m, T n)
{
	T temp;
	while (m % n != 0)
	{
		temp = n;
		n = m % n;
		m = temp;
	}
	return n;
}

//最小公倍数
template<class T>
inline T LCM(T m, T n)
{
	return m * n / GCD(m, n);
}

int main()
{
	int n, k; cin >> n >> k;
	cout << (n%k ==0 ? 0 : 1) << endl;
	return 0;
}

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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  
  if(2 * K > (N - 1) * (N - 2)){
    cout << -1 << endl;
  }else{
    int m = (N - 1) * (N - 2) / 2 - K;
    cout << N - 1 + m << endl;
    
    for(int v = 1; v < N; v++) cout << N << ' ' << v << endl;
    
    for(int u = 1; m && u < N - 1; u++){
      for(int v = u + 1; m && v < N; v++){
        cout << u << ' ' << v << endl;
        m--;
      }
    }
  }
  
  return 0;
}

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

int main()
{
  int n;
  std::cin >> n;
  std::vector<std::pair<int, int>> data;
  for (int i = 0; i < n; i++){
    int l , r;
    std::cin>> l >> r;
    data.push_back(std::make_pair(l, r));
  }

  std::vector<std::vector<int>> dp(n+1, std::vector<int>(n+1, 0));
  for (int w = 2; w <= n; w++){
    for (int l = 0; l < n; l++){
      int r = l+w;
      if(r>n)continue;
      dp[l][r] = 100000000;
      for (int mid = l+1; mid < r; mid++){
        dp[l][r] = std::min(dp[l][r], dp[l][mid] + dp[mid][r] + data[l].first*data[mid].first*data[r-1].second);
      }
    }
  }
  std::cout << dp[0][n] << std::endl;
}



Measured memory_bytes: 3188
import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [a, b, k] <- readInts
  print $ solve a b k

solve :: Int -> Int -> Int -> Int
solve a b k = reverse (filter (\x -> ((a `mod` x) == 0) && ((b `mod` x) == 0)) [1 .. n]) !! (k - 1)
  where
    n = max a b

-- 以下ライブラリ

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

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

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

int main()
{
	string strInput, strFind;
	int nSum = 0;
	cin >> strFind;
	for (int i = 0; i != strFind.length(); ++i)
	{
		strFind[i] = tolower(strFind[i]);
	}
	while (cin >> strInput, "END_OF_TEXT" != strInput)
	{
		for (int i = 0; i != strInput.length(); ++i)
		{
			strInput[i] = tolower(strInput[i]);
		}
		if (strFind == strInput)
		{
			++nSum;
		}
	}
	cout << nSum << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 3156
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
	int h,w;
	cin >> h >> w;
    int x[8] = {-1,0,1,-1,1,-1,0,1};
    int y[8] = {-1,-1,-1,0,0,1,1,1};
    
	char s[100][100];

	rep(i,0,h+2)rep(j,0,w+2)s[i][j] = '.';

	rep(i,1,h+1)rep(j,1,w+1)cin >> s[i][j];

	rep(i,1,h+1){
	    rep(j,1,w+1){
	        if(s[i][j] == '.'){
	        int cnt = 0;
            rep(k,0,8){
                if(s[i+x[k]][j+y[k]] == '#' )cnt++;
            }
            cout << cnt;
            }else cout <<"#";
	    }
	    cout << endl;
    }
    
	return  0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
bool check(vector<ll> &a,vector<ll> &b){
    ll n=a.size();
    for(ll i=0;i<n;i++){
        if(a[i]!=b[i])
            return false;
    }
    return true;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,count=1,x;
    cin>>n;
    vector<ll> arr;
    vector<pair<vector<ll>,ll> >v;
    for(i=1;i<=n;i++)
        arr.push_back(i);
    do{
        v.push_back(make_pair(arr,count));
        count+=1;
    }while(next_permutation(arr.begin(),arr.end()));
    vector<ll> arr1,arr2;
    ll first,second;
    for(i=0;i<n;i++){
        cin>>x;
        arr1.push_back(x);
    }
    for(i=0;i<n;i++){
        cin>>x;
        arr2.push_back(x);
    }
    n=v.size();
    for(i=0;i<n;i++){
        vector<ll> temp=v[i].first;
        if(check(temp,arr1))
            first=v[i].second;
        if(check(temp,arr2))
            second=v[i].second;
    }
    cout<<abs(first-second)<<endl;
    return 0;
}


Measured memory_bytes: 4852
e=(0..gets.to_i).map{[]}
i=0
a=$<.map{|s|s.split.map{|v|e[v.to_i]+=[i]}
!i+=1}
e.map{|e|i=0
u={}
e.reject{|j|u[x=a[j]]=x}.map{|j|0while u[a[j]=i+=1]}}
p a.max,*a

Measured memory_bytes: 167140
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  cout << a[distance(a.begin(), min_element(a.begin(), a.end()))] << " "
       << a[distance(a.begin(), max_element(a.begin(), a.end()))] << " "
       << accumulate(a.begin(), a.end(), 0L) << endl;
  return 0;
}



Measured memory_bytes: 3164
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
	ll n,k,sum=0,ar[100];
	cin>>n>>k;
	for(ll i=0;i<n;i++){
		cin>>ar[i];
	}
	ll dif=n-k;
	sort(ar,ar+n);
	for(ll i=dif;i<n;i++) sum+=ar[i];
	cout<<sum<<endl;
	return 0;
}

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

int	main()
{
	int	N, M, X;
	int	A[12][12];
	cin >> N >> M >> X;
	int	C[12];
	for (int i = 0; i < N; ++i) {
		cin >> C[i];
		for (int j = 0; j < M; ++j)
			cin >> A[i][j];
	}
	int	min_cost = -1;
	for (int i = 0; i < (1 << N); ++i) {
		bitset<12>	bs(i);
		bool		is_ok = true;
		for (int j = 0; j < M; ++j) {
			int	score = 0;
			for (int k = 0; k < N; ++k) {
				if (!bs.test(k)) continue;
				score += A[k][j];
			}
			if (score < X) {
				is_ok = false;
			}
		}
		if (!is_ok) continue;
		int	cost = 0;
		for (int k = 0; k < N; ++k) {
			if (!bs.test(k)) continue;
			cost += C[k];
		}
		if (min_cost == -1 || min_cost > cost)
			min_cost = cost;
	}
	cout << min_cost << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <atcoder/all>
using namespace std;
using namespace atcoder;


int main(void) {
    
    int n, m;
    cin >> n >> m;

    dsu z = dsu(n);
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        z.merge(a-1, b-1);
    }
    vector<vector<int>> vv = z.groups();
    int ans = vv.size() - 1;
    cout << ans << endl;
}



Measured memory_bytes: 8948
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	char op;
	int a,b;
	while(1)
	{
		cin>>a>>op>>b;
		if(op=='?')
		break;
		if(op=='+')
		{
		cout<<a+b<<endl;
		}
		if(op=='-')
		{
		cout<<a-b<<endl;
		}
		if(op=='*')
		{
		cout<<a*b<<endl;
		}
		if(op=='/')
		{
		cout<<a/b<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3076
N, M = map(int, input().split())
a = set([int(input()) for _ in range(M)])
INF = 1000000007

dp = [0] * (N + 1)
dp[0] = 1
if 1 not in a:
	dp[1] = 1
else:
	dp[1] = 0
for i in range(2, N + 1):
	if i in a:
		continue
	dp[i] = dp[i - 1] + dp[i - 2]
	dp[i] %= INF

print(dp[N])

Measured memory_bytes: 56664
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    string s,t;
    cin>>s>>t;
    int a[26],b[26];
    for(int i=0;i<26;i++){
        a[i]=-1;
        b[i]=-1;
    }
    bool ok=true;
    for(int i=0;i<s.size();i++){
        int p=s[i]-'a';
        int q=t[i]-'a';
        if(a[p]>=0){
            if(a[p]!=q){
                ok=false;
                break;
            }
        }
        if(b[q]>=0){
            if(b[q]!=p){
                ok=false;
                break;
            }
        }
        if(a[p]<0){
            a[p]=q;
        }
        if(b[q]<0){
            b[q]=p;
        }
    }
    if(ok){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
 return 0;   
}

Measured memory_bytes: 776
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <iomanip>
#define RG register

using namespace std;

inline int gi(){
	RG char ch=getchar();RG int x=0;
	while(ch<'0' || ch>'9') ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return x;
}

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if ((a*100+b*10+c)%4==0) cout<<"YES";
	else cout<<"NO";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int64 long long int
#define uint64 unsigned long long int
using namespace std;


const int N = 100005;
int n, DS[N], SZ[N];
int64 ans, cnt;
vector <pair<int,int>> vx, vy;
vector <struct Edge> D;

struct Edge {
	int64 c;
	int x;
	int y;
};

int root (int i)
{
	while (DS[i] != i)
		i = DS[DS[i]];
	return i;
}

int merge (int x, int y)
{
	int r = root (x);
	int rr = root (y);
	if (r == rr) return 0;
	if (SZ[r] < SZ[rr]) {
		DS[r] = rr;
		SZ[rr] += SZ[r];
	} else {
		DS[rr] = r;
		SZ[r] += SZ[rr];
	}
	return 1;
}
bool cmp (struct Edge A, struct Edge B)
{
	return A.c < B.c;
}
int main ()
{
	scanf ("%d", &n);
	for (int i = 0; i <= n + 1; i++) DS[i] = i, SZ[i] = 1;
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf ("%d %d", &x, &y);
		vx.pb ({x, i + 1});
		vy.pb ({y, i + 1});
	}
	sort (vx.begin (), vx.end ());
	sort (vy.begin (), vy.end ());
	for (int i = 0; i < vx.size () - 1; i++) {
		struct Edge E;
		E.c = vx[i + 1].first - vx[i].first;
		E.x = vx[i].second;
		E.y = vx[i + 1].second;
		D.pb (E);
	}
	for (int i = 0; i < vy.size () - 1; i++) {
		struct Edge E;
		E.c = vy[i + 1].first - vy[i].first;
		E.x = vy[i].second;
		E.y = vy[i + 1].second;
		D.pb (E);
	}
	sort (D.begin (), D.end (), cmp);
	for (auto p : D) {
		int64 c = p.c;
		int x = p.x, y = p.y;
		if (merge (x, y)) {
			cnt++;
			ans += c;
		}
		if (cnt == n - 1) break;
	}
	printf ("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 8680
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <queue>
#include <stack>
#include <stdlib.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#include <math.h>
#include <bits/stdc++.h>
using namespace std;
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}
long comb(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
using namespace std;

int main(){
   int n;
   std::cin >> n;
   std::vector<int> a(n);
   rep(i,n)std::cin >> a[i];
   sort(a.begin(),a.end());
   rep(i,n-1){
       if(a[i]==a[i+1]){
           std::cout << "NO" << std::endl;
           return 0;
       }
   }
   std::cout << "YES" << std::endl;
   
}





Measured memory_bytes: 1024
// ex3_4
//TKC001
#include<stdio.h>
 
int main(void){
    int N;
    //YN=1ならYes,0ならNo
    int yn = 0;
 
    scanf("%d", &N);
 
    for (int i = 9; i > 0; i--)
    {
        if(N/i<=9 && N/i>=1 && N%i==0){
            yn = 1;
            break;
        }
    }
 
    if(yn==1){
        printf("Yes");
    }else{
        printf("No");
    }
 
    return 0;
    
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main(void){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=0; i<n; i++){
        int a; cin >> a;
        if( (i+1)%2 == 1 && a % 2 == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stdexcept>
#include<cmath>
#include<fstream>
#include<memory>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define S second
#define pb push_back
#define pf push_front
#define LIM 100000
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef long long ll;
typedef unsigned long long ull;
const int dx[] = {0,1,0,-1};
const int dy[] = {1,0,-1,0};
char cmap[55][55];
bool used[55][55];
int w,h,cost;
bool OH_GOD;

void input(){

 rep(i,h){
      string s;
      cin >> s;
      rep(j,s.length()){
	cmap[i][j] = s[j];
	used[i][j] = false;
      }
    }

}

void ok(int x,int y,char key){
  used[y][x] = true;
  cost++;
  rep(i,4){
    int nx = x+dx[i],ny = y+dy[i];
    if(!(0<=nx && nx <w && 0<=ny &&ny<h))continue;
    if(used[ny][nx] || cmap[ny][nx] == key)continue;
    if(cmap[ny][nx] != '.' && cmap[ny][nx] != key){
      OH_GOD = false;
      continue;
    }
    ok(nx,ny,key);
  }
}

int main(){

 
  while(true){
    cin >> w >> h;
    if(w + h == 0)break;
    input();
    
    int w_cnt,b_cnt;
    w_cnt = b_cnt = 0;
    rep(i,h){
      rep(j,w){
	if(used[i][j] || cmap[i][j] == '.')continue;
	rep(k,4){
	  cost = 0;
	  OH_GOD = true;
	  if(!(0<= j+dx[k] && j+dx[k] < w && 0 <= i+dy[k] && i+dy[k] < h))continue;
	  if(cmap[i+dy[k]][j+dx[k]] == 'W' || cmap[i+dy[k]][j+dx[k]] == 'B')continue;
	  if(used[i+dy[k]][j+dx[k]])continue;
	  
	  ok(j+dx[k],i+dy[k],cmap[i][j]);
	  
	  if(OH_GOD){
	    cmap[i][j] == 'W'?w_cnt += cost:b_cnt += cost;
	  }
	}
	used[i][j] = true;
      }
    }
    cout << b_cnt << " " << w_cnt << endl;


  }
return 0;
}

Measured memory_bytes: 1260
package main

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

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	X := sc.i()
	sum := 1000 * (X / 500)
	X = X % 500
	sum += 5 * (X / 5)
	fmt.Println(sum)
}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

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

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

func abs(i int) int {
	if i < 0 {
		return -i
	}
	return i
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}

// vs: sorted slice int value
func lowerBound(vs []int, v int) (index int) {
	n := len(vs) / 2
	m := len(vs)
	for m != n {
		if vs[n] < v {
			n = (m-n+1)/2 + n
			//m = m
		} else {
			m = n
			n = n / 2
		}
	}
	return n
}

func IntSlice(n, init int) []int {
	r := make([]int, n)
	for i := range r {
		r[i] = init
	}
	return r
}


Measured memory_bytes: 1772
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define MAX(a, b, c) max(max(a, b), c)
using namespace std;

int main(){
  int a,b;
  scanf("%d%d", &a, &b);
  
  if(a >= 13) cout << b << endl;
  else if (a <= 5) cout << 0 << endl;
  else cout << b/2 << endl;
}

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

using namespace std;

typedef long long llint;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  llint ans = 0, b = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'B') {
      b++;
    } else {
      ans += b;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 640
# /usr/bin/python
# -*- coding: utf-8 -*-
import math



def nine(n):
  ret = 0
  for r in range(6,0,-1):
    p,n = divmod(n,9**r)
    ret += p
  return ret+n

def six(n):
  ret = 0
  for r in range(7,0,-1):
    p,n = divmod(n,6**r)
    ret += p
  return ret+n



if __name__ == "__main__":
  N = int(input())
  ans = [N for _ in range(N+1)]
  for l in range(N+1):
    ans[l] = nine(l)+six(N-l)
  print(min(ans))

Measured memory_bytes: 44784
using System;

public class Program
{
    public static void Main()
	{
        var input = Console.ReadLine().ToCharArray();
        Array.Reverse(input);
        var S = new string(input);

        var divs = new string[] {"dream", "dreamer", "erase", "eraser"};
        for (var i=0; i<divs.Length; i++)
        {
            var chars = divs[i].ToCharArray();
            Array.Reverse(chars);
            divs[i] = new string(chars);
        }

        var can = true;

        for (var i=0; i<S.Length; )
        {
            var can2 = false;
            foreach (var div in divs)
            {
                if (i + div.Length > S.Length)
                {
                    continue;
                }
                if (S.Substring(i, div.Length) == div)
                {
                    can2 = true;
                    i += div.Length;
                    break;
                }
            }
            if (!can2)
            {
                can = false;
                break;
            }
        }
        Console.WriteLine(can ? "YES" : "NO");
    }
}


Measured memory_bytes: 13664
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <map>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 90001

using namespace std;

ll m, a, r, c, h;

ll max(ll a, ll b)
{
	return a > b ? a : b;
}

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int N; cin >> N;
	while (N--)
	{
		string temp; cin >> temp;
		char t = temp[0];
		switch (t)
		{
		case 'M':
			m += 1;
			break;
		case 'A':
			a += 1;
			break;
		case 'R':
			r += 1;
			break;
		case 'C':
			c += 1;
			break;
		case 'H':
			h += 1;
		}
	}
	if (m + a + r + c + h < 3)
	{
		cout << 0;
		return 0;
	}
	ll ret = 0;
	ll arr[5] = { m, a, r, c, h };
	for (int i = 0; i < 5; i++)
	{
		for (int j = i + 1; j < 5; j++)
		{
			for (int k = j + 1; k < 5; k++)
			{
				ret += arr[i] * arr[j] * arr[k];
			}
		}
	}

	cout << ret << endl;
	return 0;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(0),cin.tie(0)
#define vi vector<int> vi;
typedef long long ll;


int main(){
	IOS;
	string in;
	cin>>in;
	if(in[2] == in[3] && in[4] == in[5])
		cout<<"Yes\n";
	else
		cout<<"No\n";
		
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define MIN -1000
#define MAX 1000

int find(long long target) {
	int l = MIN;
	int r = MAX;
	while (l <= r) {
		long long mid = (l + r) / 2;
		long long f = mid * mid * mid * mid * mid;
		if (target < f) {
			r = mid - 1;
		}
		else if (target > f) {
			l = mid + 1;
		}
		else {
			return mid;
		}
	}
	return 10000;
}

int main() {
	long long x;
	vector<long long> v;
	cin >> x;
	
	for (long long i = MIN; i <= MAX; i++) {
		long long b = i * i * i * i * i;
		int a = find(x + b);
		if (find(x + b) != 10000) {
			cout << a << ' ' << i << endl;
			break;
		}
	}

	return 0;
}

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

int main() {
  int d,g;
  cin >> d >> g;
  vector<int> num(d), point(d);
  for (int i=0;i<d;i++) {
    cin >> num.at(i) >> point.at(i);
  }
  
  int ans=1e9;
  for (int check=0; check < (1 << d); check++) {
    int sum=0, count=0, rest=-1;
    for (int i=0;i<d;i++) {
      if(check >> i & 1) {
        sum+=100*(i+1)*num.at(i)+point.at(i);
        count+=num.at(i);
      }
      else {
        rest=i;
      }
    }
    if(sum<g) {
      int temp=100*(rest+1);
      int need=(g-sum+temp-1)/temp;
      if(need >= num.at(rest)) {
        continue;
      }
      count+=need;
    }
    ans=min(ans,count);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    using P = pair<int, int>;

    int N, T;
    cin >> N >> T;
    vector<P> A(N);
    cin >> A;

    sort(ALL(A));
    vector<vector<int>> dp(N + 1, vector<int>(T, 0));

    int ans = 0;
    REP(i, N) {
        REP(t, T) {
            chmax(dp[i + 1][t], dp[i][t]);
            int k = t + A[i].first;
            if (k < T) { chmax(dp[i + 1][k], dp[i][t] + A[i].second); }
        }
        int now = dp[i][T - 1] + A[i].second;
        chmax(ans, now);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    int x;
    cin>>a>>b>>c>>d;
    if(a<=c){
        if(b<c) x=0;
        else if(b<=d) x=b-c;
        else x=d-c;
    }
    else if(a>c){
        if(d<a) x=0;
        else if(b>=d) x=d-a;
        else x=b-a;
    }
    cout<<x<<endl;
    return 0;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if(S.at(K - 1) == 'A') S.at(K - 1) = 'a';
  if(S.at(K - 1) == 'B') S.at(K - 1) = 'b';
  if(S.at(K - 1) == 'C') S.at(K - 1) = 'c';
  cout << S << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<random>
#include<ctime>
#include<cstdlib>
#include<unordered_map>
#include<string.h>
#include<iostream>
#define p pair<int,int>
#define P pair<int,p>
using namespace std;

int d[202];
vector<P>V;
int k[10][10];
signed main() {
	int a, b; cin >> a >> b;
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			cin >> k[i][j];
		}
	}
	for (int i = 0; i < 100; i++) {
		V.push_back({ -1,{i,i + 1} });
	}
	for (int i = 0; i < 100; i++) {
		V.push_back({ -2,{ 101+i,i + 102 } });
	}
	for (int i = 0; i <= 100; i++) {
		for (int j = 101; j <= 201; j++) {
			int MAX = 0;//余裕の最大値
			for (int k = 0; k < a; k++) {
				for (int l = 0; l < b; l++) {
					MAX = max(MAX, ::k[k][l] - i*(k + 1) - (201 - j)*(l + 1));
				}
			}
			V.push_back({ MAX,{i,j} });
		}
	}
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			memset(d, 0x3f, sizeof(d));
			d[0] = 0;
			priority_queue<p>Q;
			Q.push({0,0});
			while (Q.size()) {
				p t = Q.top(); Q.pop();
				if (d[t.second] < t.first)continue;
				for (P u : V) {
					if (u.second.first == t.second) {
						int h = 0;
						if (u.first >= 0) {
							h = u.first;
						}
						else if (u.first == -1) {
							h = i + 1;
						}
						else { h = j + 1; }
						if (d[u.second.second] > t.first + h) {
							d[u.second.second] = t.first + h;
							Q.push({t.first+h,u.second.second });
						}
					}
				}
			}
			if (d[201] != k[i][j]) {
				puts("Impossible");
				return 0;
			}
		}
	}
	puts("Possible");
	cout << 202 << " " << V.size()<< endl;
	for (P i : V) {
		if (i.first == -1) {
			cout << i.second.first + 1 << " " << i.second.second + 1 << " X" << endl;
		}
		else if (i.first == -2) {
			cout << i.second.first + 1 << " " << i.second.second + 1 << " Y" <<endl;
		}
		else {
			cout << i.second.first + 1 << " " << i.second.second + 1 << " " << i.first<< endl;
		}
	}
	cout << 1 << " " << 202 << endl;
}

Measured memory_bytes: 576
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcountll
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int n, k;
int arr[200005];
int fun(int num, int mx){
//    if(num <= mx){
//        return 0;
//    }
//    return 1 + fun(num-mx, mx);
    
    if(num % mx != 0){
        return num/mx;
    }else{
        return (num-1)/mx;
    }
}
bool check(int mx){
    int mvs = 0;
    for(int i=0; n>i; i++){
        mvs += fun(arr[i], mx);
    }
    if(mvs <= k){
        return true;
    }
    return false;
}
signed main(){
    cin >> n >> k;
    for(int i=0; n>i; i++){
        cin >> arr[i];
    }
    int l = 1, r = 1000000000;
    int ans = -1;
    while(l <= r){
        int mid = (l+r)/2;
        bool temp = check(mid);
        if(temp){
            ans = mid;
            r = mid-1;
        }else{
            l = mid+1;
        }
    }
    cout << ans << endl;
}






Measured memory_bytes: 5136
#include<stdio.h>

int main(){
    int x,y,temp,i;
    for(i=1;i<=3000;i++){
        scanf("%d %d",&x,&y);
            if(x==0 && y==0){
                exit(0);
            }else if(x>y){
                temp=x;
                x=y;
                y=temp;
                printf("%d %d\n",x,y);
            }else{
                printf("%d %d\n",x,y);
            }
    }
}


Measured memory_bytes: 2112
import sys
input = sys.stdin.readline


def main(H):
    b = H[0]
    count = 0
    max_count = 0

    for i in range(1, len(H)):
        if H[i] > b:
            if max_count < count:
                max_count = count

            count = 0
        else:
            count += 1
        b = H[i]

    return max(max_count, count)


if __name__ == "__main__":
    n = int(input())
    H = list(map(int, input().split()))
    print(main(H))


Measured memory_bytes: 14168
class SegmentTree():
    def __init__(self,param,default,func):
        if isinstance(param,list):
            n=len(param)
        else:
            n=param
        self.d=default
        self.leaf=1<<(n-1).bit_length()
        if isinstance(param,list):
            self.tree=[default]*(self.leaf-1)+param+[default]*(self.leaf-n)
            for i in range(self.leaf-2,-1,-1):
                self.tree[i]=func(self.tree[i*2+1],self.tree[i*2+2])
        else:
            self.tree=[default]*(self.leaf*2-1)
        self.f=func
    def find(self,i):
        return self.tree[i+self.leaf-1]
    def update(self,idx,a):
        idx+=self.leaf-1
        self.tree[idx]=a
        while idx:
            idx=(idx-1)>>1
            self.tree[idx]=self.merge(self.tree[idx*2+1],self.tree[idx*2+2])
    def merge(self,a,b):
        return self.f(a,b)
    def get_top(self):
        return self.tree[0]
    def query(self,a,b): #[a,b)
        T=self.tree
        l,r=a+self.leaf-1,b+self.leaf-1
        res=self.d
        while l<r:
            if not l%2:
                res=self.merge(res,T[l])
                l+=1
            if not r%2:
                r-=1
                res=self.merge(res,T[r])
            l>>=1
            r>>=1
        return res

def gcd(x,y):
    if x<y:
        x,y=y,x
    if y==0:
        return x
    return gcd(y,x%y)

n=int(input())
A=list(map(int,input().split()))
seg=SegmentTree(A,0,gcd)
ans=0
for i in range(n):
    seg.update(i,0)
    ans=max(ans,seg.get_top())
    seg.update(i,A[i])
print(ans)

Measured memory_bytes: 157704
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc120c
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            List<char> cl = new List<char>();

            for (int i = 0; i < s.Length; i++)
            {
                cl.Add(s[i]);
            }

            int remcont = 0;
            int ii = 0;
            for (; ; )
            {
                bool remf = false;
                for (; ii < cl.Count - 1; ii++)
                {
                    if ((cl[ii] == '0' && cl[ii + 1] == '1')
                        || (cl[ii] == '1' && cl[ii + 1] == '0'))
                    {
                        cl.RemoveAt(ii);
                        cl.RemoveAt(ii);
                        remcont += 2;
                        remf = true;
                        ii = Math.Max(0,ii-3);
                        break;
                    }

                }

                if (remf == false || cl.Count < 2)
                {
                    break;
                }
            }

            Console.WriteLine(remcont);
            Console.ReadLine();

        }
    }
}


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

int main() {
    int n,count,ans=0;
    cin>>n;
    for (int i=1; i<=n; i+=2) {
        count=0;
        for (int j=1; j<=i; j++) {
            if (i%j==0) count++;
        }
        if (count==8) ans++;
    }
    cout<<ans<<endl;
}   


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

int main(){
  int n, a, p = 0;
  cin >> n; 
  rep(i,n) {
    cin >> a;
    if(a == p+1) p++;
  }
  cout << (p == 0 ? -1 : n-p) << endl;
  return 0;
}

Measured memory_bytes: 256