akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		char[] s = sc.next().toCharArray();
		int ans = 1;
		
		for(int i=1; i<N; i++)
			if(s[i]!=s[i-1])
				ans++;

		System.out.println(ans);
		sc.close();
	}
}


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

using namespace std;
typedef long long ll;

int h[100001];

bool can_banish(ll times, int N, int A, int B) {
    ll rest = times;
    for(int i = 0; i < N; i++) {
        if(h[i] - B * times <= 0) continue;
        rest -= (h[i] - B * times + (A - B) - 1) / (A - B);
        if(rest < 0) return false;
    }

    return true;
}

int main(void) {
    int i, N, A, B;
    ll l = -1, r = 0;
    scanf("%d%d%d", &N, &A, &B);
    for(i=0; i<N; i++) {
        scanf("%d", h+i);
        r = max(r, 1LL * (h[i] + B - 1) / B);
    }

    ll mid = (r + l) / 2;
    while(r - l > 1) {
        if(can_banish(mid, N, A, B)) r = mid;
        else                         l = mid;
        mid = (r + l) / 2;
    }

    return !printf("%lld\n", r);
}

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



int main(){
  int n,m= 0;
  string s;
  cin >> n ;
  cin >> s;
  int ans =0;
  for(int i=0;i<n;++i){
    if(s.at(i) == 'I')m++;
    if(s.at(i) == 'D')m--;
    ans = max(ans,m);
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	int K, X; cin >> K >> X;
	for (int i = X - K + 1; i <= X + K - 1; i++)cout << i << " ";
	cout << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
 {
 	string s,s1="ABC",s2="ARC";
 	cin>>s;
 	
 	if(s==s2)
 		cout<<s1<<endl;
 	else
 		cout<<s2<<endl;
 	return 0;
}
 	
 					

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>

using namespace std;

int N;
int L[205];

int main(void)
{
	cin >> N;
	for(int i = 0; i < 2*N; i++) cin >> L[i];
	sort(L, L+2*N);
	
	int ans = 0;
	for(int i = 0; i < N; i++) ans += L[i*2];
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
"use strict";
function main(input) {
  let kari = input[0].trim().split(" ");
  let kari3 = input[1].trim().split(" ");

  let kari2 = kari.map(i => parseInt(i));
  let a = kari3.map(i => parseInt(i));

  let h = kari2[0];
  let n = kari2[1];

  let judge = false;
  let sum = 0;
  for(let i=0;i<n;i++){
    sum += a[i];
    if(sum>=h){
      judge=true;
      break;
    }
  }
  console.log(judge?"Yes":"No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

Measured memory_bytes: 22080
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn sort_string(s: String) -> String {
    let mut it: Vec<_> = s.chars().collect();
    it.sort();
    //let ret: String = it.iter().collect();
    let mut ret: String = String::new();
    for c in it {
        ret.push(c);
    }
    ret
}

fn main() {
    let n: usize = read();
    let mut v: Vec<String> = vec![];
    for _ in 0..n {
        let s: String = read();
        v.push(sort_string(s));
    }
    v.sort();
    let mut ans: u64 = 0;
    let mut cnt: u64 = 1;
    for i in 1..n {
        if v[i - 1] == v[i] {
            cnt += 1;
        } else {
            ans += cnt * (cnt - 1) / 2;
            cnt = 1;
        }
    }
    ans += cnt * (cnt - 1) / 2;

    println!("{}", ans);
}


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

int main( ) {
  std::string S;
  std::cin >> S;
  
  int price = 700;
  for(int i = 0; i < 3; i++){
    if(S[i]=='o'){
      price += 100;
    }
  }
  
  std::cout << price << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
   int h,w; cin >> h >> w;
   int ih,iw,gh,gw; cin >> ih >> iw >> gh >> gw;
   ih--; iw--; gh--; gw--;
   vector<string> s(h);
   vector<vector<int> > check(h,vector<int>(w,INF));
   rep(i,h) cin >> s[i];

    int tr[5]={-2,-1,0,1,2};
    int trh[4]={0,1,0,-1};
    int trw[4]={1,0,-1,0};

    deque<P> q;
    q.push_front(P(ih,iw));
    check[ih][iw]=0;

    while(!q.empty()){
        int hh=q.front().first;
        int ww=q.front().second;
        q.pop_front();
        rep(i,4){
            int nh=hh+trh[i];
            int nw=ww+trw[i];
            if(nh<0 || nh>=h || nw<0 || nw>=w) continue;
            if(s[nh][nw]=='#') continue;
            if(check[nh][nw]<=check[hh][ww]) continue;
            q.push_front(P(nh,nw));
            check[nh][nw]=check[hh][ww];
        }
        rep(i,5)rep(j,5){
            int nh=hh+tr[i];
            int nw=ww+tr[j];
            if(nh<0 || nh>=h || nw<0 || nw>=w) continue;
            if(s[nh][nw]=='#') continue;
            if(check[nh][nw]<=check[hh][ww]) continue;
            q.push_back(P(nh,nw));
            check[nh][nw]=check[hh][ww]+1;
        }
    }
    if(check[gh][gw]==INF) cout << -1 << endl;
    else cout << check[gh][gw] << endl;
return 0;
}

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

using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble
#define PI 3 .14159265

//typedef tuple <int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

#define siz(x) (int)(x).size()
#define Y second
#define X first
#define IN insert
#define PB push_back
#define P pop_back
#define PU push
#define PO pop
//#define F find
#define ED end()
#define MP(a,b) make_pair( a, b )

#define MOD 1000000007LL
#define INF 1000000000
#define rep(a,i,b) for (ll i = (a); i < (b); ++i)
#define reps(a,i,b) for (ll i = (a); i <= (b); ++i)
#define repd( num, i, ed ) for(ll (i)= (num)-1; (i) >= e38d; --(i))
#define repkt( bg, i, num, kt ) for(ll (i)= (bg); (i) < (num) && (kt); ++(i))
#define repchar( i ) for(char (i)= 48; (i) <= 122; (i)++)   
#define in(n) scanf("%lld", &n)
#define out(n) printf("%lld\n", n)
#define outS(s) printf("%s\n", s)
#define setA(a,n) for(ll i= 0, j= sizeof(a)/sizeof(a[0]); i < j; ++i) a[i]= n;
#define repe(num,i,ed) for(ll (i)= (num); (i) >= ed; --(i))
#define endl "\n"
const int mod =1e9+7;
int n;
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    cin>>n;
    vector<int> dp(3);
    for(int day=1;day<=n;++day)
    {
        vector<int> new_dp(3,0);
        int choose[3];
        for(int i=0;i<3;++i) cin>>choose[i];
        for(int i=0;i<3;++i)
        {
            for(int j=0;j<3;++j)
            {
                if(i!=j) new_dp[j]=max(new_dp[j],dp[i]+choose[j]);
            }
        }
        dp=new_dp;
        // for(int i=0;i<3;++i) cout<<dp[i]<<" ";
        // cout<<endl;
    }
    cout<<max({dp[0],dp[1],dp[2]});
    return 0;
}

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

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define M 998244353

#define ll long long
#define ld long double
#define vi vector<ll>
#define pi pair<ll, ll>
#define vii vector<pi>
#define vvi vector<vi>
#define pb push_back
#define endl "\n"

#define REP(i, s, e) for (ll i = s; i < e; i++)
#define RREP(i, s, e) for (ll i = s; i > e; i--)

#define all(v) v.begin(), v.end()
#define part(v, s, e) v.begin() + s, v.begin() + e
#define print(v) for (auto i: v) cout << i << " ";

int main() {
    fast;
    ll n;
    cin >> n;
    ll nm = 360, dn = n, g = __gcd(360ll, n);
    nm /= g;
    dn /= g;
    ll c = ((180 * dn - nm) * n) / dn;
    cout << c << endl;
    return 0;
}


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

using namespace std;

int main()
{
    string S;
    cin>>S;
    int A[26]= {0};
    for(int i=0; i<S.length(); i++)
    {
        A[S[i]-'a']++;
    }
    for(int i=0; i<26; i++)
    {
        if(A[i]%2==0)
        {
            continue;
        }
        else
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
ll n;
cin >> n;
ll p[n];
for(ll i=0;i<n;i++){
    cin >> p[i];
}
ll minimum=3*1e5;
ll ans=0;
for(ll i=0;i<n;i++){
    if(chmin(minimum,p[i]))ans++;
}
cout << ans << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        1000005
#define mod         1000000007  
#define pi          3.1415926535897932384626433
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    ll n=s1.size();
    ll m=s2.size();
    ll i,j,mi=MAX,count;
    for(i=0;i<=n-m;i++){
        count=0;
        for(j=0;j<m;j++){
            if(s2[j]!=s1[i+j]){
                count++;
            }
        }
        // cout<<count<<endl;
        mi=min(mi,count);
    }
    cout<<mi<<endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int n;
int a[100010];
multiset<int> s;

int main()
{
	read(n);
	for(int i=1; i<=n; ++i) read(a[i]);
	sort(a+1, a+n+1);
	for(int i=1; i<n; ++i)if(a[i]==a[i+1]) s.insert(a[i]), ++i;
	if(s.size()<2u){
		puts("0");
	} else {
		int x = *--s.end(); s.erase(--s.end());
		int y = *--s.end(); s.erase(--s.end());
		printf("%lld\n", x*1LL*y);
	}
	return 0;
}


Measured memory_bytes: 2944
#include <stdio.h>

int main(void){
  long long N,sample;
  scanf("%lld",&N);

  sample = N;
  int sum = 0;
  while(sample > 0){
    sum += sample%10;
    sample /= 10;
  }

  if(N%sum == 0){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 998244353;


int main(){
  int N, S;
  cin >> N >> S;
  vector<ll> v;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }

  vector<ll> ret(S+1,0);
  vector<ll> x(S+1,0);
  x[0] = 1;
  if(v[0]<=S) x[v[0]] = 1;
  rep(i,x.size()){
    ret[i] = x[i];
  }
  x[0] += 1;

  REP(i,1,N){
    vector<ll> y(S+1,0);
    rep(j,x.size()){
      if(j+v[i]<=S){
        y[j+v[i]] += x[j];
        y[j+v[i]] %= MOD;
      }
      y[j] += x[j];
      y[j] %= MOD;
    }
    rep(j,x.size()){
      ret[j] += y[j];
      ret[j] %= MOD;
      x[j] = y[j];
    }
    x[0] += 1;
    x[0] %= MOD;
  }

  cout << ret[S] << endl;
  
  return 0;
}


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

int main() {
    int a[3][3];
    int N;
    int b;
    int c[3][3] = {0};

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> a[i][j];
        }
    }
    cin >> N;
    for (int n = 0; n < N; n++) {
        cin >> b;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (a[i][j] == b) {
                    c[i][j] = 1;
                }
            }
        }
    }
    bool ans = false;
    for (int i = 0; i < 3; i++) {
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
            cnt += c[i][j];
        }
        if (cnt == 3) {
            ans = true;
        }
    }
    for (int i = 0; i < 3; i++) {
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
            cnt += c[j][i];
        }
        if (cnt == 3) {
            ans = true;
        }
    }
    {
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
            cnt += c[j][j];
        }
        if (cnt == 3) {
            ans = true;
        }
    }
    {
        int cnt = 0;
        for (int j = 0; j < 3; j++) {
            cnt += c[j][2 - j];
        }
        if (cnt == 3) {
            ans = true;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#  --*-coding:utf-8-*--

def f(k):
    if k == 3:
        return 100000
    elif k == 2:
        return 200000
    elif k == 1:
        return 300000            
    else:
        return 0

def main():
    X, Y = map(int, input().split())

    print(f(X) + f(Y) + (400000 if X == 1 and Y == 1 else 0))


if __name__ == '__main__':
    main()


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


int main() {
    int a, b, h; std::cin >> a >> b >> h;
    std::cout << (a + b)*h / 2 << std::endl;
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    int score = 0;
    for(int day = 1; ; day++){
        score += a;
        if(day % 7 == 0){
            score += b;
        }
        if(score >= c){
        cout << day << endl;
        break;
        }
    }
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    vector<int> rank;
    vector<int> size; // size[i]: iが親なら連結成分の数
 
    UnionFind(int N) : par(N), rank(N), size(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) {par[i] = i; rank[i] = 0; size[i] = 1;}
    }
 
    int find(int x) { // データxが属する木の根を再帰で得る：find(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
 
    void unite(int x, int y) { // xとyの木を併合
        int rx = find(x); //xの根をrx
        int ry = find(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
 
        // rank[rx] >= rank[ry] となるように rx と ry を swap
        if(rank[rx] < rank[ry]) swap(rx, ry);
 
        // 同じ高さだったならばまとめたことによって高さ +1
        if(rank[rx] == rank[ry]) ++rank[rx];
 
        par[ry] = rx; // root rx に ry の木をつなぐ
        size[rx] += size[ry];
        size[ry] = 0;
 
    }
 
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = find(x);
        int ry = find(y);
        return rx == ry;
    }
 
    int get_size(int x){
        int rx = find(x);
        return size[rx];
    }
};

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

    vector<set<int>> st(n);
    UnionFind uf(n);

    REP(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
        st[a].insert(b);
        st[b].insert(a);
    }

    REP(i, k) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        if(!uf.same(c, d)) continue;
        st[c].insert(d);
        st[d].insert(c);
    }

    REP(i, n) {
        int tmp = uf.get_size(i) - 1 - st[i].size();
        cout << tmp << endl;
    }

    return 0;
}

Measured memory_bytes: 26344
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }



int main() {
	ll x, y;
	cin >> x >> y;
	if (x % 3== 0 || y % 3 == 0) {
		cout << 0 << endl;
		return 0;
	}

	ll a = min(x, y);
	rep(i, x) {
		ll a1 = y * i;
		ll a2 = (x - i) * (y / 2);
		ll a3 = x * y - a1 - a2;
		ll k = max({ a1,a2,a3 }) - min({ a1,a2,a3 });
		a = min(a, k);
	}
	rep(i, y) {
		ll a1 = x * i;
		ll a2 = (y - i) * (x / 2);
		ll a3 = x * y - a1 - a2;
		ll k = max({ a1,a2,a3 }) - min({ a1,a2,a3 });
		a = min(a, k);
	}
	cout << a << endl;
}



Measured memory_bytes: 256
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (200'005)
#define MOD (1'000'000'007ll)
#define OO (1'050'000'000)
#define OOL (1'100'000'000'000'000'000ll)

//global
bool a[10][10];


int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	int n,m;
	cin >> n >> m;
	rep(i,0,n){
		string s;
		cin >> s;
		rep(j,0,m){
			a[i][j] = s[j]=='#';
		}
	}
	rep(i,0,n){
		rep(j,0,m){
			if(a[i][j]){
				rep(k,i+1,n){
					rep(l,0,j){
						if(a[k][l]) return cout << "Impossible",0;
					}
				}
			}
		}
	}
	cout << "Possible";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
ni = n
x = []
for i in range(10):
  x.append(ni // (10**(10 - i)))
  ni = n % (10 ** (10 - i))
x.append(ni % 10)
# print(x)
print('Yes' if n % sum(x) == 0 else 'No')

Measured memory_bytes: 9136
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;
import javax.xml.ws.WebEndpoint;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};
    static long mod=1000000007;
    
    public static void main(String[] args) {        
        new Thread(null, new Main(), "", 200 * 1024 * 1024).start();        
    }

    public void run() {
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n=sc.nextInt();
        String s=sc.nextString();
        for (int i = 0; i < s.length(); i++) {
			out.print("x");
		}
        out.println();
     	out.flush();
    }
    
    static long rep(long h) {
    	if(h==0)return 0;
    	return 1+rep(h/2)*2;
    }

    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }

    static void ret(long ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

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

//class P {
//	int x,y; double d;
//	P(int  x, int y, double d) {
//	  this.x=x;
//	  this.y=y;
//	  this.d=d;
//	}
//}


class P implements Comparable<P>{
    int p,h,f; long m;
    P(int p,int h, int f, long m) {
    	this.p=p;
    	this.h=h;
    	this.f=f;
    	this.m=m;
    }

    public int compareTo(P p){
    	if(this.p==p.p) {
    		if(this.f==-1) return 1;
    		return -1;
    	}
        return this.p-p.p;
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString()
    {
        while( st==null || !st.hasMoreTokens() )
			try {
				st = new StringTokenizer(x.readLine());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        return st.nextToken();
    }
    public int nextInt()
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) {
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) {
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() {
        return this.nextString().toCharArray();
    }    
    public long nextLong()
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 22868
#include "bits/stdc++.h"
using namespace std;

#define ll long long int
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define nl '\n'
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define all(a) a.begin(),a.end()
#define F first
#define S second
const ll N=1e6+9;
const ll mod=1e9+7;

ll a[105][N];
vector<pair<ll,ll>> v;

void solve()
{
	ll n,w,w1,v1;
	cin>>n>>w;
	rep(i,1,n)
	{
		cin>>w1>>v1;
		v.pb({w1,v1});
	} 
	v.pb({0,0});
	sort(all(v));

	rep(i,1,n)
	{		
		rep(j,1,w)
		{
			if(j-v[i].F>=0)
			a[i][j] = max( a[i-1][j] , a[i-1][j-v[i].F] + v[i].S ) ;
			else a[i][j] = a[i-1][j] ;//,cout<<"A";
		//	cout<<a[i][j]<<" ";
		}
		//cout<<nl;
	}
	cout<<a[n][w];

}



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    //if(t^1)exit(0);
    while(t--)
       solve();
}

Measured memory_bytes: 286976
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
const int MOD = 998244353;
struct Mint {
	int val;
	Mint() { val = 0; }
	Mint(const ll& x) {
		val = (-MOD <= x && x < MOD) ? x : x % MOD;
		if (val < 0) val += MOD;
	}
	friend bool operator==(const Mint& a, const Mint& b) { return a.val == b.val; }
	friend bool operator!=(const Mint& a, const Mint& b) { return !(a == b); }
	friend bool operator<(const Mint& a, const Mint& b) { return a.val < b.val; }
	Mint& operator+=(const Mint& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
	Mint& operator-=(const Mint& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
	Mint& operator*=(const Mint& m) { val = (ll)val * m.val % MOD; return *this; }
	friend Mint modex(Mint a, ll p) {
		assert(p >= 0);
		Mint ans = 1;
		for (; p; p >>= 1, a *= a) if (p & 1) ans *= a;
		return ans;
	}
	Mint& operator/=(const Mint& m) { return *this *= modex(m, MOD - 2); }
	Mint& operator++() { return *this += 1; }
	Mint& operator--() { return *this -= 1; }
	Mint operator++(int) { Mint result(*this); *this += 1; return result; }
	Mint operator--(int) { Mint result(*this); *this -= 1; return result; }
	Mint operator-() const { return Mint(-val); }
	friend Mint operator+(Mint a, const Mint& b) { return a += b; }
	friend Mint operator-(Mint a, const Mint& b) { return a -= b; }
	friend Mint operator*(Mint a, const Mint& b) { return a *= b; }
	friend Mint operator/(Mint a, const Mint& b) { return a /= b; }
	friend ostream& operator<<(ostream& os, const Mint& x) { return os << x.val; }
};
int main() {
	int n;
	scanf("%d", &n);
	vector<map<int, Mint>> mp(3);
	for (int i = 0; i < 3; ++i) {
		int m;
		scanf("%d", &m);
		vector<vector<int>> E(n + 1);
		vector<int> nim(n + 1);
		for (int j = 0; j < m; ++j) {
			int a, b;
			scanf("%d%d", &a, &b);
			if (a > b) swap(a, b);
			E[a].push_back(b);
		}
		for (int j = n; j >= 1; --j) {
			set<int> vals;
			for (int x : E[j]) {
				vals.insert(nim[x]);
			}
			while (vals.count(nim[j])) ++nim[j];
			mp[i][nim[j]] += modex(Mint(1e18), j);
		}
	}
	Mint ans = 0;
	for (auto& ak : mp[0]) {
		int a = ak.first;
		for (auto& bk : mp[1]) {
			int b = bk.first;
			int c = a ^ b;
			auto it = mp[2].find(c);
			if (it == mp[2].end()) continue;
			ans += it->second * bk.second * ak.second;
		}
	}
	printf("%d\n", ans.val);
}


Measured memory_bytes: 4816
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
typedef pair<int,int> P;

int main(){
    int N,M,X,Y;
    cin>>N>>M>>X>>Y;
    int MAX_X=-101;
    int MIN_Y=101;
    for(int i=0;i<N;i++){
        int x;
        cin>>x;
        MAX_X=max(MAX_X,x);
    }
    for(int i=0;i<M;i++){
        int y;
        cin>>y;
        MIN_Y=min(MIN_Y,y);
    }
    bool flag = false;
    if(MAX_X < MIN_Y && MAX_X<Y && MIN_Y>X){
        flag=true;
    }
    if(flag){
        cout<<"No War"<<endl;
    }else{
        cout<<"War"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
N, T =list(map(int, input().split()))
c = [0 for i in range(N)]
t = [0 for i in range(N)]
for i in range(N):
  c[i], t[i] = list(map(int, input().split()))

mi = 1001
now_mi = -1
for i in range(N):
  if t[i] <= T:
    if mi > c[i]:
      mi = c[i] 

if mi == 1001:
  print("TLE")
else:
  print(mi)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        2e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
   
    #endif
}




void solve()
{
  
  int a,b,n;
  cin >> a >> b >> n;
  
 int vl = min(n,b-1);

 cout<<max((a*vl)/b,(n*a)/b-a*(n/b));

}

int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }


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

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

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


int main(){
    int a,b;
    cin >> a >> b;
    int A = 0,B = 0;
    rep(i,a){
        A += b;
        A*= 10;
    }
    rep(i,b){
        B += a;
        B *= 10;
    }
    A /= 10;
    B /=  10;
    if(A>B)cout << A << endl;
    else cout << B << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())

stones = list(input())

left = 0
right = N - 1

count = 0

while left < right:
    if stones[left] == 'R':
        left += 1
        continue
    while left < right:
        if stones[right] == 'R':
            stones[left], stones[right] = stones[right], stones[left]
            left += 1
            right -= 1
            count += 1
            break
        right -= 1

print(count)

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

int max3(int i, int j, int k) {
  int max = i;
  if(max < j) max = j;
  if(max < k) max = k;
  return max;
}
int main() {

  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  /*int maxi,mini;
  maxi = max;
  mini = min(a,b,c);

  int least_times = (maxi - mini) % 2 == 0 ? (maxi - mini) / 2 : (maxi - mini) / 2 + 1;
  */
  int max = max3(a[0], a[1], a[2]);

  int sum = a[0] + a[1] + a[2];
  int least_times = (max*3 - sum) % 2 == 0 ? (max*3 - sum) / 2 : (max*3 - sum) / 2 + 1;

  int answer = 0;
  
  if(sum % 3 == 0) {
    answer = 0;
  }
  else if(sum % 3 == 1) {
    answer = 1;
  }
  else {
    answer = 2;
  }
  while(answer < least_times) {
    answer += 3;
  }

  cout << answer << endl;
  return 0;
}


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



int main(){
    int N;
    cin >> N;
    std::vector<int> seq(N);

    for(int i=0; i < N; i++){
        cin >> seq.at(i);
    }
    sort(seq.begin(), seq.end());
    double current_guzai = double(seq.at(0));
    for(int i=1; i < N; i++){
        current_guzai = (current_guzai + seq.at(i)) / 2.0;
    }
    cout << current_guzai  << endl;



}


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

int main() {
  int n,k;
  int a[100];
  cin>>n>>k;
  for (int i = 0; i < n; i++) cin >> a[i];
  
  sort(a,a+n,greater<int>());
  
  int sum=0;
  
  for (int i = 0; i <k; i++){
    sum+=a[i];
  }
  
  cout<<sum<<endl;

  
}

Measured memory_bytes: 256
using System;

public class Program {

        public static void Main(string[] args) {

            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            var C = 0;

            if(A + B == 3) {

                C = 3;

            } else if(A + B == 4) {

                C = 2;

            } else if(A + B == 5) {

                C = 1;

            }

            Console.WriteLine(C);

        }

    }

Measured memory_bytes: 11092
import sys
input = sys.stdin.readline
def function(n):
    if n % 10 == 0:
        return n
    else:
        return (n // 10)*10 + 10
A, B, C, D, E = (int(input()) for i in range(5))
list, ans = [(A % 10, A), (B % 10, B), (C % 10, C), (D % 10, D), (E % 10, E)], 0
for z in list:
    if z[0] == 0:
        ans += z[1]
        list.remove(z)
N = len(list)
list = sorted(list, key=lambda x:x[0])
for i in range(N-1):
    ans += function(list[N-i-1][1])
ans += list[0][1]
print(ans)


Measured memory_bytes: 3064
#https://atcoder.jp/contests/abc075/submissions/2242350
N,K=map(int,input().split())

points=[tuple(map(int,input().split())) for i in range(N)]
answer=10**19
sortx=sorted(points)
numberx = list(enumerate(sortx))

#n-k+1以降を左の頂点とすると点の数が明らかに足りない
for left,(x1,y1) in numberx[:N-K+1]:
  #left+K-1以降を右の頂点にしないと間に足りる点の数が入ってない
  for right,(x2,y2) in numberx[left+K-1:]:
    dx=x2-x1
    #left-rightの間でyについてsort
    sorty=sorted(y for x,y in sortx[left:right+1])
    #K個点を入れた状態で面積を求める
    for y3,y4 in zip(sorty,sorty[K-1:]):
      if y3<=y1 and y3<=y2 and y4>=y1 and y4>=y2:
        answer=min(answer,dx*(y4-y3))
         
print(answer)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,l[200010],r[200010],a[200010]={},st[200010]={},top=0;
long long ans=0;
inline int read()
{
	int x=0,w=0;char ch=0;
	while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
	while(isdigit(ch)){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
	return w?-x:x;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++){
		l[i]=0,r[i]=n+1;
		a[i]=read();
		while(a[i]<a[st[top]])
			r[st[top--]]=i;
		l[i]=st[top];
		st[++top]=i;
	}
	for(int i=1;i<=n;i++)
		ans+=(long long)a[i]*(i-l[i])*(r[i]-i);
	printf("%lld\n",ans);
}

Measured memory_bytes: 3328
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

class D
{
public:
	int t;
	int g;
	int p;
	int s;
	D()
	{
		t=g=p=s=0;
	}
	D(int t,int g,int p,int s)
	{
		this->t=t;
		this->g=g;
		this->p=p;
		this->s=s;
	}
};

stack<D>ST;
string S;


int main()
{
	cin>>S;
	int res=-500000;
	vector<int> DP(S.length()+1,-500000);
	ST.push(D());
	while(!ST.empty())
	{
		D d;
		d=ST.top();
		ST.pop();
		if(DP[d.t]>=d.s)continue;
		if(d.t==S.length())
		{
			res=max(res,d.s);
			continue;
		}
		//g
		if(S[d.t]=='g')
		{
			if(d.p<d.g)
			{
				ST.push(D(d.t+1,d.g,d.p+1,d.s+1));
			}
			else
			{
				ST.push(D(d.t+1,d.g+1,d.p,d.s));
			}
		}
		//p
		else
		{
			if(d.p<d.g)
			{
				ST.push(D(d.t+1,d.g,d.p+1,d.s));
			}
			else
			{
				ST.push(D(d.t+1,d.g+1,d.p,d.s-1));
			}
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>

#define lli long long int
#define REP(i,n) for(lli i=0;i<n;i++)
#define LINF 1LL<<60

using namespace std;

int main(){

	lli ans = LINF;

	string str;
	cin>>str;

	REP(i,str.size()-1){
		if(str[i]!=str[i+1]){
			ans = min(ans,(lli)max(i+1,(lli)str.size()-i-1));
		}
	}
	if(ans == LINF)cout<<str.size()<<endl;
	else cout<<ans<<endl;

	return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    V<ll> x(n);
    cinf(n,x);
    ll ans=INF;
    ll l=x[0],r=x[k-1];
    for(int i=1;i<=n-k+1;i++){
        if(r<=0) chmin(ans,abs(l));
        else if(l>=0)chmin(ans,r);
        else{
            chmin(ans,abs(l)+abs(r)+min(abs(l),abs(r)));
        }
        if(i==n-k+1)break;
        l=x[i];
        r=x[i+k-1];
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k; cin>>n>>k;
	vector<int>a(n); for(auto&&i:a)cin>>i;
	int64_t sum=accumulate(a.begin(),a.begin()+k,0L);
	for(int i=k;i<n;++i){
		int64_t tmp=sum;
		sum-=a.at(i-k),sum+=a.at(i);
		if(sum>tmp)cout<<"Yes\n"s;
		else cout<<"No\n"s;
	}
}


Measured memory_bytes: 3984
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 3e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
ll bit[500005];
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(15)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
    //abcのbed乗を計算する
    if(bed==0){return 1;}
    else{
        ll ced = rui(abc,bed/2);
        ced *= ced;
        ced %= mod;
        if(bed%2==1){ced*=abc; ced%=mod;}
        return ced;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}

ll i,j,k,ii,jj,r,l;
ll n,m,num,sum;
ll ans;
ll a,b,c,d,e,g,h,w,ok,ng;
ll x[500005],y[500005],z[500005];
ll cost[500005];
bool flag,dame;
char s[5005];

int main(){
    cin >> n >> m;
    for(i=0;i<m;i++){
        cin >> a >> b >> c;
        tree[a].pb(P(b,-c));
    }
    for(i=1;i<=n;i++){
        cost[i] = INF;
    }
    cost[1] = 0;
    num = 0;
    while(1){
        num ++;
        bool update = false;
        for(i=1;i<=n;i++){
            for(j=0;j<tree[i].size();j++){
                ll to,edgecost;
                to = tree[i][j].first;
                edgecost = tree[i][j].second;
                if(cost[i] != INF && cost[to] > cost[i] + edgecost){
                    cost[to] = cost[i] + edgecost;
                    update = true;
                }
            }
        }
        if(!update)break;
        if(num >= n + 10 && !flag){
            c = cost[n];
            flag = true;
        }
        if(num >= 2 * n + 30){
            if(c != cost[n]){
                p("inf");
                return 0;
            }else{
                break;
            }
        }
        
    }
    for(i=1;i<=n;i++){
       // pe(i);p(cost[i]);
    }
    p(-1 * cost[n]);
    return 0;
}


Measured memory_bytes: 26880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k,sum=0;
	cin>>n>>k;
	vector<int> a(n);
	rep(i,n){
		cin>>a[i];
		sum+=a[i];
	}
	vector<int> div;
	for(int i=1;i*i<=sum;i++){
		if(sum%i==0){
			div.push_back(i);
			if(i!=sum/i) div.push_back(sum/i);
		}
	}
	sort(begin(div),end(div),greater<int>());
	for(auto num:div){
		if(num==1){
			cout<<1<<endl;
			return 0;
		}
		vector<int> now;
		rep(i,n){
			if(a[i]%num){
				now.push_back(a[i]%num);
			}
		}
		sort(begin(now),end(now));
		int m=now.size();
		vector<int> sum(m+1,0);
		rep(i,m){
			sum[i+1]=sum[i]+now[i];
		}
		rep(i,m-1){
			if(sum[i+1]==num*(m-i-1)-(sum[m]-sum[i+1]) && sum[i+1]<=k){
				cout<<num<<endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
Scanf.scanf "%d %d %d" (fun n m x ->
    let c = Array.make n 0 in
    let a = Array.make_matrix n m 0 in
    for i = 0 to n - 1 do
        Scanf.scanf " %d" (fun cx -> c.(i) <- cx);
        for j = 0 to m - 1 do
            Scanf.scanf " %d" (fun ax -> a.(i).(j) <- ax);
        done
    done;

    let calc bit =
        let skills = Array.make m 0 in
        let rec loop i acc =
            if i = n then acc else
            let acc = if bit land (1 lsl i) > 0 then (
                for j = 0 to m - 1 do
                    skills.(j) <- skills.(j) + a.(i).(j)
                done;
                acc + c.(i)
            ) else acc
            in
            loop (i + 1) acc
        in
        let cost = loop 0 0 in
        if Array.fold_left (fun acc v -> if v >= x then acc else false) true skills then cost else -1
    in

    let rec loop i acc =
        if i < 0 then acc else
            let cost = calc i in
            let acc = if cost >= 0 then min acc cost else acc in
            loop (i - 1) acc
    in
    let ans = loop ((1 lsl n) - 1) max_int in
    Printf.printf "%d\n" @@ if ans = max_int then -1 else ans
)

Measured memory_bytes: 4716
import java.util.*;

public class Main {
    static long INF = 1000000000000000L;
    
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int[][] array = new int[h][w];
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                array[i][j] = sc.nextInt();
            }
        }
        
        
        int r = 0;
        int c = 0;
        int flag = 0;
        if (array[r][c] % 2 != 0) {
            flag = 1;
        }
        
        int count = 0;
        List<String> ans = new ArrayList<String>();
        while (true) {
            int or = r;
            int oc = c;
            if (r % 2 == 0) {
                c++;
                if (c == w) {
                    c = w - 1;
                    r++;
                }
            } else {
                c--;
                if (c == -1) {
                    c = 0;
                    r++;
                }
            }
            if (r ==h) break;
            if (flag == 0) {
                if (array[r][c] % 2 != 0) {
                    flag = 1;
                }
            } else {
                ans.add((or+1) + " " + (oc+1) + " ");
                ans.add((r+1) + " " + (c+1));
                count++;
                if (array[r][c] % 2 != 0) {
                    flag = 0;
                }
            }
        }
        
        System.out.println(count);
        for (int i = 0; i < ans.size(); i++) {
            if (i % 2 == 0) {
                System.out.print(ans.get(i));
            } else {
                System.out.println(ans.get(i));
            }
        }
    }
}

Measured memory_bytes: 118204
# -*- coding: utf-8 -*-
N, a, b = map(int, input().split()) 
 
sum = 0
for x in range(N + 1):
  l = [int(y) for y in list(str(x))]
  temp_sum = 0
  for z in l:
    temp_sum += z
  if a <= temp_sum and b >= temp_sum:
     sum += x
print(sum)

Measured memory_bytes: 3060