akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
	std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
	if (b < a) {
		a = b;
		return 1;
	}
	return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);

	int h,w,k;
	cin>>h>>w>>k;
	string s[h];
	rep(i,0,h) cin>>s[i];

	int cnt = 0;
	int los = 0;

	rep(H,0,bits(h)){
		rep(W,0,bits(w)){
		  int count = 0;
			rep(i,0,h){
				if(H & bits(i)){
					int wa = 0;
					rep(j,0,w){
						if(W & bits(j)){
							if(s[i][j] == '#') ++count;
						}
					}
				}
			}
		  if(count == k) ++cnt;
		}
	}

	cout<<cnt<<'\n';
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	string s; cin >> s;
	ll r=0; ll g=0; ll b=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R')r++;
		if(s[i]=='G')g++;
		if(s[i]=='B')b++;
	}
	ll res=r*g*b;
	for(int i=0;i<n;i++){
		for(int j=1;j<n;j++){
			if(i+j+j>=n)continue;
			if(s[i]!=s[i+j]&&s[i+j]!=s[i+j+j]&&s[i]!=s[i+j+j])res--;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 3656
N, X = map(int, input().split())
L = list(map(int, input().split()))
d = 0
count = 0
for i in range(N):
  d += L[i]
  if X < d:
    count = i + 1
    break
if count == 0:
  print(N + 1)
else:
  print(count)
    


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<set>
#include<string>
#include<bitset>
#include<queue>
#include<map>
using namespace std;



int main() {
	int N; 
	long long D;
	cin >> N >> D;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		long long dis;
		long long X, Y;
		cin >> X >> Y;

		dis = X * X + Y * Y - D * D;
		if (dis <= 0) {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3160
K,N=map(int,input().split())
A=list(map(int,input().split()))
sa=[]
sa.append(int(K-A[-1]+A[0]))
for i in range(1,N):
  tmp=A[i]-A[i-1]
  sa.append(tmp)
ans=K-max(sa)
print(ans)

Measured memory_bytes: 26436
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    ll*a=new ll[n];
    ll*b=new ll[n];
    for(int i=0;i<n;i++)b[i]=0;
    for(int i=0;i<n-1;i++){
        cin>>a[i];
        b[a[i]-1]++;
    }
    for(int i=0;i<n;i++)cout<<b[i]<<'\n';
    return 0;
}

Measured memory_bytes: 6716
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, X = read_values()
    
    if X in (1, 2 * N - 1):
        print("No")
        return
    
    print("Yes")

    F = [i for i in range(2 * N - 1, 0, -1) if i != X]
    for f in F[N - 1:]:
        print(f)
    print(X)
    for f in F[:N - 1]:
        print(f)


if __name__ == "__main__":
    main()



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

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    rep(i,n) {
        if(a[i] == 0) {
            cout << "0" << endl;
            return 0;
        }
    }

    ll ans = a[0];
    if(ans > (ll)1e18) {
        cout << "-1";
        return 0;
    }
    rep(i,n-1) {
        ll tmp = (ll)1e18/a[i+1];
        if(ans > tmp) {
            cout << "-1";
            return 0;
        }
        ans *= a[i+1];
        if(ans > (ll)1e18) {
            cout << "-1";
            return 0;
        }
    }
    
    
    
    cout << ans << "\n";
    return 0;
}


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

int main() {
	string s; cin >> s;
	int n = s.size();
	int mini = 1e9;
	REP(i, 26) {
		int cnt = 0;
		int maxi = 0;
		REP(j , n) {
			if (s[j] == i + 'a') {
				maxi = max(maxi, cnt);
				cnt = 0;
			}
			else cnt++;
		}
		maxi = max(maxi, cnt);
		mini = min(mini, maxi);
	}
	cout << mini << '\n';
    return 0;
}


Measured memory_bytes: 3572
S = input()
ans = 0
if S[0] == '1':
    for i in range(1, len(S)):
        if i % 2 == 0:
            if S[i] != '1':
                ans += 1
        else:
            if S[i] != '0':
                ans += 1
    print(ans)
else:
    for i in range(1, len(S)):
        if i % 2 == 0:
            if S[i] != '0':
                ans += 1
        else:
            if S[i] != '1':
                ans += 1
    print(ans)      

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
  //if(y==0) return x;
  //return gcd(y, x%y);
//}
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
int main(){
  int a,b;
  cin >> a >> b;
  int c=a-b*2;
  if(c>0) cout << c << endl;
  else cout << 0 << endl; 
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define For(i, a, b) for (i = a; i <= b; i++)
using namespace std;
inline int read() {
	int res = 0; bool bo = 0; char c;
	while (((c = getchar()) < '0' || c > '9') && c != '-');
	if (c == '-') bo = 1; else res = c - 48;
	while ((c = getchar()) >= '0' && c <= '9')
		res = (res << 3) + (res << 1) + (c - 48);
	return bo ? ~res + 1 : res;
}
const int N = 2e5 + 5;
int i, n, p[N]; double ans;
int main() {
	n = (read() << 1) - 1; For (i, 0, n) p[i] = read();
	sort(p, p + n + 1); For (i, 0, n) ans += 1.0 * i * p[i] / n;
	printf("%.10lf\n", ans); return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MODNum 1000000007
#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    int N, ans;
    scanf("%d", &N);
    vector<int> W(N);
    int Sum = 0;
    REP(int,i,0,N){
        scanf("%d", &W.at(i));
        Sum += W.at(i);
    }
    ans = INT_MAX;
    int Sum2 = Sum;
    REP(int,i,0,N){
        Sum2 -= W.at(i);
        int Sum1 = Sum - Sum2;
        int Diff = abs(Sum1-Sum2);
        ans = min(ans, Diff);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define MAX 3e5+7
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int w,h;
	cin >> h >> w;
	char c[h*2+1][w+1];
	for(int i=0;i<h*2;i+=2)
	{
		for(int j=0;j<w;j++)
		{
			cin >> c[i][j];
			c[i+1][j]=c[i][j];
		}
	}
	int k=0;
	for(int i=0;i<h*2;i++)
	{
		for(int j=0;j<w;j++)
		{
			cout << c[i][j];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
d=dict()
need=[0,2,5,5,4,5,6,3,7,6]
for i in range(m):
    if need[a[i]] not in d:
        d[need[a[i]]]=a[i]
    else:
        if a[i]>d[need[a[i]]]:
            d[need[a[i]]]=a[i]
d=list(d.items())
d.sort()
m=len(d)
dp=[[-1]*10 for _ in range(n+1)]
dp[0]=[0]*10
for i in range(n+1):
    for j in range(m):
        if i-d[j][0]>=0 and dp[i-d[j][0]][0]!=-1:
            if dp[i][0]==dp[i-d[j][0]][0]+1:
                ok=False
                for k in reversed(range(1,10)):
                    if k==d[j][1]:
                        if dp[i][k]<dp[i-d[j][0]][k]+1:
                            ok=True
                            break
                        if dp[i][k]>dp[i-d[j][0]][k]+1:
                            break
                    else:
                        if dp[i][k]<dp[i-d[j][0]][k]:
                            ok=True
                            break
                        if dp[i][k]>dp[i-d[j][0]][k]:
                            break
                if ok:
                    for k in range(10):
                        dp[i][k]=dp[i-d[j][0]][k]
                    dp[i][d[j][1]]+=1
                    dp[i][0]+=1
            elif dp[i][0]<dp[i-d[j][0]][0]+1:
                for k in range(10):
                    dp[i][k]=dp[i-d[j][0]][k]
                dp[i][d[j][1]]+=1
                dp[i][0]+=1
ans=str()
for i in reversed(range(1,10)):
    ans+=str(i)*dp[-1][i]
print(ans)
#print(d)
#print(dp[-1])

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  vector<int> cnt(26, 0);
  if(s == "zyxwvutsrqponmlkjihgfedcba") {
    cout << -1 << endl;
    return 0;
  }
  for(int i=0;i<s.size();i++)
    cnt[s[i]-'a']++;

  for(int i=0;i<26;i++) {
    if(cnt[i] == 0) {
      cout << s << (char)('a'+i) << endl;
      return 0;
    }
  }

  vector<int> cnt2(26, 0);
  for(int i=s.size()-1;i>=0;i--) {
    cnt2[s[i]-'a']++;
    for(int j=s[i]-'a'+1;j<26;j++) {
      if(cnt2[j]) {
        cout << s.substr(0, i) << (char)(j+'a') << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int g=count(s.begin(),s.end(),'g'),p=count(s.begin(),s.end(),'p');
	cout<<(g-p)/2<<endl;
	return 0;
}

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

using namespace std;

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

int main() {
    vector<vector<int>> inputs(3, vector<int>(3));
    int c_max = 0;
    rep(i, 3){
        rep(j, 3){
            cin >> inputs.at(i).at(j);
            c_max = max(c_max, inputs.at(i).at(j));
        }
    }
    vector<int> As(3);
    vector<int> Bs(3);
    rep(a1, c_max*2+1){
        rep(i, inputs.size()){
            Bs.at(i) = inputs.at(0).at(i) - a1;
        }
        rep(i, inputs.at(0).size()){
            As.at(i) = inputs.at(i).at(0) - Bs.at(0);
        }
        bool ans = true;
        rep(i, inputs.size()){
            rep(j, inputs.at(i).size()){
                if(inputs.at(i).at(j) != As.at(i) + Bs.at(j)){
                    ans = false;
                    break;
                }
            }
            if(!ans) break;
        }
        if(ans){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
readline = open(0).readline
writelines = open(1, 'w').writelines
s = set()
def insert(x):
    s.add(x)
    ans.append("%d\n" % len(s))
def find(x):
    ans.append("%d\n" % (x in s))

C = [insert, find, s.discard].__getitem__
Q = int(readline())
ans = []
for _ in range(Q):
    t, x = map(int, readline().split())
    C(t)(x)
writelines(ans)


Measured memory_bytes: 34996
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
int n; cin >> n;
vector<int> pos(n+1);
pos[0] = -1;
for( int i = 0; i < n; ++i ){
  int t; cin >> t;
  pos[t] = i;
}
int cnt = 0;
int ans = 0;
for( int k = 1; k <= n; ++k ){
  if( pos[k-1] < pos[k] ) ++cnt;
  else cnt = 1;
  ans = max(ans, cnt);
}
cout << n-ans << endl;
}

Measured memory_bytes: 1024
from collections import defaultdict, deque
import sys
import math

sys.setrecursionlimit(100000)

MIN = -10 ** 9
MAX = 10 ** 9 + 7


def main():
    # N = int(input())
    K, X = [int(a) for a in input().split()]
    # H = [
    #     int(input())
    #     for _ in range(N)
    # ]
    # A = [int(a) for a in input().split()]
    m = max(-1000000, X - K + 1)
    m2 = min(1000000, X + K - 1)
    print(*range(m,m2+1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3436
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<utility>
#include<cmath>
#include<set>
#include<list>
#include<string>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<set>
#include<cstring>
#include<iterator>
#include<bitset>
#include<assert.h>
//#include<unistd.h>
//#include<chrono>
//#include<time.h>
//#include<windows.h>
using namespace std;
 
//#define int ll
typedef long long ll;
static const int MOD = 1000000007;
//static const int INF = 2147483647;
//static const long long INF = 9223372000000000000;
//static const long long INF = 9223372000000000000/2;
//static const int INF = 1000010000;
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define NP next_permutation
#define PQ priority_queue
#define UB upper_bound
#define LB lower_bound
#define SZ(a) int((a).size())
#define LEN(a) int((a).length())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REP1(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREP1(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define YESNO(x) puts((x)?"YES":"NO")

template< typename T >
struct edge
{
  int src, to;
  T cost;
 
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
 
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
 
  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s)
{
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}


signed main(){
    int v,e,r;
    cin >> v >> e >> r;
    WeightedGraph< unsigned > g(v);
    REP(i,e){
        int t1,t2,t3;
        cin >> t1 >> t2 >> t3;
        g[t1].emplace_back(t2,t3);
    }

    auto cost = dijkstra(g,r);
    REP(i,v){
        if(cost[i]==numeric_limits< unsigned >::max()) puts("INF");
        else printf("%d\n",cost[i]);
    }

    return 0;
}



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

#define ll long long
#define pb push_back
#define mod 1000000007
#define rep(i,a,n) for(int i=a;i<n;i++)
#define dbg(x) cout<<#x<<" = "<<x<<'\n';

void solve()
{
    string s;
    cin>>s;

    int sz=s.size();
    ll sum=0;
    for(int i=0;i<sz;i++)
    {
        sum+=s[i]-'0';
    }

    if(sum%9==0)
        cout<<"Yes";
    else
        cout<<"No";

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  int tc=1;
  //cin>>tc;
  while(tc--)
  {
    solve();
  }
  return 0;
}


Measured memory_bytes: 3700
import math

N = int(input())
A = []
prim = 0
for i in range(N):
    x = int(input())
    A.append(x)

for j in range(len(A)):
    num = 0

    if A[j] == 2:
        prim += 1
    else:
        for k in range(2, int(math.sqrt(A[j]))+1):
            if A[j] == 1:
                pass
            elif A[j]%k == 0:
                break
        else:
            prim += 1
print(prim)



Measured memory_bytes: 6004
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
import Debug.Trace
-- trace _ = id

solve :: Int -> Int -> [Int] -> [Int] -> Int
solve n m xs ys = weightX `mMul` weightY
  where
    diff ps = zipWith mSub (tail ps) ps
    dxs = diff xs
    dys = diff ys
    weightX = foldl' mAdd 0 $ zipWith mMul dxs [hight n k | k <- [0..n-2]]
    weightY = foldl' mAdd 0 $ zipWith mMul dys [hight m k | k <- [0..m-2]]

hight n k = mMul (n - 1 - k) (k + 1)

----------------------------------------------------------------------

mPrime = 10^9 + 7

-- mAdd x y = (x + y) `mod` mPrime
mAdd :: Int -> Int -> Int
mAdd x y = let w = x + y in if w < mPrime then w else w - mPrime

-- mSub x y = (x - y) `mod` mPrime    -- ok even if x < y
mSub :: Int -> Int -> Int
mSub x y = let w = x - y in if w >= 0 then w else w + mPrime

mMul :: Int -> Int -> Int
mMul x y = (x * y) `mod` mPrime

traceL :: Show a => String -> a -> b -> b
traceL label showObj val = trace (label ++ " " ++ show showObj) val

----------------------------------------------------------------------

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n,bs_m]:remLines1 = remLines0
      n = readBInt bs_n
      m = readBInt bs_m
      line2:remLines2 = remLines1
      xs = map readBInt line2
      line3:remLines3 = remLines2
      ys = map readBInt line3
  in solve n m xs ys

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "3 3\n1 3 4\n1 3 6\n"
inp2 = "6 5\n-790013317 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677\n"
inp3 = "4 4\n0 1 2 3\n0 1 2 3\n"
inp4 = "4 3\n0 1 2 3\n0 1 2\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
tv4 = tmain $ B.pack inp4
test1 = tv1 == 60
test2 = tv2 == 835067060
test3 = tv3 == 100
test4 = tv4 == 40
alltest = test1 && test2 && test3 && test4



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

void solve() {
    int x; cin >> x;
    cout << 1 - x << '\n';
}

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


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,z;
  cin >> n >> z;
  int ans1 = 4*n-z;
  int ans2 = z-2*n;
  if(ans1>=0&&!(ans1%2)&&ans2>=0&&!(ans2%2))cout << "Yes";
  else cout << "No";
  cout << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
#define maxl __LONG_LONG_MAX__
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define rep(i, n) for(int i = 0; i < n; i++)
#define rev(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i=1; i < n; i++)
#define rev1(i, n) for(int i=n ; i > 0; i--)
#define FOR(i, a, b) for(int i=a ; i < b; i++)
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define n_ones(x) __builtin_popcountll(x)
#define n_trailzero(x) __builtin_ctzll(x)
#define n_leadingzero(x) __builtin_clz(x)
#define sz(a) (ll)(a.size())

typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef stack<ll> stk;
typedef queue<ll> que;

typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setll;
typedef tree<char,null_type,less<char>,rb_tree_tag,
tree_order_statistics_node_update> indexed_setc;

ll max(int a,ll b){ return max((ll)a,b);}
ll min(int a,ll b){ return min((ll)a,b);} 
ll min(ll a,int b){ return min(a,(ll)b);}
ll max(ll a,int b){ return max(a,(ll)b);}

ll mod = 1e9 + 7;

vll adj[100005];
ll vis[100005];
ll dp[100005];

ll dfs(ll u)
{
	if(vis[u])
		return dp[u];
	vis[u]++;
	ll d = 0;
	for(ll v : adj[u])
	{
		d = max(d, dfs(v) + 1);
	}
	dp[u] = d;
	return dp[u];
}
void solve()
{
	ll n, m;
	cin>>n>>m;
	rep(i, m)
	{
		ll u, v;
		cin>>u>>v;
		adj[u].pb(v);
	}
	ll maxi = 0;
	rep1(i, n+1)
	{
		maxi = max(maxi, dfs(i));
	}
	cout<<maxi<<endl;
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
	ll t = 1;
	//cin>>t;
	rep(i, t)
		solve();
	return 0;
	
}

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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL<<60;

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


// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));



// まずin-place dp でやる=>品物番号省略
// 制約からweightは添字にしない
// 価値DPをする

int main()
{
    ll n,W;cin>>n>>W;
    vec<ll> dp(100100,INF);//その価値だすための値の最小重量を記録する
    dp[0]=0; //val=0 <=> weight=0 初期条件
    ll weight,value;
    loop(i,1,n+1){ //次のvのfor文で1000*1から始めるためにi=1,2,...,n 
        cin>>weight>>value;
        for(ll v=1000*i;v>=value;v--){
            dp[v]=min(dp[v],dp[v-value]+weight);
            // dp[0]から積んでいく
            // i=0のループで、v==valueのとき
            // dp[v]=min(dp[v],dp[0]+weight)=min(INF,weight)=weight
            // ここでv=value+1以降は実現不可なため重さINFと定義する
        }
    }
    // valueの総和はたかだか10^3**10^2=10^5なので
    // 100000までみてW以下の最大の値を回答とする
    ll ans=0;
    for(ll i=0;i<=100000;i++)if(dp[i]<=W)ans=i;
    cout<<ans<<endl;
    return 0;

}




Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}

	vector<int> dp(n, 1000000010);
	dp[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= k; j++) {
			if (i - j < 0) {
				break;
			}
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
	cout << dp[n - 1] << endl;

	return 0;
}

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

int* islandIndex;
vector<int> islandFromStart;

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

	islandIndex = (int*)malloc(sizeof(int)*N);
	for (int i = 0; i < N; i++)
		islandIndex[i] = 0;

	int a, b;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		if (a == 1) {
			islandFromStart.push_back(b - 1);
		}
		else if (b == N){
			islandIndex[a - 1] = 1;
		}
	}

	bool flag = false;
	int len = islandFromStart.size();
	for(int i=0; i<len; i++){
		if (islandIndex[islandFromStart.at(i)] == 1) {
			flag = true;
			break;
		}
	}

	if (flag)
		cout << "POSSIBLE";
	else
		cout << "IMPOSSIBLE";

	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define gi(x) ((x) = F())
int F(){
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}
int n, a[100010];
long long ans;
int main(){
	gi(n);
	for (int i = 1; i <= n; ++i) gi(a[i]);
	for (int i = 1; i <= n; ++i) if (a[i] & 1) if (a[i + 1]) ++ans, --a[i], --a[i + 1];
	for (int i = 1; i <= n; ++i) ans += a[i] >> 1;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define zzz ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b){return (a*b)/gcd(a, b);}
bool check[5000];
int main()
{
    zzz;
    int a,b; cin>>a>>b;
    int j = b-a+1;
    while(j<b)
    {
        cout<<j++<<" ";
    }
    cout<<b<<" ";
    j = b+1;
    while(j!=b+a)
    {
        cout<<j++<<" ";
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  vector<int> prime={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
  int n;
  cin>>n;
  int num[25];
  rep(i,0,25){
    num[i]=0;
  }
  rep(i,0,25){
    int cur=n;
    while(cur>0){
      cur/=prime[i];
      num[i]+=cur;
    }
  }
  int ans=0;
  rep(i,0,25){
    if(num[i]>=74) ans++;
  }
  rep(i,0,25){
    rep(j,0,25){
      if(i!=j){
        if(num[i]>=24 && num[j]>=2) ans++;
      }
    }
  }
  rep(i,0,25){
    rep(j,0,25){
      if(i!=j){
        if(num[i]>=14 && num[j]>=4) ans++;
      }
    }
  }
  rep(i,0,24){
    rep(j,i+1,25){
      rep(k,0,25){
        if(i!=k && j!=k){
          if(num[i]>=4 && num[j]>=4 && num[k]>=2) ans++;
        }
      }
    }
  }
  cout<<ans<<endl;
}

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

int main(){
  string S;
  cin >> S;
  int count=0;
  int ans=0;
  for(int i=0;i<(int)S.size();i++){
    if(S[i]=='A' || S[i]=='C' || S[i]=='G' || S[i]=='T'){
      count++; 
      ans=max(ans,count);
    }
    else{
      count=0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
p,q= input().split()
a,b =(int(p), int(q))
f = map(int,input().split())
f_list = list(f)
out_dis =f_list[0] + a -f_list[b-1]
dis_list=[out_dis]
for i in range(b-1):
    dis = f_list[i+1]-f_list[i]
    dis_list.append(dis)

print(int((sum(dis_list)-max(dis_list))))

Measured memory_bytes: 26444
#include <stdio.h>
	int main(void){
		int n,i,j,k;
		int b;
		char a[100],s[100],h[100],d[100],c[100];
		scanf("%d",&n);
		for(i=0;i<13;i++){
			s[i]=0;
			h[i]=0;
			d[i]=0;
			c[i]=0;
		}
		for(j=0;j<2*n;j++){
			scanf("%c %d",&a[j],&b);
			if(a[j]=='S'){
				s[b-1]=1;
			}else if(a[j]=='H'){
				h[b-1]=1;
			}else if(a[j]=='D'){
				d[b-1]=1;
			}else if(a[j]=='C'){
				c[b-1]=1;
			}
		}

		for(k=0;k<13;k++){
			if(s[k]==0){
				printf("S %d\n",k+1);
			}
		}
		for(k=0;k<13;k++){
			if(h[k]==0){
				printf("H %d\n",k+1);
			}
		}
		for(k=0;k<13;k++){		
			if(c[k]==0){
				printf("C %d\n",k+1);
			}
		}
		for(k=0;k<13;k++){
			if(d[k]==0){
				printf("D %d\n",k+1);
			}
		}
	return 0;
}

Measured memory_bytes: 596
N = int(input())
C = [-1] * N
for i in range(N):
    ai, bi = [int(_) for _ in input().split()]
    C[i] = (ai + bi, ai, bi)

C.sort(reverse=True)

result = 0
for i, ci in enumerate(C):
    if i % 2 == 0:
        result += ci[1]
    else:
        result -= ci[2]

print(result)

Measured memory_bytes: 20952
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int n;

void make(string s){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    char ma='a';
    rep(i,s.size()){
        if(s[i]>ma) ma=s[i];
    }
    ma++;
    char x='a'; x--;
    rep(i,(ma-'a')+1){
        x++;
        make(s+x);
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    cin>>n;
    make("a");
    
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const int maxn = 500050;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const ll linf = 7e18;
ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}

ll gcd(ll x, ll y)
{
    if (x % y == 0)
        return y;
    return gcd(y, x % y);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int i, j, k;
    ll ans;
    long double m, n;
    cin >> n >> m;
    ans = m * n;
    cout << ans << "\n";
    return 0;
}


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

Measured memory_bytes: 600
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int w = sc.nextInt();
        int[] wArr = new int[n];
        int[] vArr = new int[n];

        int V_MAX = 100100;
        for (int i = 0; i < n; i++) {
            wArr[i] = sc.nextInt();
            vArr[i] = sc.nextInt();
        }

        long[][] dp = new long[n + 1][V_MAX];
        for (long[] x : dp) {
            Arrays.fill(x, Integer.MAX_VALUE);
        }
//        debug(dp);
        dp[0][0] = 0;
        // dp[i][j] ... i番目までの荷物をつかって、価値がjを達成するような重さの最小値

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < V_MAX; j++) {
                if (vArr[i] <= j) {
                    dp[i + 1][j] = Math.min(dp[i][j], dp[i][j - vArr[i]] + wArr[i]);
                } else {
                    dp[i + 1][j] = dp[i][j];
                }
            }
        }

//        debug(dp);
        int ans = 0;
        for (int i = 0; i < V_MAX; i++) {
//            debug(dp[n][i]);
            if (w >= dp[n][i]) {
                ans = i;
            }
        }

        System.out.println(ans);
    }


    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 126932
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); i++)
int main(){
    int a; string s;
    cin >> a >> s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int			long long
#define ll 			long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

void solve()
{
	ll n,x,t;
	cin>>n>>x>>t;
	ll curr=0;
	ll ans=0;
	while(curr<n){
		curr+=x;
		ans+=t;
	}	
	cout<<ans<<endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c; cin >> a >> b >> c;
    if(a == b && b == c) cout << 1 << endl;
    else if(a == b || b == c || c == a) cout << 2 << endl;
    else cout << 3 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int N, A, B, C;
vector<string> s;
bool fin = false;
string ans;

void dfs(int d, int a, int b, int c, string &now) {
    if(fin) {
        return;
    }
    if(d == N) {
        fin = true;
        ans = now;
        return;
    }
    if(s[d] == "AB") {
        if(a >= 1) {
            now += "B";
            dfs(d + 1, a - 1, b + 1, c, now);
            now.pop_back();
        }
        if(b >= 1) {
            now += "A";
            dfs(d + 1, a + 1, b - 1, c, now);
            now.pop_back();
        }
    } else if(s[d] == "AC") {
        if(a >= 1) {
            now += "C";
            dfs(d + 1, a - 1, b, c + 1, now);
            now.pop_back();
        }
        if(c >= 1) {
            now += "A";
            dfs(d + 1, a + 1, b, c - 1, now);
            now.pop_back();
        }
    } else {
        if(b >= 1) {
            now += "C";
            dfs(d + 1, a, b - 1, c + 1, now);
            now.pop_back();
        }
        if(c >= 1) {
            now += "B";
            dfs(d + 1, a, b + 1, c - 1, now);
            now.pop_back();
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B >> C;
    s.resize(N);
    for(int i = 0; i < N; i++) {
        cin >> s[i];
    }
    string now = "";
    dfs(0, A, B, C, now);
    if(fin) {
        print("Yes");
        for(const auto &c : ans) {
            print(c);
        }
    } else {
        print("No");
    }
}

Measured memory_bytes: 13024
n=gets.to_i
t=gets.split.map{|e|e.to_i*2}
v=gets.split.map{|e|e.to_i*2}
z=[0]*10**5
q=j=s=m=0
n.times{|i|
  q+=t[i]
  z[j]=[z[j],v[i]].min
  (j+1..q).each{|k|z[k]=[z[k-1]+1,v[i]].min}
  j=q
  }
(j-1).downto(0){|i|s+=m=[m+1,z[i]].min}
p s/4.0

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

const int THUNDER=5;
int h,w,c;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

bool isrange(int x,int y){return 0<=x && x<h && 0<=y && y<w;}

int elec(int time,vector<vector<int>> p){
  if(time==THUNDER){
    queue<pair<int,int>> que;
    int color=p[0][0];
    if(color!=c) return 0;
    int res=1;
    que.push(make_pair(0,0));
    p[0][0]=-1;
    while(!que.empty()){
      auto place=que.front();
      que.pop();
      for(int i=0;i<4;i++){
	int tox=place.first+dx[i];
	int toy=place.second+dy[i];
	if(isrange(tox,toy) && p[tox][toy]==color){
	  res++;
	  p[tox][toy]=-1;
	  que.push(make_pair(tox,toy));
	}
      }
     
    }

    return res;
  }
  int res=0;
  for(int toc=0;toc<6;toc++){
    vector<vector<int>> newp=p;
    int color=p[0][0];
    queue<pair<int,int>> que;
    que.push(make_pair(0,0));
    newp[0][0]=-1;
    while(!que.empty()){
      auto place=que.front();
      que.pop();
      for(int i=0;i<4;i++){
	int tox=place.first+dx[i];
	int toy=place.second+dy[i];
	if(isrange(tox,toy) && p[tox][toy]==color && newp[tox][toy]!=-1){
	  newp[tox][toy]=-1;
	  que.push(make_pair(tox,toy));
	}
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(newp[i][j]==-1) newp[i][j]=toc;
      }
    }
    res=max(res,elec(time+1,newp));
    
  }
  
  return res;
}

int main(){

  while(cin>>h>>w>>c,h){
    vector<vector<int>> p(h,vector<int>(w));
    c--;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>p[i][j];
	p[i][j]--;
      }
    }
    int res=elec(0,p);
    cout<<res<<endl;
  }



}

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


int main() {
    ll A, B, K;
    cin >> A >> B >> K;

    if (K < A) {
        A -= K;
        K = 0;
    } else {
        K -= A;
        A = 0;
    }
    if (K < B) {
        B -= K;
    } else {
        B = 0;
    }
    cout << A << " " << B << endl;
    
}



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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll ans=2020;
    ll l,r;
    cin>>l>>r;
    ll a,b;
    a = l%2019;
    b = (min(l+2018,r)) % 2019;
    if(b<a) b+=2019;
    for (int i = a; i <= b; i++)
    {
        for (int j = a; j < i; j++)
        {
            ll tmp = (i*j)%2019;
            ans=min(ans,tmp);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25

long long N;
int c;

void dfs(long long n)
{
	if (n > N) {
		return;
	}
	string s = to_string(n);
	if (s.find('3') != string::npos && s.find('5') != string::npos && s.find('7') != string::npos) {
		c++;
	}
	dfs(n * 10 + 3);
	dfs(n * 10 + 5);
	dfs(n * 10 + 7);
}

int main()
{
	c = 0;
	cin >> N;
	if (N >= 357) {
		dfs(0);
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
	#define rev(i,n) for(i=n-1;i>=0;i--)
		#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
		#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
int dp[1001][1001];

int main(void){
	int i,j,W,n,v[1000],w[1000],c=1;
	while(W=in(),W){
		n=in();
		rep(i,n){
			scanf("%d,%d",v+i,w+i);
		}
		rep(i,W+1) dp[0][i]=0;
		for(i=1;i<=n;i++){
			rep(j,W+1){
				if(j<w[i-1]) dp[i][j]=dp[i-1][j];
				else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
			}
		}
		rep(i,W+1)
			if(dp[n][i]==dp[n][W]) break;
		printf("Case %d:\n",c++);
		print(dp[n][W]);
		print(i);
	}
	return 0;
}


Measured memory_bytes: 5612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int k, a, b; std::cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            std::cout << "OK" << std::endl;
            return 0;
        }
    }
    std::cout << "NG" << std::endl;
    return 0;
}


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

int N, ans;
int main() {
  cin >> N;
  for (int i = 1; i <= N; i++) {
    if (std::to_string(i).size() % 2 != 0) {
      ans++;
    }
  }

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


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

typedef long long ll;
ll mod = 1000000007;

bool vis[101];
int assigned[101];
vector<vector<int> > ans(101);
int n;
bool find(int x){
    for(int i=0; i<ans[x].size(); i++){
        if(!vis[ans[x][i]]){
            vis[ans[x][i]] = true;
            if(assigned[ans[x][i]] == -1|| find(assigned[ans[x][i]]))
            {
                assigned[ans[x][i]] = x;
                return true;
            }
        }
    }
    return false;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //memset(vis, false, sizeof(vis));
    memset(assigned, -1, sizeof(assigned));
    int n;
    cin >> n;
    int a, b;
    vector<pair<int, int> > vb, vr;
    for(int i=0; i<n; i++){
        cin >> a >> b;
        vr.push_back({a, b});
    }
    for(int i=0; i<n; i++){
        cin >> a >> b;
        vb.push_back({a, b});
    }
    int cnt = 0;
    for(int i=n-1; i>=0; i--){
        for(int j=0; j<n; j++){
            if(vb[j].first > vr[i].first && vb[j].second > vr[i].second){
                ans[i].push_back(j);
            }
        }
    }
    for(int i=0; i<n; i++){
        memset(vis, false, sizeof(vis));
        if(find(i)) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);                                                                                                                                                                        size_t a, b, t = 0;
    cin >> a >> b;
    for (size_t i = a; i <= b; ++i) {
        if (i / 10000 == i % 10 && (i % 10000) / 1000 == (i % 100) / 10) {
            ++t;
        }
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int S = stdIn.nextInt();
		
		int h = S / 3600;
		S = S - h*3600;
		
		int m = S / 60;
		S = S - m*60;
		
		System.out.println(h+ ":" + m + ":" + S);
	}
}

Measured memory_bytes: 17176
from collections import deque

h, w = [int(v) for v in input().split()]

maze = []
for i in range(h):
    maze.append(list(input()))

def contains(maze, i, j):
    if i < 0 or i >= h:
        return False
    if j < 0 or j >= w:
        return False
    return True

def far(maze, i0, j0):
    q = deque([])

    q.append((i0, j0, 0))

    closed = set()
    closed.add((i0, j0))
    max_dist = 0
    max_p = None
    while len(q) > 0:
        e = q.popleft()
        
        i = e[0]
        j = e[1]
        cost = e[2] + 1
        for n in ((0, 1), (1, 0), (-1, 0), (0, -1)):
            ni = i + n[0]
            nj = j + n[1]
            nkey = (ni, nj)
            if not contains(maze, ni, nj):
                continue
            if maze[ni][nj] != '.':
                continue
            nkey = (ni, nj)
            if nkey in closed:
                continue
            closed.add(nkey)
            q.append((ni, nj, cost))
            if max_dist < cost:
                max_dist = cost
                max_p = nkey
    return max_p, max_dist
    
def solve(maze):
    max_dist = 0
    for i in range(h):
        for j in range(w):
            if maze[i][j] != '.':
                continue
            p, dist = far(maze, i, j)
            if max_dist < dist:
                max_dist = dist
    return max_dist

print(solve(maze))

Measured memory_bytes: 3316
///
// File:  alds1_2_a.cpp
// Author: ymiyamoto
//
// Created on Wed Oct  4 01:16:26 2017
//

#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;
static vector<uint32_t> array;

static uint32_t bubble_sort()
{
  uint32_t count = 0;
  for (uint32_t i = 0; i < array.size(); i++) {
    for (uint32_t j = array.size() - 1; j > i; j--) {
      if (array[j - 1] > array[j]) {
        swap(array[j - 1], array[j]);
        count++;
      }
    }
  }
  return count;
}

int32_t main()
{
  uint32_t N;
  cin >> N;

  for (uint32_t i = 0; i < N; i++) {
    uint32_t val;
    cin >> val;
    array.push_back(val);
  }

  uint32_t count = bubble_sort();

  for (uint32_t i = 0; i < array.size(); i++) {
    if (i != 0) cout << " ";
    cout << array[i];
  }

  cout << endl << count << endl;

  return 0;
}

Measured memory_bytes: 3132
n, k = map(int, input().split())
def f(n, k):
    return int(n/k)

if k%2:
    print(f(n,k)**3)
else:
    l = k//2
    p = f(n, k)
    q = f(n, l) - p
    print(p**3+q**3)

Measured memory_bytes: 3060