akhauriyash/Code-Regression huggingface dataset:
from collections import deque

h, w = map(int, input().split())
meiro = [list(input()) for i in range(h)]
# meiro[y][x]


def bfs(a, b):  # a縦b横
    mx_dist = 0
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    dist = [[-1] * w for i in range(h)]
    dist[a][b] = 0
    que = deque([])
    que.append((a, b))
    while que:
        y, x = que.popleft()
        D = dist[y][x]
        for i in range(4):
            X = x + dx[i]
            Y = y + dy[i]
            if 0 <= Y and Y <= h - 1 and X <= w - 1 and 0 <= X:
                if meiro[Y][X] == ".":
                    if dist[Y][X] == -1:
                        dist[Y][X] = D + 1
                        que.append((Y, X))
                        mx_dist = max(mx_dist, D + 1)

    return mx_dist


saidai = 0
for i in range(h):
    for j in range(w):
        if meiro[i][j] == ".":
            saidai = max(saidai, bfs(i, j))
print(saidai)


Measured memory_bytes: 9484
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
	long long int n;
	scanf("%lld", &n);
	for (long long int i = sqrt(n); i >= 0; i--){
		if (n % i == 0){
			printf("%lld\n", i + n / i - 2);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

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

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	vi x;
	vector<long long>len;
	int i, j, k, l, m, n;
	long long ans;

	cin >> n >> m;
	x.resize(m);

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

	if (n >= m) {
		cout << 0;
		return 0;
	}

	sort(x.begin(), x.end());

	rep(i, m - 1) {
		len.push_back((long long)abs(x[i] - x[i + 1]));
	}
	sort(len.begin(), len.end());

	ans = 0;

	rep(i, m - n) {
		ans += len[i];
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = signed long long int;
using P = pair<int, int>;
int main (void) {
    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i, S.size()) {
        if (S.at(i) != T.at(i)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3920
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n) {
        rep(i, n) { par[i] = i; }
    }

    int root(int x) {
        if (par[x] == x)
            return x;
        return par[x] = root(par[x]);
    }

    void merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    int res = 0;

    rep(i, M) { cin >> A[i] >> B[i]; }

    rep(i, M) {
        UnionFind tree(N);
        int s1 = A[i] - 1, s2 = B[i] - 1;
        rep(j, M) {
            if (i != j) {
                tree.merge(A[j] - 1, B[j] - 1);
            }
        }

        if (!tree.same(s1, s2))
            res++;
    }

    cout << res << endl;
}

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

#define sc scanf
#define pf printf
#define CIN ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ull unsigned long long int
#define ll  long long int
#define db double
#define fl float
#define vi vector<int>
#define vl vector<ll>
#define qin queue<int>
#define pb push_back
#define pob pop_back
#define ft front
#define bk back
#define mp make_pair
#define pii pair<int,int>
#define all(c) c.begin(), c.end()
#define MOD 1000000007
#define pll __builtin_popcountll
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.begin(),v.end(),greater<ll>())



int main()
{
    CIN;

    ll n,m,x;
    cin>>n>>m>>x;

    vl u(n),v(m),su(n+1),sv(m+1);


    for(ll i=0;i<n;i++)
        cin>>u[i];

    for(ll i=0;i<m;i++)
        cin>>v[i];


    for(ll i=0;i<n;i++)
        su[i+1]=su[i]+u[i];

    for(ll i=0;i<m;i++)
        sv[i+1]=sv[i]+v[i];

    //for(ll i=0;i<sv.size();i++) cout<<sv[i]<<endl;

    ll cnt=0;

    for(ll i=0;i<=n;i++)
    {
        ll p=x-su[i];

        if(p<0)
            break;


        //cout<<"hey"<<endl;

        ll l=lower_bound(sv.begin(),sv.end(),p)-sv.begin();


        if(l>m || sv[l]>p)
            l--;

        cnt=max(i+l,cnt);
    }

    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 9520
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
ans, x = 0, 0
ans += x
for i in range(N):
    x = min(A[i]-x,B[i])
    ans += x
    x = min(A[i+1],B[i]-x)
    ans += x
print(ans)


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

using namespace std;

int main()
{
    int n,k,h,c=0;

    cin>>n>>k;

    while(n--)
    {
        cin>>h;

        if(h>=k)
        {
            c++;
        }
    }

    cout<<c<<endl;

    return 0;
}



Measured memory_bytes: 256
N, K = map(int, input().split())

data_list = []
for i in range(N):
    data = int(input())
    data_list.append(data)
data_list.sort()

result = 9999999999999999
for i in range(N-K+1):
    temp = data_list[i+K-1] - data_list[i]
    result = min(result, temp)
print(result)



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

using namespace std;

#define INF (1<<29)

typedef pair<char,int> P;

int solve(vector<P> &A,int p,int r){
  int x = A[r].second;
  int i = p - 1;

  for(int j = p ; j < r ; j++){
    if(A[j].second <= x){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);

  return i + 1;
}

void QuickSort(vector<P> &A,int p,int r){
  if(p < r){
    int q = solve(A,p,r);
    QuickSort(A,p,q-1);  
    QuickSort(A,q+1,r);  
  }
}

void MergeSort(vector<P> &A){
  int n = (int)A.size();

  if(n <= 1) return;

  vector<P> L(A.begin(), A.begin() + n / 2);
  vector<P> R(A.begin() + n / 2, A.end());

  MergeSort(L);
  MergeSort(R);

  int l = (int)L.size(), r = (int)R.size();
  for(int i = 0,j = 0,k = 0 ; i < n ; i++){
    if(k == r){
      A[i] = L[j++];
    }else if(j == l){
      A[i] = R[k++];
    }else if(L[j].second <= R[k].second){
      A[i] = L[j++];
    }else{
      A[i] = R[k++];
    }
  }
}

int main(){
  int n;

  cin >> n;
  vector<P> v(n);
  for(int i = 0 ; i < n ; i++){
    cin >> v[i].first >> v[i].second;
  }

  vector<P> check = v;
  QuickSort(v,0,n-1);
  MergeSort(check);

  if(v == check){
    cout << "Stable" << endl;
  }else{
    cout << "Not stable" << endl;
  }

  for(int i = 0 ; i < n ; i++){
    cout << v[i].first << " " << v[i].second << endl;
  }

  return 0;
}

Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#pragma GCC target("avx2")
#pragma GCC optimize("unroll-loops")

ll N, ans;

int main()
{
	fast();
	cin >> N;
	for (ll i = 2, M = N, z = 2; i * i <= M && N != 1; z = ++i)
	{
		while (N % z == 0)
			ans++, N /= z, z *= i;
		while (N % i == 0)
			N /= i;
	}

	cout << ans + (N != 1) << "\n";
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N);
    rep(i, N){
        cin >> P.at(i);
    }
    sort(P.begin(), P.end());
    int ans = 0;
    rep(i, K){
        ans += P.at(i);
    }
    cout << ans << endl;
 
}

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

#define precise(n,k) fixed<<setprecision(k)<<n

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
 
int main() {
    
    string s;
    
    cin >> s;
    
    int n = s.size();
    
    int x = 0;
    
    for(int i = 0; i < n; ++i) {
        if(s[i] == '-') {
            x--;
        } else if(s[i] == '+'){
            x++;
        }
    }
    
    cout << x << endl;
   
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;



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

  ll t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

  ll da = t1 * a1 + t2 * a2;  // 1サイクルでAが移動する距離
  ll db = t1 * b1 + t2 * b2;  // 1サイクルでBが移動する距離

  if (da == db) {
    cout << "infinity" << endl;
    return 0;
  }

  if ((a1 > b1 && a2 > b2) || (a1 < b1 && a2 < b2)) {
    cout << 0 << endl;
    return 0;
  }

  if (a1 > b1) {
    swap(a1, b1);
    swap(a2, b2);
  }

  ll ans = 0;
  ll p = (a1 - b1) * t1;
  ll q = (a2 - b2) * t2;

  if (p + q < 0) {
    cout << 0 << endl;
    return 0;
  }

  ll s = (-p) / (p + q);
  ll t = (-p) % (p + q);

  if (t == 0) {
    cout << s * 2 << endl;
  } else {
    cout << s * 2 + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
b=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(h):
  a=list(input().split())
  for j in range(w):
    if a[j]=="snuke":
      print(b[j],end="")
      print(i+1)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){
  int N;
  cin >> N;
  int prev; cin >> prev;
  int count = 1, up = 0;
  for(int i = 1; i < N; i++){
    int x;  cin >> x;
    if(up == 1 && x < prev){
      count++;  up = 0;
    }
    else if(up == -1 && x > prev) {
      count++;
      up = 0;
    }
    else if(up == 0 && x < prev) up = -1;
    else if(up == 0 && x > prev) up = 1;
    prev = x;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#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() {
    int N;
    cin >> N;
    vector<char> S(N);
    bool a=false;
    rep(i,N){
        cin >> S.at(i);
        if(S.at(i)=='Y') a=true;
    }
    if(a)cout << "Four" << endl;
    else cout << "Three" << endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
typedef long long ll;

int n;

struct K {
  ll a, b;
};
bool operator<(const K& k1, const K& k2) {
  return k1.a + k1.b < k2.a + k2.b;
}

K vs[100000+10];
bool used[100000+10];

int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld%lld", &vs[i].a, &vs[i].b);
  }
  sort(vs, vs + n);
  reverse(vs, vs + n);
  ll res = 0;
  REP(i, n) {
    if(i%2 == 0) {
      res += vs[i].a;
    } else {
      res -= vs[i].b;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<cstdlib>

#define N 100000
using namespace std;


typedef struct{
  int num[N];
  int head;
  int tail;
}Queque;


//grobal
Queque que;

//add to head position
void Enqueue(int);
//delete head position
void Dequeue(void);
//return now of stck
int front(void);


int main(){
  //format
  que.head=0;
  que.tail=0;

  int pasttime=0;
  int i,n,q,tim=0;
  string name[N];
  int finishcount=0;
  int flag[N];
  int st;

  //load n and q
  cin >>n>>q;

  //load name and time
  for(i=0;i<n;i++){
    cin >>name[i]>>tim;
    Enqueue(tim);
  }

  //format flag
  for(i=0;i<n;i++){
    flag[i]=0;
  }
  
  i=0;

  while(1){
    if(finishcount==n) break;
    //i->n i=0 continue
    else if(i==n){
      i=0;
      continue;
      }
    //flag=1 go next
      else if(flag[i]==1){
      i++;
      continue;
    }
    //load
    st=front();

    if(st>q){
      Enqueue(st-q);
      Dequeue();
      pasttime+=q;
    }

    else{
      Dequeue();
      pasttime+=st;
      flag[i]=1;
      finishcount++;
      //print
      cout <<name[i]<<" "<<pasttime<<endl;
    } 
    
    i++;
  }
    
  
  return 0;
  
}

//add to head position
void Enqueue(int x){
  que.num[que.tail]=x;
  que.tail++;
  if(que.tail==N)que.tail=0; 
}
//delete head position
void Dequeue(void){
  que.head++;
}
//return now of stck
int front(void){
  return que.num[que.head];
}

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

int main() {
	int t;
	while (cin >> t, t) {
		int n; cin >> n;
		int sum = 0;
		rep(i, n) {
			int s, f; cin >> s >> f;
			sum += f - s;
		}
		printf(sum < t ? "%d\n" : "OK\n", t - sum);
	}
}

Measured memory_bytes: 3124
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=a&&a<b)
using namespace std;
int main(){
	int X,Y,c[15][15],land[15][15],ans;
	while(cin>>X>>Y,X){
		rep(i,Y)rep(j,X)cin>>land[i][j],c[i][j]=i==0&&land[i][j]!=1;
		rep(i,Y-1)rep(j,X)if(land[i+1][j]!=1){
			if(land[i+1][j]==2)c[i+1][j]+=land[i][j]==0?c[i][j]:0;
			else rep(d,3)if(ck(j+d-1,X)&&land[i][j+d-1]==0)
			c[i+1][j]+=c[i][j+d-1];
			if(i>0&&land[i-1][j]==2)c[i+1][j]+=c[i-1][j];
		}
		ans=0;
		rep(i,X)ans+=c[Y-1][i]+(Y>1&&land[Y-2][i]==2?c[Y-2][i]:0);
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;
#define rep(i,b) for(int i=0; i<(int)(b); i++)

int solve(string const& s){
    int ans=0;
    rep(i,s.size()/2){
        int j=s.size()-i-1;
        if(s[i]=='('){
            if(s[j]==')') continue;
            else ans++;
        } else if(s[i]==')'){
            if(s[j]=='(') continue;
            else ans++;
        } else {
            if(s[j]==s[i]) continue;
            else ans++;
        }
    }
    if(s.size()%2==1){
        char c=s[s.size()/2];
        if(c=='(' || c==')') ans++;
    }
    return ans;
}

int main(){
    string s;
    while(cin>>s){
        cout << solve(s) << endl;
    }
}

Measured memory_bytes: 1188
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;

set<lint> decomp(lint N){
    set<lint> res;
    for(int i=2;i<=1100000;i++){
        while(N%i==0) N/=i,res.insert(i);
        if(N==1) break;
        if(i==1100000) res.insert(N);
    }
    return res; 
}

int main(void){
    lint A,B;
    int ans=0;
    cin >> A >> B;
    set<lint> Adiv=decomp(A),Bdiv=decomp(B);
    Adiv.insert(1),Bdiv.insert(1);
    lint x=Adiv.size();
    auto itr=Adiv.begin();
    for(int i=0;i<x;i++){
        if(Bdiv.count(*itr)) ans++;
        itr++;
    }
    cout << ans << endl;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	set<int> s;
	for (int i = 1; i <= 3; i++) {
		s.insert(i);
	}
	s.erase(a);
	s.erase(b);
	cout << *s.begin();
	return 0;
}


Measured memory_bytes: 3576
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int N = sc.nextInt();
      int L = sc.nextInt();
      ArrayList<String> array = new ArrayList<>();
      for(int i = 0; i < N; i++){
        array.add(sc.next());
      }
      
      // 文字列生成
      String result = "";
      for(int i = 0; i < N; i++){
        String min = getMinStr(array);
        result += min;
        array.remove(array.indexOf(min));
      }
      
      // 出力
      System.out.println(result);
    }
    
    // リスト内の最小文字列を探索する関数
    public static String getMinStr(ArrayList<String> array){
      String min = array.get(0);
      for(int i = 0; i < array.size(); i++){
        String target = array.get(i);
        if(min.compareTo(target) > 0){
          min = target;
        }
      }
      
      return min;
    }

}

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

#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = INF + 7;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 5e3 + 5;

int DP[N][N], PW[N];

int Power(int a, int b) {
	int res = 1;
	for (; b; b >>= 1, a = 1LL * a * a % MOD) if (b & 1) res = 1LL * res * a % MOD;
	return res;
}

int main() {
 
	sync;

	PW[0] = 1;
	for (int i = 1; i < N; i++) PW[i] = 2LL * PW[i - 1] % MOD;
	DP[0][0] = 1;
	for (int i = 1; i < N; i++) for (int j = 0; j <= i; j++) {
		if (j) DP[i][j] = 2LL * DP[i - 1][j - 1] % MOD;
		else DP[i][j] = DP[i - 1][j];
		if (j + 1 < N) DP[i][j] = (DP[i][j] + DP[i - 1][j + 1]) % MOD;
	}
	
	int n; cin >> n;
	string s; cin >> s;
	cout << 1LL * DP[n][sz(s)] * Power(PW[sz(s)], MOD - 2) % MOD << endl;

	return 0;
}


Measured memory_bytes: 96512
using System;
using System.Collections.Generic;
class Program
    {
    	static void Main(string[] args)
    	{
            int n = int.Parse(Console.ReadLine());
            string[] s1 = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i<n; i++)
            {
                a[i] = int.Parse(s1[i]);
            }
            int ans = 0;
            for (int i=0; i+2 < n; i++)
            {
                if (a[i] < a[i+1] && a[i+1] < a[i+2]) ans++;
                else if (a[i] > a[i+1] && a[i+1] > a[i+2]) ans++;
            }
            Console.WriteLine(ans);

            
            
        }
    }
    //mcs Main.cs
    //mono Main.exe

Measured memory_bytes: 11092
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        for (int i = 0; i < m; i++) {
            n -= Integer.parseInt(sc.next());
        }
        if (n <= -1) {
            System.out.println("-1");
        } else {
            System.out.println(n);
        }
        sc.close();
    }
}


Measured memory_bytes: 41436
import math
N = int(input())
A = list(map(int, input().split()))

sum = 0
for i in range(len(A)):
    sum += A[i]
#print(sum)
check_sum = 0
for i in range(len(A)):
    check_sum += A[i]
    if check_sum == sum/2:
        print(0)
        exit()
    if check_sum > sum / 2:
        if i+ 1 == len(A):
            print(A[i] - (check_sum - A[i]))
            exit()
        else:
            if (abs(2 * (check_sum - A[i]) - sum) < abs(2 * check_sum - sum)):
                print(abs(2 * (check_sum - A[i]) - sum))
                exit()
            #print("chek")
            else:
                print(abs(2 * check_sum - sum))
                exit()


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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>         vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)            for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

ll xp(ll b, ll e) {
  if (e == 0) return 1;
  ll c = xp(b, e >> 1);
  c *= c;
  c %= mod;
  if (e & 1) c *= b, c %= mod;
  return c;
}

int main() {
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

  ll n;
  cin >> n;
  ll ans = xp(10, n);
  ans -= xp(8, n) + 2 * (xp(9, n) - xp(8, n));
  ans = (ans % mod + mod) % mod;
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}

void solve(){
	long long x;
	cin>>x;
	ll ans=(x/500)*1000+((x%500)/5)*5;
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

struct Node {
	int key;
	Node *right, *left, *parent;
};

Node *root, *NIL;

Node *find(Node *u,int k){
	while(u != NIL && k != u->key){
		if(k < u->key) u = u->left;
		else u = u->right;
	}
	return u;
}

void insert(int k)
{
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL)
	{
		y = x;
		if(z->key < x->key){
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if(y == NIL){
		root = z;
	} else {
		if(z->key < y->key){
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

void inorder(Node *u)
{
	if(u == NIL) return;
	inorder(u->left);
	printf(" %d",u->key);
	inorder(u->right);
}

void preorder(Node *u)
{
	if(u == NIL) return;
	printf(" %d",u->key);
	preorder(u->left);
	preorder(u->right);
}

int main()
{
	int n,i,x;
	string com;
	
	scanf("%d",&n);
	
	for(i = 0; i < n; i++)
	{
		cin >> com;
		if(com[0] == 'f')
		{
			scanf("%d",&x);
			Node *t = find(root,x);
			if(t != NIL) printf("yes\n");
			else printf("no\n");
		} else if(com == "insert"){
			scanf("%d",&x);
			insert(x);
		} else if(com == "print"){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	
	return 0;
}


Measured memory_bytes: 21924
#include <iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long n,m;
  cin >> n >> m;
  if(2*n>=m) {
    cout << m/2 << endl;
  }
  else {
    cout << (2*n+m)/4 << endl;
  }
}

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

int main(){
	string s;
	int x,y;
	cin >> s >> x >> y;
	int n = s.length();
	
	vector<vector<int> > num(2);
	num[0].push_back(x);
	num[1].push_back(y);
	int ptr = 0;
	if(s[0]=='F'){
		for(; ptr<n && s[ptr]=='F'; ptr++){
			num[0][0]--;
		}
	}
	if(num[0][0]<0) num[0][0] = -num[0][0];
	if(num[1][0]<0) num[1][0] = -num[1][0];
	
	int dir = 0; //0:hori, 1:vert
	for( ; ptr<n; ptr++){
		if(s[ptr]=='F'){
			num[dir].back()++;
		}else{
			dir = 1-dir;
			num[dir].push_back(0);
		}
	}
	
	bool flag = true;
	for(int r=0; r<2; r++){
		int sum=0;
		for(int i=0; i<(int)num[r].size(); i++){
			sum += num[r][i];
		}
		if(sum%2!=0){
			flag = false;
			break;
		}
		sum /= 2;
		
		vector<bool> dp(sum+1, false);
		dp[0] = true;
		for(int i=0; i<(int)num[r].size(); i++){
			for(int j=sum; j>=0; j--){
				if(dp[j] && j+num[r][i] <= sum){
					dp[j+num[r][i]] = true;
				}
			}
		}
		if(!dp[sum]){
			flag = false;
			break;
		}
	}
	
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
{-# LANGUAGE Strict #-}

main :: IO ()
main = do
  s <- getLine
  putStrLn $ if solve s then "Yes" else "No"

solve :: String -> Bool
solve xs = isPalindrome xs && isPalindrome ys && isPalindrome zs
  where ys = take (n `div` 2) xs
        zs = drop (n `div` 2 + 1) xs
        n = length xs

isPalindrome :: String -> Bool
isPalindrome xs = xs == reverse xs


Measured memory_bytes: 3784
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import math

N, M = list(map(int, sys.stdin.readline().rstrip().split()))


Ss = set()
Es = set()
for _ in range(M):
    a_orig, b_orig = list(map(int, sys.stdin.readline().rstrip().split()))
    for a, b in [(a_orig, b_orig), (b_orig, a_orig)]:
        if a== 1:
            Ss.add(b)
        if a == N:
            Es.add(b)

if len(Ss.intersection(Es)):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
exit(0)


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

int main()
{
  while (1)
  {
    int H, W;
    cin >> H >> W;
    if (H == 0 && W == 0)
    {
      break;
    }
    for (int i = 0; i < H; i++)
    {
      for (int j = 0; j < W; j++)
      {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
}


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

bool f(int& c, vector<pair<int, int>>& p) 
{
	for (auto& i : p) {
		if ((1 << (i.first - 1)) & c) {
			if (i.second == 0) {
				return false;
			}
		}
		else {
			if (i.second == 1) {
				return false;
			}
		}
	}
	return true;
}

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

	vector<vector<pair<int, int>>> axy(n);

	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		axy[i].resize(a);
		for (int j = 0; j < a; ++j) {
			cin >> axy[i][j].first >> axy[i][j].second;
		}
	}

	int c = 1;
	int end = pow(2,n);
	int ret = 0;
	while (c < end) {
		bool isOK = true;
		int count = 0;
		for (int i = 0; i < n; ++i) {
			if ((1 << i) & c) {
				++count;
				if (!f(c, axy[i])) {
					isOK = false;
					break;
				}
			}
		}

		if (isOK) {
			if (ret < count) {
				ret = count;
			}
		}

		++c;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include<complex>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> pr;
typedef complex<double> com;


int main(){
	string s, t;
	cin >> s >> t;
	string ans = "";
	rep(i, s.size() + t.size()) {
		if (i % 2 == 0) {
			ans += s[i / 2];
		}
		else {
			ans += t[(i-1) / 2];
		}
	}
	cout << ans;
	return 0;
}
//Ctrl+Aを使わない

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

int main() {
  ll A[2];
  cin >> A[0] >> A[1];
  A[0]--;
  for (int i = 0; i < 2; i++) {
    if (A[i] <= 0)
      A[i] = 0;
    else if (A[i] == 1)
      A[i] = 1;
    else if (A[i] % 4 == 0) {
      A[i] = A[i];
    } else if (A[i] % 4 == 1) {
      A[i] = 1;
    } else if (A[i] % 4 == 2) {
      A[i] = A[i] + 1;
    } else if (A[i] % 4 == 3) {
      A[i] = 0;
    }
  }
  cout << (A[0] ^ A[1]) << endl;
}

Measured memory_bytes: 256
//ABC062B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int h, w;
	cin >> h >> w;
	vector<vector<char>> a(h,vector<char>(w));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> a.at(i).at(j);
		}
	}
	for(int i=0;i<w+2;i++){
		cout << "#";
	}
	cout << endl;
	for(int i=0;i<h;i++){
		cout << "#";
		for(int j=0;j<w;j++){
			cout << a.at(i).at(j);
		}
		cout << "#" << endl;
	}
	for(int i=0;i<w+2;i++){
		cout << "#";
	}
	return 0;
}

Measured memory_bytes: 256
from collections import deque

n, q = map(int, input().split())
que = deque([])
for _ in range(n):
    key, value = input().split()
    que.append([key, int(value)])
    
t = 0
que_2 = []
while True:
    # print(que)
    if que[0][1] > q:
        t += q
        new = [que[0][0], que[0][1] - q]
        que.popleft()
        que.append(new)
    else:
        t += que[0][1]
        new_2 = [que[0][0], t]
        que_2.append(new_2)
        que.popleft()
        if len(que) == 0:
            break
        
for i in range(n):
    print(que_2[i][0], que_2[i][1])


Measured memory_bytes: 15076
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
int main(){
    string s;int counter=0;
    cin>>s;
    int n=s.size();
    if(s[0]!='A'){
        cout<<"WA"<<endl;return 0;
    }
    if(s[1]-'a'<0){
        cout<<"WA"<<endl;return 0;
    }
    for(int i=2;i<n-1;i++){
        int num=s[i]-'a';
        if(num<0){
            if(s[i]=='C'&&counter==0)
            counter++;
            else{
                cout<<"WA"<<endl;return 0;
            }
        }
    }
    if(counter==0){
        cout<<"WA"<<endl;return 0;
    }
    if(s[n-1]-'a'<0){
        cout<<"WA"<<endl;return 0;
    }
    cout<<"AC"<<endl;
    return 0;    
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    int count = 0;
    while(count < n){
        ans += min(ans,k);
        count += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    string st[3];
    REP(i,3){
        cin>>st[i];
    }
    int ans=0;
    REP(i,n){
        map<char,int> ma;
        REP(j,3){
            ma[st[j][i]]++;
        }
        ans+=ma.size()-1;
    }
    cout<<ans<<endl;
    return 0;
}

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() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  string c1;
  string c2;
  string c3;

  cin >> c1 >> c2 >> c3;

  string ans = "";
  ans += c1.at(0);
  ans += c2.at(1);
  ans += c3.at(2);

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


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MAXQ=100000;
const int TMAX=1000000000;
typedef struct Q { int t,s,idx; } Q;
bool operator<(const Q &a,const Q &b) { return a.s<b.s; }

int total;
int n;
int t[MAXN+3];
int nq;
Q q[MAXQ];

int beforezero[MAXN+3];
int delta[MAXN+3];
int lim[MAXN+3];
int ans[MAXQ];

void run() {
	scanf("%d%d",&total,&n);
	t[0]=0; ++n; FOR(i,1,n) scanf("%d",&t[i]); t[n++]=TMAX+1; t[n++]=TMAX+2;
	scanf("%d",&nq); REP(i,nq) scanf("%d%d",&q[i].t,&q[i].s),q[i].idx=i;
	sort(q,q+nq);

	beforezero[0]=beforezero[1]=0; FOR(i,2,n) beforezero[i]=i%2==0?min(total,beforezero[i-1]+(t[i]-t[i-1])):max(0,beforezero[i-1]-(t[i]-t[i-1]));
	delta[0]=0,lim[0]=total; int at=0;
	REP(i,nq) {
		while(at+2<n&&min(lim[at],delta[at]+q[i].s)-(t[at+1]-t[at])>=0) {
			delta[at+1]=delta[at]-(t[at+1]-t[at]);
			lim[at+1]=lim[at]-(t[at+1]-t[at]);
			delta[at+2]=delta[at+1]+(t[at+2]-t[at+1]);
			lim[at+2]=min(total,lim[at+1]+(t[at+2]-t[at+1]));
			at+=2;
		}
		int pos=lower_bound(t,t+n,q[i].t)-t; if(t[pos]>q[i].t) --pos; int dt=q[i].t-t[pos];
		int posval=pos>at?beforezero[pos]:min(lim[pos],delta[pos]+q[i].s);
		ans[q[i].idx]=pos%2==0?max(0,posval-dt):min(total,posval+dt);
	}

	REP(i,nq) printf("%d\n",ans[i]);
}

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


Measured memory_bytes: 4352
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[fastout]
fn main() {
    input! {
      n:usize
    }

    let mut ans = vec![0; n + 1];

    for x in 1..=n {
        for y in 1..=n {
            if x * x + y * x > n {
                break;
            }
            for z in 1..=n {
                let buf = x * x + y * y + z * z + x * y + y * z + z * x;
                if buf > n {
                    break;
                }
                ans[buf] += 1;
            }
        }
        if x * x > n {
            break;
        }
    }
    for i in ans.iter().skip(1) {
        println!("{}", i);
    }
}


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

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

int main(){
	
	for(int n,w,d;cin>>n>>w>>d,w;){
		vector<PP>V;
		V.push_back(PP(0,P(w,d)));
		for(int k=1;n--;k+=5){
			int p,s;
			cin>>p>>s;
			V[p-1].first=1145141919;
			w=V[p-1].second.first;
			d=V[p-1].second.second;
			s%=(w*2+d*2);
			int x=0,y=0;
			if(s<w)x=s;
			else if(s<w+d)y=s-w;
			else if(s<w+d+w)x=w-(s-w-d);
			else y=d-(s-w-d-w);
			if(x==0){
				V.push_back(PP((w*y<w*(d-y)?k:k+1),P(w,y)));
				V.push_back(PP((w*y<w*(d-y)?k:k+1),P(w,d-y)));
			}
			else{
				V.push_back(PP((x*d<(w-x)*d?k:k+1),P(x,d)));
				V.push_back(PP((x*d<(w-x)*d?k:k+1),P(w-x,d)));
			}
			sort(V.begin(),V.end());
		}
		vector<int>A;
		for(int i=0;i<V.size();i++){
			if(V[i].first==1145141919)continue;
			A.push_back(V[i].second.first*V[i].second.second);
		}
		sort(A.begin(),A.end());
		for(int i=0;i<A.size();i++)cout<<A[i]<<" \n"[i+1>=A.size()];
	}
	
	return 0;
}


Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
#define REP(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    vector<int> n(3);
    REP(i, 3) cin >> n[i];
    
    sort(n.rbegin(), n.rend());
    
    cout << 10*n[0] + n[1] + n[2] << endl;

}

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

int main(){
	std::vector<int >data;
	for (int i = 0; i <10; i++){
		data.push_back(i);
		std::cin>>data[i];
	}
	std::sort(data.begin(), data.end(),std::greater<int>());
	for (int j = 0; j < 3; j++)
		std::cout << data[j] << std::endl;
	return 0;
}


Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	int H, W;
	while (true)
	{
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		REP(h, H)
		{
			REP(w, W)
			{
				if (h > 0 && h < H - 1 && w>0 && w < W - 1)
				{
					cout << '.';
				}
				else
				{
					cout << '#';
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <cstdio>
#include <string>
#include <stdlib.h>
#include <set>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <math.h>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
#define fors(i, s) for (auto i = (s).begin(); i != (s).end(); ++i)
#define all(x) (x).begin(), (x).end()
//#define INTERACTIVEEE



void solve2() {

}


void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n - 1);
    forn(i, n) cin >> a[i], a[i]--;
    forn(i, n) cin >> b[i];
    forn(i, n - 1) cin >> c[i];
    int ans = 0;
    int prev = -5;
    forn(i, n) {
        if (prev + 1 == a[i]) {
            ans += b[a[i]] + c[prev];
        }
        else {
            ans += b[a[i]];
        }
        prev = a[i];
    }
    cout << ans << "\n";
}



int32_t main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#if defined(SUPER_DEFINE) && !defined(INTERACTIVEEE)
    assert(freopen("input.txt", "r", stdin));
    while (!cin.eof()) {
        solve();
        cout << "\n\n";
        string s = "#";
        do getline(cin, s);
        while(!cin.eof() && !s.empty());
        while(isspace(cin.peek())) cin.get();
    }
#else
    solve();
#endif
    return 0;
}

Measured memory_bytes: 256
program test
implicit none
integer(8) :: i,j,k,n,m,ii
integer(8) :: x(1000),y(1000),z(1000),value(1000)
integer(8),parameter :: ten = 10
integer(8) :: dp(0:1000,0:1000)=0,value_max=0
integer(8) :: x_sig(8) = (/-1,-1,-1,-1, 1, 1, 1, 1/)
integer(8) :: y_sig(8) = (/-1,-1, 1, 1,-1,-1, 1, 1/)
integer(8) :: z_sig(8) = (/-1, 1,-1, 1,-1, 1,-1, 1/)

read(*,*) n,m

do i=1,n
	read(*,*) x(i),y(i),z(i)
enddo


do ii= 1,8
	dp(0:1000,0) = 0
	dp(0:1000,1:1000) = ten ** 15 * -1
	do i=1,n
		value(i) = x_sig(ii)*x(i) + y_sig(ii)*y(i) + z_sig(ii)*z(i)
	enddo
	
	do i=1,n
		do j=1,m
			dp(i,j) = max(dp(i-1,j) , dp(i-1,j-1)+value(i))
		enddo
	enddo
	
	value_max = max(value_max,dp(n,m))
	
enddo

write(*,*) value_max


end program

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>

int numOfDivisor(int n) {
    int result = 1;

    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            result *= 2;
        }
    }

    return result;
}

int main() {
    int N;
    std::cin >> N;
    int cnt = 0;
    for (int i = 1; i <= N; ++i) {
        if (i % 2 == 1) {
            if (numOfDivisor(i) == 8) {
                cnt += 1;
            }
        }
    }
    std::cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b;
    cin >> a >> b;
    a += b;
    int x = 0;
    rep(i,a.size()){
        x *= 10;
        x += (a[i] - '0');
    }
    int y;
    for(y = 1; (y+1)*(y+1) <= x; ++y) ;
    if(y*y == x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

using namespace std;

typedef int in;
#define int long long

map<int,bool> vis;
int ans = 1;

void fun(int n){
    if(n == 1){
        return;
    }
    for(int i = 2 ; i * i <= n ; i ++){
        if(n % i == 0){
            if(!vis[i]){
                ans ++;
            }
            vis[i] = 1;
            fun(n / i);
            return;
            //cout << n << endl;
        }
    }
    if(!vis[n]){
        ans ++;
    }
}

in main() {
    int a,b;
    cin >> a >> b;
    int n = __gcd(a,b),m = n;
    /*for(int i = 2 ; i <= m ; i ++){
        if(n % i == 0){
            if(!vis[i]){
                ans ++;
            }
            vis[i] = 1;
            n /= i;
            i = 2;
            //cout << n << endl;
        }
    }
    //cout << m << endl;*/
    fun(m);
    cout << ans << endl;
    return 0;
}


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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update

#define rep(i,n) for(i=1;i<=n;i++)
#define Rep(i,n) for(i=0;i<n;i++)
#define For(i,a,b) for(i=a;i<=b;i++)

#define pb(x) push_back(x)
#define sz(x) x.size()

#define mem(ara,val) memset(ara,val,sizeof(ara))
#define eps 1e-11

#define si(x) scanf("%d",&x)
#define sii(x,y) scanf("%d %d",&x,&y)
#define siii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sll(x,y) scanf("%lld %lld",&x,&y)
#define slll(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define ss(ch) scanf("%s",ch)
#define pi(x) printf("%d",x)
#define pii(x,y) printf("%d %d",x,y)
#define piii(x,y,z) printf("%d %d %d",x,y,z)
#define pl(x) printf("%lld",x)
#define pll(x,y) printf("%lld %lld",x,y)
#define plll(x,y,z) printf("%lld %lld %lld",x,y,z)
#define ps(ch) printf("%s",ch)
#define Afridi 0
#define NL printf("\n")
#define debug(x) printf("wow  %d !!\n",x)
#define Max 200005
#define INF (LL)1e18
#define mod 1000000007
#define un(x) x.erase( unique( x.begin() , x.end() ) , x.end() )
#define pii pair<int,int>
#define _mp make_pair

#define FI freopen("in.txt","r",stdin)

#define D(x) cout << #x << " = " << (x) << endl
#define DD(x,y) cout << #x << " = " << x << "   " << #y << " = " << y << endl

typedef long long LL;
typedef unsigned long long ULL;

using namespace std;


LL bigmod(LL b,LL p,LL m)
{
    if(p == 0)return 1;
    LL my = bigmod(b,p/2,m);
    my*=my;my%=m;
    if(p & 1)my*=b,my%=m;
    return my;
}
int setb(int n,int pos){return n=n | (1 << pos);}
int resb(int n,int pos){return n=n & ~(1 << pos);}
bool checkb(int n,int pos){return (bool)(n & (1 << pos));}

LL ara[5];
LL lol[] = {0,1,2,4,8};
LL table[5][5];
LL n;

///1 2 4 8

int main()
{
	//FI;
	LL i,j;
    rep(i,4)sl(ara[i]);
    sl(n);
    n *= 4;
    rep(i,4)
    {
		rep(j,4)
		{
			if( i == j ) table[i][j] = ara[i];
			else if( j < i ) table[i][j] = -1;
			else table[i][j] = table[i][j-1] * 2;
		}
    }
    LL cur = n,ret = 0;
	for(LL j = 4; j >= 1; j--)
	{
		LL item = cur / lol[j];
		LL my = -1;
		rep(i,4)
		{
			if( table[i][j] == -1 ) continue;
			if( my == -1 ) my = table[i][j];
			else my = min( my , table[i][j] );
		}
		ret += ( item * my );
		cur -= item * lol[j];
	}
	pl(ret); NL;
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>; 
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>;

int main() {
    ll N, M;
    cin >> N >> M;
    vll G(N);
    rep(i, M){
        ll A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }

    queue<ll> q;
    vl ans(N, -1);
    ans[0] = 0;
    q.push(0);
    while(!q.empty()){
        ll v = q.front();
        q.pop();
        for(auto nv : G[v]){
            if(ans[nv] != -1) continue;
            ans[nv] = v;
            q.push(nv);
        }
    }

    if(G[0].size() == 0){
        cout << "No";
        return 0;
    }
    cout << "Yes" << endl;
    FOR(i, 1, N){
        cout << ans[i]+1 << endl;
    }


}

Measured memory_bytes: 15976
s = input()
if s[0] != 'A':
    print("WA")
    exit()
cnt = 0
for i in range(2, len(s) - 1):
    if s[i] == 'C':
        cnt += 1
s = s.replace('A', '', 1)
s = s.replace('C', '', 1)
if not s.islower():
    print("WA")
    exit()
if cnt != 1:
    print("WA")
else:
    print("AC")


Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()
	//lastday := 5000 * 1000 * 1000 * 1000 //5*10^12
	s := nextStr()
	k := nextInt64()

	// 1なら終了
	if k <= int64(len(s)) {
		only1 := true
		for i := 0; int64(i) < k; i++ {
			if s[i] != '1' {
				only1 = false
			}
		}
		if only1 == true {
			fmt.Println(1)
			return
		}
	}

	for i := 0; i < len(s); i++ {
		if s[i] != '1' {
			fmt.Println(string(s[i]))
			return
		}
	}

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}
func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    int N, Q;
    cin >> N >> Q;
    vector<ll> a(N + 1, 0);
    for (int i = 1; i <= N; i++)
    {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    while (Q--)
    {
        ll x;
        cin >> x;
        ll ret = 0;
        for (int i = 1; i <= N; i++)
        {
            auto itr = lower_bound(a.begin(), a.end(), a[i] - x);
            ret += distance(itr, a.begin() + i);
        }
        cout << ret << endl;
    }
}



Measured memory_bytes: 3564
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, ll> state;
typedef vector<vector<ll>> matrix;

void solve() {
  ll w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << (w*h)/2 << ".";
  if(w%2 && h%2) cout << "5";
  else cout << "0";
  if(2*x==w && 2*y==h) {
    cout << " 1\n";
  }
  else {
    cout << " 0\n";
  }
}

void casesolve() {
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 256