akhauriyash/Code-Regression huggingface dataset:
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 210;
const ll Mod = 998244353;

int n;
ll pw[maxn];
struct point
{
	int x,y;
}p[maxn]; 
bool v[maxn][maxn];

bool judge(point x,point y,const point z)
{
	x.x-=z.x; x.y-=z.y;
	y.x-=z.x; y.y-=z.y;
	return (x.x*y.y-x.y*y.x)==0;
}
ll ans;

int main()
{
	pw[0]=1ll;
	for(int i=1;i<maxn;i++) pw[i]=pw[i-1]*2ll%Mod;
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&p[i].x,&p[i].y);
	ans=pw[n];
	
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++) 
		{
			bool flag=true;
			for(int k=i+1;k<j;k++) if(judge(p[i],p[k],p[j])) {flag=false; break;}
			for(int k=1;k<i;k++) if(judge(p[k],p[i],p[j])) {flag=false; break;}
			if(!flag) continue;
			int ct=2;
			for(int k=j+1;k<=n;k++) if(judge(p[i],p[j],p[k])) ct++;
			(ans-=pw[ct]-ct-1)%=Mod;
		}
	}
	
	ans=(ans-n-1+Mod)%Mod;
	printf("%lld\n",ans);
	
	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(){
  long long H; cin >> H;
  long long cnt = 0;
  long long ans = 1;
  long long ans_pre = 1;

  for (long long i = 0; i < 10000000000000000; i++)
  {
    cnt++;
    if (H == 1)
    {
      break;
      }
    else {
      H = H / 2;
    }
  }

  for (long long i = 0; i < cnt-1; i++){
    ans_pre = ans_pre*2;
    ans = ans + ans_pre;
  }
  cout << ans << endl;
}


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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
const double PI = 3.141592653589793238462643383279;
const int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template<typename T, typename U> inline bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> inline bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
struct Init {
    Init() {
        cout << fixed << setprecision(20);
    };
} init;

int N;
int S[330000];
multiset<int> st;
signed main() {
    int N;
    cin >> N;
    for (int i = 0; i < (1 << N); i++) {
        cin >> S[i];
        st.insert(-S[i]);
    }
    sort(S, S + (1 << N));
    priority_queue<int> next;
    next.push(-S[(1 << N) - 1]);
    st.erase(st.find(-S[(1 << N) - 1]));
    for (int i = 0; i < N; i++) {
        priority_queue<int> cur = next;
        priority_queue<int> tmp;
        while (!cur.empty()) {
            int cc = cur.top();
            cur.pop();
            tmp.push(cc);
            auto it = st.upper_bound(cc);
            if (it == st.end()) {
                cout << "No" << endl;
                return 0;
            } else {
                tmp.push(*it);
                st.erase(it);
            }
        }
        next = tmp;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 20600
const find = (val) =>{
const base ='ATCG'
var count = 0
var hit = []
val.forEach((ele,index) =>{
    if(base.includes(ele)){
    	count++
        if(val.length >= index){
        	hit.push(count)
        }
    }else{
      	hit.push(count)
    	count = 0
    }
})
return hit.sort((a,b)=>{return b-a})[0]
}

const main = (s) => {
if(s){
const val = s.split("")
console.log(find(val))
}else{
console.log(0)
}
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim())

Measured memory_bytes: 11468
n=int(input())
A=0
W=0
T=0
R=0
for i in range(n):
	a=input()
	if a=='AC':
		A+=1
	if a=='WA':
		W+=1
	if a=='TLE':
		T+=1
	if a=='RE':
		R+=1
print('AC x '+str(A))
print('WA x '+str(W))
print('TLE x '+str(T))
print('RE x '+str(R))

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

string s[700];

int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>s[i];
    int cnt=0;
    rep(i,n){
        bool flag=true;
        rep(j,n){
            rep(k,n)if(s[j][(i+k)%n]!=s[k][(j+i)%n]){
                flag=false;
                break;
            }
            if(!flag) break;
        }
        if(flag) cnt+=n;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}


int main(){
    int n;
    cin >> n;
    vector<pair<double, double>> v(n);

    REP(i,n){
        cin >> v[i].first >> v[i].second;
    }
    vector<int> m(n);
    REP(i,n){
        m[i] = i;
    }
    double sum = 0,ans = 0;
    double a,b,x;
    int cnt = 0;
    do{
        sum = 0;
        cnt ++;
        REP(i,m.size()-1){
            a = v[m[i]].first - v[m[i+1]].first;
            b = v[m[i]].second - v[m[i+1]].second;
            x = (a*a) + (b*b);
            x = sqrt(x);
            sum += x;
        }
        ans += sum;
        
        
        
    }while(next_permutation(m.begin(), m.end()));

    printf("%8f\n",ans/cnt);


}



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

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

    int d, n;
    cin >> d >> n;

    int ans;
    bool j = n < 100;
    if(d == 0) ans = j ? n : 101;
    if(d == 1) ans = j ? n * 100 : 10100;
    if(d == 2) ans = j ? n * 10000 : 1010000;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int A,B,C;
  cin >> A >> B >> C ;
  if(A*B == C){
	cout << C << endl;
  }
  else if(A*B > C){
    cout << C << endl;
  }
  
  else if(A*B < C){
    cout << A*B << endl;
  }
  
  
}

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; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向
string s,t;
void input(){
  cin >> s >> t;  
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  input();
  int sz = s.size();
  int tz = t.size();
  if(sz<tz) cout << "UNRESTORABLE" << endl;
  else{
    int i;
    bool flg = false;
    for(i=sz-tz;i>=0;i--){
      int cnt = 0;
      for(int j=0;j<tz;j++)if(s[i+j]==t[j] || s[i+j]=='?')cnt++;
      if(cnt==tz){
        flg=true;
        break;
      }
    }
    if(!flg){
      cout << "UNRESTORABLE" << endl;
      return 0;
    }
    string ans = s.substr(0,i) + t + s.substr(i+tz);
    int az = ans.size();
    for(int i=0;i<az;i++)if(ans[i]=='?')ans[i]='a';
    cout << ans << endl;
  }
  return 0;
}


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

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

#define MAXK 61
// #define MAXK 10

int solve(){
  int N,K;cin>>N>>K;
  vector<int> A(N);
  map<int, vi> E;
  map<int, int> nex;
  rep(i, N) {
    cin>>A[i];
    if (E.find(A[i]) != E.end()){
      nex[E[A[i]][sz(E[A[i]])-1]] = i;
    }
    E[A[i]].pb(i);
  }
  dump(A);
  dump(E);
  dump(nex);

  vector<vector<pii>> db(N, vector<pii>(MAXK, mp(0,0)));
  rep(i, N){
    if (nex.find(i)!=nex.end()){
      int ni = (nex[i]+1)%N;
      db[i][0] = mp(ni, (ni==0?1:0));
    }
    else{
      int ni = (E[A[i]][0]+1)%N;
      int k = 1;
      if (ni==0) k++;
      db[i][0] = mp(ni, k);
    }
  }

  rep(j, 1, MAXK){
    rep(i, N){
      int c,k;
      tie(c,k) = db[i][j-1];
      int c2,k2;
      tie(c2,k2) = db[c][j-1];
      db[i][j] = mp(c2, k+k2);
    }
  }
  // dump(db);

  int r = K;
  int c = 0;
  while(true){
    rep(j, 0, 61){
      if (db[c][j+1].second < r) continue;
      else{
        int now,k;
        tie(now,k) = db[c][j];
        if (k>=r) break;
        r -= k;
        c = now;
        break;
      }
    }
    // dump(c, r);
    if (r==1) break;
  }

  vi ans;
  rep(i, c, N){
    if (nex.find(i)!=nex.end()){ i = nex[i]; }
    else{ ans.pb(A[i]); }
  }
  rep(i, sz(ans)) cout << ans[i] << (i!=sz(ans)-1 ? " " : "\n");

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


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

int main() {
  //円の座標の上下左右にｒを足した座標がすべて０以上で
  //x,y座標が長方形の座標までの中にあればYes、違えばNo
  int W,H,x,y,r;
  cin>>W>>H>>x>>y>>r;
  if(x-r>=0&&x+r<=W&&y-r>=0&&y+r<=H){cout<<"Yes"<<endl;}
   else{cout<<"No"<<endl;}
  return 0;
}


Measured memory_bytes: 3120
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
  int n;
  cin>>n;
  ll vec[n][3];
  ll minabs[n];
  for(int i=0;i<n;i++){
    cin>>vec[i][0]>>vec[i][1]>>vec[i][2];
    minabs[i]=min(abs(vec[i][0]),abs(vec[i][1]));
  }
  ll ans[n+1];
  for(int i=0;i<=n;i++){
    ans[i]=1e13;
  }
  int vecb[n];
  int vecc[n];
  ll cost[n];
  ll sum,x;
  for(int bit=0;bit<(1<<n);bit++){
    int t=0;
    for(int i=0;i<n;i++){
      if(bit&(1<<i)){
        vecb[i]=1;
        vecc[t]=i;
        t++;
      }
      else{
        vecb[i]=0;
      }
    }
    if(t==n){
      ans[t]=0;
      continue;
    }
    for(int i=0;i<n;i++){
      cost[i]=minabs[i];
    }
    /*x=0;
    for(int i=0;i<n;i++){
      if(vecb[i]==1){
        vecc[x]=i;
        x++;
      }
    }*/
    for(int bitb=0;bitb<(1<<t);bitb++){
      for(int i=0;i<t;i++){
        if(bitb&(1<<i)){ //縦に引く
          for(int j=0;j<n;j++){
            cost[j]=min(cost[j],abs(vec[j][0]-vec[vecc[i]][0]));
          }
        }
        else{ //横に引く
          for(int j=0;j<n;j++){
            cost[j]=min(cost[j],abs(vec[j][1]-vec[vecc[i]][1]));
          }
        }
      }
      sum=0;
      for(int i=0;i<n;i++){
        sum+=cost[i]*vec[i][2];
        cost[i]=minabs[i];
      }
      ans[t]=min(ans[t],sum);
    }
  }
  
  for(int i=0;i<n+1;i++){
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 3592
#![allow(dead_code, unused_variables, unused_macros, unused_imports)]

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input! {
        n: usize,
        m: usize,
        c: i32,
        b: [i32; m],
        a: [[i32; m]; n],
    }

    let mut ans = 0;
    for i in 0..n {
        let sum = a[i].iter().zip(b.iter()).map(|(a, b)| a * b).sum::<i32>() + c;
        if sum > 0 {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
D,G=map(int, input().split())
G //= 100
dp = [ [ 0 for i in range(1105) ] for i in range(12) ]
for i in range(1,D+1):
  p, c = map(int, input().split())
  c //= 100
  for j in range(1005):
    for k in range(p):
      dp[i][j+k] = max( dp[i][j+k], dp[i-1][j] + k*i)
    dp[i][j+p] = max( dp[i][j+p], dp[i-1][j] + p*i + c)

for i in range(1001):
  if dp[D][i] >= G:
    print(i)
    break

#for j in range(23):
#  print(j,dp[0][j],dp[1][j],dp[2][j])


Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,M;
    cin >> N >> M;
    int a[N],b[N],c[M],d[M];
    for(int i=0;i<N;i++) cin >> a[i] >> b[i];
    for(int i=0;i<M;i++) cin >> c[i] >> d[i];

    int temp;
    
    for(int i=0;i<N;i++){
        int now = abs(a[i]-c[0])+abs(b[i]-d[0]);
        temp = 1;
        for(int j=1;j<M;j++){
            int point = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(now > point){
                now = point;
                temp = j + 1;
            }
        }
            cout << temp << endl;
    }
    
}

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

int main(){
    int N;
    cin >> N;
    vector<string> blue(N);
    for(int i=0;i<N;i++){
        cin >> blue[i];
    }
    int M;
    cin >> M;
    vector<string> red(M);
    for(int i=0;i<M;i++){
        cin >> red[i];
    }
    string word;
    int ans=0,cnt=0;
    for(int i=0;i<N;i++){
        word=blue[i];
        for(int j=0;j<M;j++){
            if(word==red[j])
            cnt--;
        }
        for(int k=0;k<N;k++){
            if(word==blue[k])
            cnt++;
        }
        ans=max(ans,cnt);
        cnt=0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;

public class Main {
    Scanner in = new Scanner(System.in);

    void solve(){
        HashMap<String, ArrayList<String>> map = new HashMap<>();
        while(in.hasNextLine()){
            String[] s = in.nextLine().split(" ");
            if(map.containsKey(s[0])){
                map.get(s[0]).add(s[1]);
            }else{
                map.put(s[0], new ArrayList<>(Arrays.asList(s[1])));
            }
        }
        String[] p = map.keySet().toArray(new String[map.size()]);
        Arrays.sort(p);
        for(String s : p){
            System.out.println(s);
            ArrayList<String> list = map.get(s);
            list.sort(new Comparator<String>(){
                public int compare(String s1, String s2){
                    return Integer.parseInt(s1) > Integer.parseInt(s2) ? 1: -1;
                }   
            });
            System.out.println(String.join(" ", map.get(s)));
        }
    }

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

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

// @@ !! LIM(f:updMaxMin)
// --> f:updMaxMin
// ---- inserted function updMaxMin from util.cc
template<typename T>
bool updMax(T& tmax, const T& x) {
  if (x > tmax) { tmax = x; return true;  }
  else          {           return false; }
}
template<typename T>
bool updMin(T& tmin, const T& x) {
  if (x < tmin) { tmin = x; return true;  }
  else          {           return false; }
}
// ---- end updMaxMin
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  using Pair = pair<ll, ll>;
  ll N; cin >> N;
  vector<Pair> A;
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    A.emplace_back(a, i);
  }
  sort(A.begin(), A.end(), greater<Pair>());
  vector tbl(N+1, vector<ll>(N+1, LLONG_MIN));
  tbl.at(0).at(0) = 0;
  for (ll i = 0; i < N; i++) {
    const auto& prev = tbl.at(i);
    auto& cur = tbl.at(i+1);
    auto [a, k] = A.at(i);
    for (ll j = 0; j <= i; j++) {
      if (j+1 <= N) updMax(cur.at(j+1), prev.at(j) + a * abs(k - (N - j - 1)));
      updMax(cur.at(j), prev.at(j) + a * abs(k - (i-j)));
    }
  }
  ll ans = 0;
  for (ll j = 0; j <= N; j++) updMax(ans, tbl.at(N).at(j));
  cout << ans << endl;

  return 0;
}



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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;

int main() {
	int n;
	cin >> n;
	vi d(n);
	rep(i, 0, n) {
		cin >> d[i];
	}
	set<int> ans;
	rep(i, 0, n) {
		ans.insert(d[i]);
	}
	cout << ans.size() << endl;
	return 0;
}


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


void solve(long long N, std::vector<long long> H){
    int now_max = 0;
    int count = 0;
    for (int i = 0; i < N; i++) {
        if (H[i] >= now_max) {
            count++;
            now_max = H[i];
        }
    }
    cout << count << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, std::move(H));
    return 0;
}
	

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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int f(int n) {
    int res = 0;
    while(n % 2 == 0) {
        n /= 2;
        ++res;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M; cin >> N >> M;
    v<int> A(N); rep(i, N) cin >> A[i];
    rep(i, N) {
        A[i] /= 2;
    }

    int t = f(A[0]);
    rep(i, N) {
        if (f(A[i]) != t) {
            cout << 0 << endl;
            return 0;
        }
        A[i] >>= t;
    }
    M >>= t;

    ll l = 1;
    rep(i, N) {
        l = lcm(l, A[i]);
        if (l > M) {
            cout << 0 << endl;
            return 0;
        }
    }

    M /= l;
    int ans = (M+1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
def read():
  return list(map(int,input().split()))

def ok(width,xs,ws):
  x=0
  for l,r in sorted((x-w,x+w) for x,w in zip(xs,ws)):
    if x<l: return False
    x=max(x,r)
  return width<=x

while 1:
  try:
    n,w,h=read()
    xs,ys,ws=([0]*n for _ in range(3))
    for i in range(n):
      xs[i],ys[i],ws[i]=read()
  except: break
  print("Yes" if ok(w,xs,ws) or ok(h,ys,ws) else "No")

Measured memory_bytes: 34820
def total(num):
    return (1+num) * num // 2

s = input()
length = len(s)

ans = 0
cnt = 0
a = []
bef = ''

for c in enumerate(s):
    if c[0] == 0:
        cnt += 1
        bef = c[1]
        continue

    if c[1] == bef:
        cnt += 1
    else:
        a.append(cnt)
        bef = c[1]
        cnt = 1
a.append(cnt)
#print(a)
aa = [total(i) for i in a]
#print(aa)

if s[0] == '<':
    for i in range(0, len(a)-1, 2):
        if a[i] <= a[i+1]:
            aa[i] -= a[i]
        else:
            aa[i+1] -= a[i+1]
else:
    for i in range(1, len(a)-1, 2):
        if a[i] <= a[i+1]:
            aa[i] -= a[i]
        else:
            aa[i+1] -= a[i+1]

#print(a)
#print(aa)
print(sum(aa))

Measured memory_bytes: 8220
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner scanner = new Scanner(System.in);

        String s = scanner.next();
        String t = scanner.next();
        StringBuilder builder = new StringBuilder();
        for(int i = 0; i < t.length() - 1 ; i++){
            {
                builder.append(t.charAt(i));
            }
        }
        System.out.println(s.equals(builder.toString()) ? "Yes" : "No");

    }
}


Measured memory_bytes: 35516
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for(int i = 0; i < n; i++) {
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        double sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i; j < n-1; j++) {
                int distanceX = x[j+1] - x[i];
                int distanceY = y[j+1] - y[i];
                double distance = distanceX * distanceX + distanceY * distanceY;
                sum += Math.sqrt(distance);
            }
        }
        System.out.println(sum * 2 / n);
    }
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] stones = new int[n];
		int[] dp = new int[n];
		dp[0] = 0;
		for (int i = 0; i < 2; ++i) {
			stones[i] = sc.nextInt();
			if (i > 0) dp[i] = Math.abs(stones[i] - stones[i - 1]);
		}
		for (int i = 2; i < n; ++i) {
			stones[i] = sc.nextInt();
			dp[i] = Math.min(Math.abs(stones[i] - stones[i - 1]) + dp[i - 1], Math.abs(stones[i] - stones[i - 2]) + dp[i - 2]);
		}
		System.out.println(dp[n - 1]);
		
		sc.close();
	}

}


Measured memory_bytes: 49376
n=int(input())

if 1<=n<=9:
        print(n)
elif 10<=n<=99:
        print(9)
elif 100<=n<=999:
        print(9+n-99)
elif 1000<=n<=9999:
        print(909)

elif 10000<=n<=99999:
        print(9+900+n-9999)

elif n==100000:
        print(9+900+n-9999-1)


Measured memory_bytes: 3060
N, K = map(int, input().split())
A = list(map(int, input().split()))

idx_1 = A.index(1)
ckpt = 0
ans = 0
for i in range(0, idx_1 + 1, K - 1):
    ans += 1
    if i <= idx_1 and idx_1 <= i + K - 1:
        ckpt = i + K - 1
        break
if ckpt < N - 1:
    for i in range(ckpt, N, K - 1):
        if len(A[i:i + K]) > 1:
            ans += 1
print(ans)


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

void Main()
{
    int n;
    cin >> n;
    if(n % 1000 == 0){
        cout << 0 << endl;
        return;
    }else{
        cout << 1000 - (n % 1000) << endl;
        return;
    }
}

int main(int argc, char **argv)
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    Main();
    return 0;
}


Measured memory_bytes: 3632
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
 */
//入力終了→Ctrl+D
import java.util.*;
import java.awt.*;
import java.awt.Graphics.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        String s=sc.next();
        char[] e=s.toCharArray();
        String p=sc.next();
        for (int i = 0; i < s.length(); i++) {
            String check="";
            for (int j = 0; j < s.length(); j++) {
                check+=e[(i+j)%s.length()];
            }
            if(check.contains(p)){
                out.println("Yes");
                exit(0);
            }
        }
        out.println("No");
    }
}


Measured memory_bytes: 32508
def mod_pow(a, n, mod):
    """
    二分累乗法による a^n (mod m)の実装
    :param a: 累乗の底
    :param n: 累乗の指数
    :param mod: 法
    :return: a^n (mod m)
    """

    result = 1
    a_n = a
    while n > 0:
        if n & 1:
            result = result * a_n % mod
        a_n = a_n * a_n % mod
        n >>= 1
    return result


def mod_inverse(a, mod):
    """
    フェルマーの小定理による a^-1 ≡ 1 (mod m)の実装
    aの逆元を計算する
    a^-1 ≡ 1 (mod m)
    a * a^-2 ≡ 1 (mod m)
    a^-2 ≡ a^-1 (mod m)
    :param a: 逆元を計算したい数
    :param mod: 法
    :return: a^-1 ≡ 1 (mod m)
    """

    return mod_pow(a=a, n=mod - 2, mod=mod)


def mod_combination(n, k, mod):
    fact_n = 1
    fact_k = 1
    for i in range(k):
        fact_n *= (n - i)
        fact_n %= mod
        fact_k *= (i + 1)
        fact_k %= mod

    fact_n *= mod_inverse(fact_k, mod)
    return fact_n % mod


N, A, B = map(int, input().split(' '))
MOD = 10 ** 9 + 7

print((mod_pow(2, N, MOD) - 1 - mod_combination(N, A, MOD) - mod_combination(N, B, MOD)) % MOD)


Measured memory_bytes: 9244
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        int[] count = new int[26];
        char c;
        String str1, str2, temp;
        for (int i = 0; i < 26; i++) 
            count[i] = 0;
        Scanner sc = new Scanner(System.in);
        str1 = sc.next();
        str2 = sc.next();

        for(int i = 0; i < str1.length(); i++) {
            temp = "";
            for (int j = 0; j < str2.length(); j++) 
                temp += str1.charAt((i+j) % str1.length());
            if (temp.equals(str2)) {
                System.out.println("Yes");
                break;
            } 
            if (i == str1.length() - 1)
                System.out.println("No");
        }
    }
}


Measured memory_bytes: 26552
#include<bits/stdc++.h>
#define MAX (int)(2e6+5)
#define PB push_back
#define MP make_pair
#define ll long long
#define pii pair<long long,long long>
#define sz(a) (int)a.size()
#define sl(a) scanf("%lld",&a)
#define sll(a,b) scanf("%lld%lld",&a,&b)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d%d",&a,&b)
#define p1(a) cout<<"Check "<<a<<endl;
#define p2(a,b) cout<<"Check "<<a<<' '<<b<<endl;
#define p3(a,b,c) cout<<"Check "<<a<<' '<<b<<' '<<c<<endl;
#define forn(i,n) for(int i=0;i<int(n);i++)
#define fore(i,l,n) for(int i=int(l);i<int(n);i++)
#define clr(a) memset(a,0,sizeof(a))
#define MOD (int)(1e7+7)
#define INF (long long)(1e18)

using namespace std;


int main()
{
    //freopen("tt.txt","r",stdin);
    int test=1,i=0,n,m;
    //si(test);
    while(test--){
        ll x;
        cin>>x;
        for(ll i=-1000;i<1001;i++){
            ll num=i*i*i*i*i;
            for(ll j=-1000;j<1001;j++){
                if(num-(j*j*j*j*j)==x){
                    printf("%lld %lld\n",i,j);
                    i=1002,j=1002;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3696
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
print(2**int(log2(N)))


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

#define int long long int
#define ff first
#define ss second
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int cmod = 998244353;
const int N = 1e3 + 5;
const int inf = 1e16 + 2;

int power(int x , int y , int m) {
    int res = 1;
    while(y > 0) {
        if(y & 1) res = (res * x) % m;
        y /= 2;
        x = (x * x) % m;
    }
    return res % m;
}

int get(int x) {
    if(x == 0) return 0;
    int t = __builtin_popcount(x);
    return 1 + get(x % t);
}
void solve(int Case) {
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0 ;
    for(auto x : s) cnt += x - '0';
    int num1 = 0 , num2 = 0 , num = 0;
    for(int i = n - 1 ; i >= 0 ; i --) {
        if(s[i] == '1') {
            if(cnt - 1 > 0)num1 = (num1 + power(2LL , n - i - 1 , cnt - 1)) % (cnt - 1);
            num2 = (num2 + power(2LL , n - i - 1 , cnt + 1)) % (cnt + 1);
            
        }
    }
    
    //cout << num2 << '\n';
    for(int i = 0 ; i < n ; i ++) {
        if(s[i] == '1') {
            if(cnt - 1 == 0) {
                cout << 0 << '\n';
            }
            else {
                
                cout << 1 + get((num1 - power(2 , n - 1 - i , cnt - 1) + cnt - 1) % (cnt - 1)) << '\n';
                
            }
        }
        else {
            
            cout << 1 + get((num2 + power(2 , n - 1 - i , cnt + 1) + cnt + 1) % (cnt + 1)) << '\n';
        }
    }
}
/*
 */

int32_t main()
{
    fastio
    int testcase = 1;
    //cin >> testcase;
    int Case = 1;
    while(testcase --) {
        solve(Case ++);
    }
    return 0;
}
 



Measured memory_bytes: 3716
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    s=SI()
    n=len(s)
    ans=0
    nxt=0
    for i in range(n-1,-1,-1):
        now=int(s[i])+nxt
        if now>5 or (i>0 and now==5 and int(s[i-1])>4):
            nxt=1
            ans+=10-now
        else:
            ans += now
            nxt = 0
    ans+=nxt
    print(ans)

main()

Measured memory_bytes: 5492
A, B = map(int, input().split())

def getPrimeFactors(x):
    anss = []
    while x%2 == 0:
        anss.append(2)
        x //= 2
    for d in range(3, int(x**0.5)+1, 2):
        while x%d == 0:
            anss.append(d)
            x //= d
    if x != 1:
        anss.append(x)
    return anss

PFAs = getPrimeFactors(A) + [1]
PFBs = getPrimeFactors(B) + [1]

setA = set(PFAs)
setB = set(PFBs)

ans = len(setA & setB)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include <ext/rope>

#pragma 03

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define gcd __gcd
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i=0; i<(n); i++)
#define rep1(i, n) for (int i=1; i<=(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl "\n"

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
template<typename _def> using ordered_set=tree<_def, null_type, less<_def>, rb_tree_tag, tree_order_statistics_node_update>;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;

struct store {
    int a, b;
    store(int a, int b): a(a), b(b) {}
    bool operator< (const store& oth) const {return (ll)a*(oth.b+1)>(ll)oth.a*(b+1);}
};

const ll INF=1e18;
ll dp[2][33];

int32_t main() {
    fastio;
    int n, t; cin>>n>>t;
    vector<store> stores;
    vector<store> zeroes;
    rep(i, n) {
        int a, b; cin>>a>>b;
        if(a!=0) stores.eb(a, b);
        else zeroes.eb(a, b);
    }
    sort(all(stores));
    sort(all(zeroes), [&](const store& x, const store& y){return x.b<y.b;});
    rep(i, 2) rep(j, 33) dp[i][j]=INF;
    dp[0][0]=0;
    rep(i, stores.size()) {
        rep(j, 33) dp[(i+1)&1][j]=INF;
        store s=stores[i];
        rep(j, 33) {
            if(dp[i&1][j]==INF) continue;
            dp[(i+1)&1][j]=min(dp[(i+1)&1][j], dp[i&1][j]);
            ll c=(dp[i&1][j]+1)*(s.a+1)+s.b;
            if(c<=t&&j<32) dp[(i+1)&1][j+1]=min(dp[(i+1)&1][j+1], c);
        }
    }
    int ans=0;
    vll pf(zeroes.size()+1, 0);
    rep1(i, zeroes.size()) pf[i]=pf[i-1]+zeroes[i-1].b+1;
	rep(i, 33) {
		ll res=t-dp[stores.size()&1][i];
		if(res<0) continue;
		ans=max(ans, int(upper_bound(all(pf), res)-pf.begin()+i-1));
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    string s;
    cin >> s;
    if (s[0]==s[1] && s[0]==s[2]) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
def q3():
    import itertools
    li = [int(i) for i in list(input())]

    ans_op = None
    ops = list(itertools.product(['+','-'], repeat=3))
    for op in ops:
        tmp_sum = li[0]
        for i, o in enumerate(op):
            if o == '+':
                tmp_sum += li[i+1]
            else:
                tmp_sum -= li[i+1]
        if tmp_sum == 7:
            ans_op = op
            break

    return '{}{}{}{}{}{}{}=7'.format(li[0], op[0], li[1], op[1], li[2], op[2], li[3])


if __name__ == "__main__":
    print(q3())


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

int main()
{
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    s1[0] = toupper(s1[0]);
    s2[0] = toupper(s2[0]);
    s3[0] = toupper(s3[0]);

    cout << s1[0] << s2[0] << s3[0] << endl;
    return 0;
}


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

#define MAX 100005
#define int long long
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int dp[3][100005];

int helper(int arr[][100005], int n, int prevOption, int index){
	if(index == n){
		return 0;
	}
	if(prevOption != -1 && dp[prevOption][index] != -1){
		return dp[prevOption][index];
	}

	int tempAns1 = INT_MIN, tempAns2 = INT_MIN, tempAns3 = INT_MIN;
	if(prevOption == -1){
		tempAns1 = arr[0][index] + helper(arr, n, 0, index + 1);
		tempAns2 = arr[1][index] + helper(arr, n, 1, index + 1);
		tempAns3 = arr[2][index] + helper(arr, n, 2, index + 1);
	}

	if(prevOption == 0){
		tempAns1 = arr[1][index] + helper(arr, n, 1, index + 1);
		tempAns2 = arr[2][index] + helper(arr, n, 2, index + 1);
	}
	if(prevOption == 1){
		tempAns1 = arr[0][index] + helper(arr, n, 0, index + 1);
		tempAns2 = arr[2][index] + helper(arr, n, 2, index + 1);
	}
	if(prevOption == 2){
		tempAns1 = arr[0][index] + helper(arr, n, 0, index + 1);
		tempAns2 = arr[1][index] + helper(arr, n, 1, index + 1);
	}
	if(prevOption != -1){
		dp[prevOption][index] = max(tempAns1, max(tempAns2, tempAns3));
	}
	return max(tempAns1, max(tempAns2, tempAns3));
}

int32_t main(){
	//Initialize DP array with -1.
	for(int i = 0; i < 100005; i++){
		dp[0][i] = -1;
		dp[1][i] = -1;
		dp[2][i] = -1;
	}
	int n;
	cin>>n;
	int arr[3][100005];

	for(int i = 0; i < n; i++){
		cin>>arr[0][i]>>arr[1][i]>>arr[2][i];
	}

	cout<<helper(arr, n, -1, 0);

}

Measured memory_bytes: 15872
# -*- coding: utf-8 -*-
from collections import deque
h,w = map(int, input().split())
s = [input() for _ in range(h)]

if h==1 and w==1:
    print(0)
    exit()

maxr = 0
for hi in range(h):
    for wi in range(w):
        if s[hi][wi]==".":
            maxr += 1

def solve(sh,sw):
    res = -1
    visited = [[False for _ in range(w)] for _ in range(h)]
    visited[sh][sw] = True
    q = deque([(sh,sw,0)])
    while len(q)>0:
        hi,wi,r = q.popleft()
        for dh,dw in [[1,0],[0,1],[-1,0],[0,-1]]:
            if hi+dh>=0 and hi+dh<h and wi+dw>=0 and wi+dw<w and s[hi+dh][wi+dw]==".":
                if not visited[hi+dh][wi+dw]:
                    visited[hi+dh][wi+dw] = True
                    q.append((hi+dh,wi+dw,r+1))
                    res = max(res, r+1)

    return res

res = -1
for shi in range(h):
    for swi in range(w):
        if s[shi][swi]=="#":
            continue
        r = solve(shi,swi)
        res = max(res, r)

print(res)

Measured memory_bytes: 3316
#include <stdio.h>
 
int main(void){
 
int n[5];
int h, i;
 
scanf("%d %d %d %d %d", &n[0], &n[1], &n[2], &n[3], &n[4]);
 
for(h=0; h<4; h++){
 
for(i=0; i<4; i++){
 
if(n[i]<n[i+1]){
 
int temp=n[i];
n[i]=n[i+1];
n[i+1]=temp;
 
   }
 
 }
 
}
 
printf("%d %d %d %d %d\n", n[0], n[1], n[2], n[3], n[4]);
 
return 0;
 
}

Measured memory_bytes: 596
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


class WeightedUnionFind:
    def __init__(self, N):
        self.par = [i for i in range(N)]
        self.rank = [0] * N
        self.weight = [0] * N  # 親までの距離

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            r = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = r
            return r

    def union(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff_w(self, x, y):
        return self.weight[x] - self.weight[y]


def main():
    N, M = map(int, readline().split())
    m = map(int, read().split())
    LRD = list(zip(m, m, m))

    D = WeightedUnionFind(N)

    for l, r, d in LRD:
        l -= 1
        r -= 1
        D.union(l, r, d)

    for i in range(N):
        D.find(i)

    for l, r, d in LRD:
        l -= 1
        r -= 1
        if d != D.diff_w(l, r):
            print('No')
            sys.exit()
    
    print('Yes')


main()


Measured memory_bytes: 63028
// Problem : B - Homework
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : http://0s.mf2gg33emvzc42tq.dd34.ru/contests/abc163/tasks/abc163_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

int main(){
	int sum,n;
	
	
	cin >> sum >> n;
		vector<int> a(n);

	
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum -= a[i];	
	}
	
	if (sum < 0){
		cout << -1 << endl;
	}else {
		cout << sum << endl;
	}
		
	
	return 0;	
}


Measured memory_bytes: 3664
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <queue>
#include <list>
#include <limits>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;

typedef long long ll;
const int MOD = 1000000007;

    class Pairs{
        public : ll a;
        ll b;
        void setpairs(ll _a, ll _b){
            a = _a;
            b = _b;
        }
    };

    bool cmp(const P &A, const P &B){
        return (A.first < B.first);
    }


int main(){  
    char a,b;
    for(int i=0;i<4;i++){
        cin >> a;
        if(a == b){
            cout << "Bad";
            return 0;
        }
        b = a;
    }
    cout << "Good";
}


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

using namespace std;

#define MAX 20
#define MAX_V 500
#define INF 1e9
 
struct Edge{
    int to,cap,rev;
    Edge(int to,int cap,int rev) :
        to(to),cap(cap),rev(rev) {}
};
 
vector<Edge> G[MAX_V];
int level[MAX_V],iter[MAX_V];
 
void add_edge(int from,int to,int cap){
    G[from].push_back(Edge(to,cap,G[to].size()));
    G[to].push_back(Edge(from,0,G[from].size()-1));
}
 
void bfs(int s){
    memset(level,-1,sizeof(level));
    queue<int> Q;
    level[s] = 0;
    Q.push(s);
    while(!Q.empty()){
        int v = Q.front(); Q.pop();
        for(int i = 0 ; i < (int)G[v].size() ; i++){
            Edge &e = G[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                Q.push(e.to);
            }
        }
    }
}
 
int dfs(int v,int t,int f){
    if(v == t) return f;
    for(int &i = iter[v] ; i < (int)G[v].size() ; i++){
        Edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            int d = dfs(e.to,t,min(f,e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}
 
int max_flow(int s,int t){
    int flow = 0;
    for(;;){
        bfs(s);
        if(level[t] < 0) return flow;
        memset(iter,0,sizeof(iter));
        int f;
        while((f = dfs(s,t,INF)) > 0){
            flow += f;
        }
    }
}

bool inField(int y,int x,int H,int W){
    return (0 <= x && x < W && 0 <= y && y < H);
}

void init(){
    for(int i = 0 ; i < MAX_V ; i++){
        G[i].clear();
    }
}

int main(){
    int H,W,N;
    int r[MAX][MAX];
    cin >> N;
    for(int n = 0 ; n < N ; n++){
        int tcost = 0;
        init();
        cin >> W >> H;
        for(int i = 0 ; i < H ; i++){
            for(int j = 0 ; j < W ; j++){
                cin >> r[i][j];
                tcost += r[i][j];
            }
        }
        const int di[] = {0,-1,0,1};
        const int dj[] = {-1,0,1,0};
        int s = H*W,t = s+1;
        for(int i = 0 ; i < H ; i++){
            for(int j = 0 ; j < W ; j++){
                if((i+j)%2 == 0){
                    add_edge(s,i*W+j,r[i][j]);
                    for(int k = 0 ; k < 4 ; k++){
                        int ni = i + di[k];
                        int nj = j + dj[k];
                        if(inField(ni,nj,H,W)){
                            add_edge(i*W+j,ni*W+nj,INF);
                        }
                    }
                }else{
                    add_edge(i*W+j,t,r[i][j]);
                }
            }
        }
        cout << "Case " << n+1 << ": " << tcost - max_flow(s,t) << endl;
    }
    return 0;
}

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

  const int MOD = 1000000007;

  //long long
  using ll = long long;

  //出力系
  #define print(x) cout << x << endl
  #define yes cout << "Yes" << endl
  #define YES cout << "YES" << endl
  #define no cout << "No" << endl
  #define NO cout << "NO" << endl
  
  // begin() end()
  #define all(x) (x).begin(),(x).end()

  //for
  #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

  //最大公約数（ll）
  ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

  //素因数分解
  vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
      if(n % i) continue;
      res.emplace_back(i, 0);
      while(n % i == 0){
        n /= i;
        res.back().second++;
      }
    }
  if(n != 1) res.emplace_back(n, 1);
  return res;
  }


int main()
{
    vector<int>A(3, 0);
    REP(i, 2) {
        int x;
        cin >> x;
        A.at(x - 1) = 1;
    }

    REP(i , 3){
        if(A.at(i) == 0){
            print(i + 1);
            return 0;
        }
    }

    }

Measured memory_bytes: 256