akhauriyash/Code-Regression huggingface dataset:
def main():
    import sys
    input = sys.stdin.readline

    N, M = map(int, input().split())
    pS = [list(input().split()) for i in range(M)]

    was = [0]*N
    acs = [0]*N

    for p, s in pS:
        q_ind = int(p)-1
        if acs[q_ind] == 0:
            if s == 'AC':
                acs[q_ind] = 1
            else:
                was[q_ind] += 1
    ans_wa = 0
    for i in range(N):
        if acs[i] != 0:
            ans_wa += was[i]

    print(sum(acs), ans_wa)


if __name__ == "__main__":
    main()


Measured memory_bytes: 27416
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000000;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n;
	cin >> n;
	ll ans = 0;
	VI a(n);
	REP(i, n)
		cin >> a[i];
	REP(i, n) {
		for(int j = i + 1;j < n;j++) {
			ans += a[i] * a[j];
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N;cin>>N;
	int a,b;
	vector<int> C(N);vector<int> g[N];
	vector<int> count(N);
	for(int i=0;i<N-1;i++){
		cin>>a>>b;
		a--;b--;
		count[a]++;
		count[b]++;
		g[a].push_back(b);
		g[b].push_back(a);
	}for(int i=0;i<N;i++){
		cin>>C[i];
	}sort(C.begin(),C.end());
	int M=0;int D[N];
	for(int i=0;i<N-1;i++){
		for(int j=0;j<N;j++){
			if(count[j]==1){
				int v=g[j][0];
				count[j]--;
				count[v]--;
				g[j].erase(g[j].begin());
				for(int k=0;k<g[v].size();k++){
					if(g[v][k]==j){
						g[v].erase(g[v].begin()+k);
						break;
					}
				}D[j]=C[i];
                if(i==N-2){
                    D[v]=C[N-1];
                }M+=C[i];
				break;
			}
		}
	}
	cout<<M<<endl;
	cout<<D[0];
	for(int i=1;i<N;i++){
		cout<<" "<<D[i];
	}cout<<endl;
}

Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<complex>
#include<unordered_map>
#define deg(x) cout<<#x<<"="<<x<<endl;
#define fd(x) for(int i=0;i<x;i++)
#define fdd(a,x) for(int i=a;i<x;i++)
#define fx(x,n) for(int i=n-1;i>=x;i--)
#define mst(x) memset(x,0,sizeof(x));
#define fi first
#define se second
#define TB ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define ok "ok"
#define HH puts("");
#define ls rt<<1
#define rs rt<<1|1
#define pb(a,b) a.push_back(b);
#define FIN  freopen("1.in","r",stdin);
#define FOUT freopen("1.out","w",stdout);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,int> pss;
typedef unsigned long long ull;
const ll mod=1e18;
const ll inf=1e18;
const double eps=1e-8;
const double pi=acos(-1);



int main(){
    TB
    int n;
    cin>>n;
    int d=n/2;
    if(n&1) d++;
    cout<<d<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<ctime>
#include<deque>
#include<sstream>
#include<iomanip>
#include<sstream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<climits>
#include<map>
#include<set>
#include<list>
#include<cassert>
#include<deque>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<27
#define all(n) n.begin(),n.end()
#define insert(a,b,c,d) PP(P(a,b),P(c,d))
#define F first
#define S second
#define MOD 100000
#define pb push_back
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
typedef pair<int,bool> IB;
typedef long long ll;
typedef unsigned long long ull;
int h,w;                 //       FROM    AVAILABLE
int imap[110][110][2][2];//[y][x][L or B][A or U]
                         //       0    1  0    1

int main(){

  while(true){
    cin >> w >> h;
    if(w+h == 0)break;
    rep(i,h+1)rep(j,w+1)imap[i][j][0][0] = imap[i][j][0][1] = imap[i][j][1][0] = imap[i][j][1][1] = 0;
    rep(i,max(h,w)+1)imap[0][i][0][0] = imap[i][0][1][0] = 1;
    
    REP(i,1,h){
      REP(j,1,w){
	imap[i][j][0][0] += (imap[i][j-1][0][0] + imap[i][j-1][0][1])%MOD;//OK
	imap[i][j][0][1] += imap[i][j-1][1][0]%MOD;
	imap[i][j][1][0] += (imap[i-1][j][1][0] + imap[i-1][j][1][1])%MOD;
	imap[i][j][1][1] += imap[i-1][j][0][0]%MOD;
      }
    }
    int total;
    total = 0;
    rep(i,2)rep(j,2)total += imap[h-1][w-1][i][j];
    cout << total%MOD << endl;
    

  }
return 0;
}

Measured memory_bytes: 1336
#include <iostream>
#include <algorithm>
#include <vector>
#include <limits>

using namespace std;

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

    vector<int> R;
    for (int i = 0; i < n; ++i) {
        int r;
        cin >> r;
        R.push_back(r);
    }

    int maxv = R[1] - R[0];
    int minv = R[0];
    for (int j = 1; j < n; ++j) {
        maxv = max(maxv, R[j] - minv);
        minv = min(minv, R[j]);
    }
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 3832
#include<stdio.h>
 
int main(void)
{
        int a,b,c,d,e,f,A;
        while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=EOF)
        {
                A = (a*e-b*d);
                printf("%.3f %.3f\n",(float)(c*e-b*f)/A+0,(float)(a*f-c*d)/A+0);
        }
        return 0;
}

Measured memory_bytes: 636
# review
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]
 
def f(i,a,b,c):
    if i == N:
        if min(a, b, c) <= 0:
            return 10**9
        return abs(a-A)+abs(b-B)+abs(c-C)-30
    costx = f(i+1,a,b,c)
    costA = f(i+1,a+L[i],b,c)+10
    costB = f(i+1,a,b+L[i],c)+10
    costC = f(i+1,a,b,c+L[i])+10
    return min(costx,costA,costB,costC)
 
print(f(0,0,0,0))

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

int main() {
	ios_base::sync_with_stdio( false );

	vector<int> mts( 10 );
	for( auto& v: mts ) { cin >> v; }

	sort( mts.begin(), mts.end(), greater<>() );

	for( int i = 0; i < 3; ++i ) {
		cout << mts[i] << endl;
	}
}



Measured memory_bytes: 3180
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>

using namespace std;

int main(){
    int n;
    cin >> n;
    
    vector<int> v;
    
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.push_back(x);
    }
    int ans = 0;
    int m = 0;
    
   for(int i = 0; i < n; i++){
       if(i == 0){
           m = v[0];
           ans++;
       }
       else{
           if(v[i] >= m){
               m = v[i];
               ans++;
           }
       }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

const int MAXN = 10010;
int jikan[MAXN];
int sum[MAXN];

int main(void) {
    int n;
    while (cin >> n) {
        if (n == 0) break;
        for (int i = 0; i < n; i++) cin >> jikan[i];
        sort(jikan, jikan+n);
        ll ret = 0;
        for (int i = 1; i < n; i++) {
            sum[i] = sum[i-1] + jikan[i-1];
            ret += sum[i];
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1244
use std::io::*;
use std::str::FromStr;
use std::cmp;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const E: char = 'E';
const W: char = 'W';

fn main() {
    let n: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();


    let mut right = 0;
    for i in 0..n {
        if s[i] == E { right += 1; }
    }

    let mut min = n;

    let mut left = 0;
    for i in 0..n {
        if s[i] == E { right -= 1; }
        if i > 0 && s[i-1] == W { left += 1; }

        min = cmp::min(min, left + right);
    }

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


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

int main() {
  int n,x,a,aa,aaa;
    cin>>n;
  a=n/1.08;
  aa=a*1.08;
  aaa=(a+1)*1.08;
  if(aa==n){
  x=a;
    cout<<x;
  }
  else if(aaa==n){
      x=a+1;
    cout<<x;
  }
  else{
  cout<<":(";
  }
}


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

using namespace std;

int main()
{
	int count;
	int tmp;
	vector<int>* numline = new vector<int>();
	vector<int>::iterator itr;
	
	cin >> count;
	
	while(count)
	{
		cin >> tmp;
		cin.ignore();
		numline->push_back(tmp);
		--count;
	}
	
	sort(numline->begin(), numline->end());
	int tmpc;
	for(itr = numline->begin(); itr != numline->end(); itr += tmpc)
	{
		tmpc = 1;
		while(*itr == *(itr+tmpc))
		{
			++tmpc;
		}
		if(tmpc > *itr)
		{
			count += tmpc - (*itr);
		}
		else if(tmpc < *itr)
		{
			count += tmpc;
		}
	}
	
	cout << count <<endl;
	
	delete numline;
	
	return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxS = 1e4 + 1;
char s[maxS];

int main()
{
  int n;
  while (scanf("%d", &n) != EOF)
  {
    scanf(" %s", s);
    for (int i = 0; s[i]; i ++)
      s[i] = ((s[i] - 'A') + n) % 26 + 'A';
    printf("%s\n", s);
  }
  return 0;
}

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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;

  ll power = 1;
  for(ll i=1; i<=n; i++){

    power *= i;
    power %= MOD;
  }

  cout << power << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 10000000000LL
#define rep(i,n) for(i=0;i<n;i++)

typedef pair<int,int> pii;
int i,j;

int main(void) {
  int n,i,j;
  while(1){
    char str[1000]={};
    cin>>n;
    if(n==0)break;
    int alph[26]={};
    rep(i,n){
      cin>>str;
      char a=str[0];
      alph[(int)(a-'A')]++;
      int check[26]={};
      rep(j,26)
        check[j]=alph[j];
      sort(check,check+26);
      if(check[24]+n-i-1<check[25])break;
    }
   int num=i+1;
    for(i=num;i<n;i++)
      cin>>str;
    pii p[26];
    rep(i,26){
      p[i].first=alph[i];
      p[i].second=i;
    }
    sort(p,p+26);
    if(p[24].first==p[25].first)
      cout<<"TIE"<<endl;
    else{
      str[0]='A'+p[25].second;
      cout<<str[0]<<" "<<num<<endl;
    }
  }
  return 0;
}

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

const int N = 1e5 + 100;

int main(){

    # ifdef FILEs
        freopen( "input.txt", "r", stdin );
        freopen( "output.txt", "w", stdout );
    # endif
    ios_base::sync_with_stdio( false );
    
    int n;
    cin >> n;
    int cnt = 1;
    for( int i = 1; i <= n; i ++ ){
        int a; 
        cin >> a;
        if( a == cnt )
            cnt++;
    }
    if( cnt == 1 ){
        cout << -1;
    }else{
        cout << n-cnt+1;
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int x, y, n, m, ans;
int a[N], root[N];
unordered_map<int, unordered_set<int>> mp;

int find_st(int x) {
    if (root[x] == x) return x;
    return root[x] = find_st(root[x]);
}
void union_st(int x, int y) {
    if (root[x] != root[y])
        root[root[x]] = root[y];
}

int main() {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        root[i] = i;
        cin >> a[i];
    }
    for (int i = 0; i < m; ++i) {
        cin >> x >> y;
        if (find_st(a[x]) != find_st(a[y]))
            union_st(a[x], a[y]);
    }
    for (int i = 1; i <= n; ++i) {
        int r = find_st(i);
        mp[r].insert(i);
    }
    for (int i = 1; i <= n; ++i) {
        if (mp[find_st(a[i])].count(i))
            ++ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 18944
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N, R;
    cin >> N >> R;
    if(N >= 10) {
        cout << R << endl;
    } else {
        cout << R + 100 * (10 - N) << endl;
    }
    return 0;
}

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

int main() {
	int k;
	cin >> k;
	if(k % 2 == 0)
		return cout << -1, 0;
	string s = "7";
	long long cur_power = 1, cur = 7;
	while(cur % k != 0) {
		cur_power = cur_power * 10 % k;
		cur = cur + 7 * cur_power % k;
		cur %= k;
		s += '7';
		if(s.size() > k)
			return cout << -1, 0;
	}
	cout << s.size();
}
	


Measured memory_bytes: 5192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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; }

const long long INF = 1LL << 60;

int main(){
  string s, t;
  cin >> s >> t;

  int n = s.size();
  int m = t.size();
  rep(i, m) cout << s[i] << t[i];
  if(n-m == 1) cout << s[n-1];
  cout << endl;

  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;


class U {
public:
  int n;
  vector<int> p, s;

  U(int _) {
    n = _;
    p.resize(n);
    s.resize(n);
    for (int i = 0; i < n; i++) {
      p[i] = i;
      s[i] = 1;
    }
  }

  bool connect(int a, int b) {
    int ap, bp;
    for (ap = p[a]; ap != p[ap]; ap = p[ap]);
    for (bp = p[b]; bp != p[bp]; bp = p[bp]);
    if (ap == bp)
      return true;
    int mi = min(ap, bp), ma = max(ap, bp);
    p[ma] = mi;
    s[mi] += s[ma];
    s[ma] = 0;
    for (int pp = a; pp != mi;) {
      int next = p[pp];
      p[pp] = mi;
      pp = next;
    }
    for (int pp = b; pp != mi;) {
      int next = p[pp];
      p[pp] = mi;
      pp = next;
    }
    return false;
  }

  int q(int a) {
    int ap;
    for (ap = a; ap != p[ap]; ap = p[ap]);
    return s[ap];
  }

  int parent(int a) {
    int ap;
    for (ap = a; ap != p[ap]; ap = p[ap]);
    return p[ap];
  }

  bool query(int a, int b) { return parent(a) == parent(b); }
};

U u(101010);

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<pair<ll, ll>> ps(n);
  for (int i = 0; i < n; i++) cin >> ps[i].first >> ps[i].second;

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

  vector<int> buf;
  buf.push_back(ps[0].second);
  for (int i = 1; i < n; i++) {
    if (ps[i].first == ps[i - 1].first) {
      buf.push_back(ps[i].second);
    } else {
      int now = buf[0];
      for (int j = 1; j < buf.size(); j++) {
        u.connect(now, buf[j]);
      }
      buf.clear();
      buf.push_back(ps[i].second);
    }
  }
  int now = buf[0];
  for (int j = 1; j < buf.size(); j++) {
    u.connect(now, buf[j]);
  }
  ll ans = 0;
  vector<set<int>> q(101010);
  for (int i = 0; i < n; i++) {
    q[u.parent(ps[i].second)].insert(ps[i].first);
  }
  for (int i = 0; i <= 100000; i++) {
    if (u.parent(i) == i)
      ans += q[i].size() * u.s[i];
  }
  ans -= n;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 9728
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
xl = [LI() for _ in range(n)]
xl.sort()
ans = 0
h = []
for x,l in xl:
    heappush(h,(x+l,x-l))
ans = 0
now = -inf
while h:
    r,l = heappop(h)
    if now <= l:
        now = r
    else:
        ans += 1
print(n-ans)


Measured memory_bytes: 66908
#include <stdio.h>
#include <string.h>
#define N 200005
#define inf 1000000000000000
long long u[N], v[N], w[N], first[N], next[N], book[N], que[N * 10];
long long dis[N];
int main()
{
        int n;
        while (~scanf("%d", &n))
        {
                int m = n - 1;
                int head = 1, tail = 1;
                for (int i = 0; i < N; i++)
                {
                        dis[i] = inf;
                }
                memset(book, 0, sizeof(book));
                memset(first, -1, sizeof(first));
                for (int i = 1; i <= m * 2; i += 2)
                {
                        int p = i + 1;
                        scanf("%lld%lld%lld", &u[i], &v[i], &w[i]);
                        u[p] = v[i], v[p] = u[i], w[p] = w[i];
                        next[i] = first[u[i]];
                        first[u[i]] = i;
                        next[p] = first[u[p]];
                        first[u[p]] = p;
                }
                int q, kk, t, k;
                scanf("%d%d", &q, &kk);
                dis[kk] = 0;
                que[tail] = kk;
                tail++;
                book[kk] = 1;
                while (head < tail)
                {
                        k = first[que[head]];
                        while (k != -1)
                        {
                                if (dis[v[k]] > dis[u[k]] + w[k])
                                {
                                        dis[v[k]] = dis[u[k]] + w[k];
                                        if (book[v[k]] == 0)
                                        {
                                                que[tail] = v[k];
                                                tail++;
                                                book[v[k]] = 1;
                                        }
                                }
                                k = next[k];
                        }
                        book[que[head]] = 0;
                        head++;
                }
                while (q--)
                {
                        int t1, t2;
                        scanf("%d%d", &t1, &t2);
                        printf("%lld\n", dis[t1] + dis[t2]);
                }
        }
        return 0;
}


Measured memory_bytes: 16000
#from collections import deque
H,W=map(int,input().split())
S=[input() for i in range(H)]
visit=[[False]*W for i in range(H)]
par=[[None]*W for i in range(H)]
dd={}
X=[-1,0,1,0]
Y=[0,-1,0,1]
for j in range(H):
    for i in range(W):
        if visit[j][i]:
            continue
        if S[j][i]=='.':
            continue
        lH=[]
        lH.append((j,i,0))#0が黒
        par[j][i]=(i,j)
        num=0
        while lH:
            y,x,t=lH.pop()
            visit[y][x]=True
            for k in range(4):
                nx=x+X[k]
                ny=y+Y[k]
                if 0<=nx<W and 0<=ny<H:
                    if visit[ny][nx]:
                        continue
                    if t==0 and S[ny][nx]=='.':
                        visit[ny][nx]=True
                        num+=1
                        lH.append((ny,nx,1))
                    elif t==1 and S[ny][nx]=='#':
                        visit[ny][nx] = True
                        par[ny][nx]=(i,j)
                        lH.append((ny,nx,0))
        dd[(i,j)]=num
#print(par)
#print(dd)
ans=0
for j in range(H):
    for i in range(W):
        if S[j][i]=='#':
            x,y=par[j][i]
            ans+=dd[(x,y)]
print(ans)


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

int main() {
    // 演算子のみで解答する。
    int a, b;
    cin >> a;
    cin >> b;

    double ave = (a + b) / 2.0;
    //5.5
    double i = ave * 10.0;
    int j = ave;
    int ones = i - j * 10;
    int diff = ones / 5;
    int ans = ave + diff;
    //double rem = ave % 10.0;
    //int diff = rem - 5;

    cout << ans;

}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int H, W; char s[1009][1009];
int main() {
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++) scanf("%s", s[i]);
	vector<pair<int, int> > v;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '.' || s[i][j] == '9') continue;
			int cnt = 0;
			for (int k = -1; k <= 1; k++) {
				for (int l = -1; l <= 1; l++) {
					int tx = j + l, ty = i + k;
					if (0 <= tx && tx < W && 0 <= ty && ty < H && s[ty][tx] == '.') cnt++;
				}
			}
			if (cnt >= s[i][j] - 48) v.push_back(make_pair(j, i));
		}
	}
	int ret = 0;
	for (; !v.empty(); ret++) {
		for (pair<int, int> i : v) s[i.second][i.first] = '.';
		vector<pair<int, int> > w;
		for (pair<int, int> i : v) {
			int sx = i.first, sy = i.second;
			for (int j = -1; j <= 1; j++) {
				for (int k = -1; k <= 1; k++) {
					int tx = sx + k, ty = sy + j;
					if (!(0 <= tx && tx < W && 0 <= ty && ty < H)) continue;
					if (s[ty][tx] == '.' || s[ty][tx] == '9') continue;
					int cnt = 0;
					for (int l = -1; l <= 1; l++) {
						for (int m = -1; m <= 1; m++) {
							int ux = tx + m, uy = ty + l;
							if (0 <= ux && ux < W && 0 <= uy && uy < H && s[uy][ux] == '.') cnt++;
						}
					}
					if (cnt >= s[ty][tx] - 48) w.push_back(make_pair(tx, ty));
				}
			}
		}
		sort(w.begin(), w.end());
		w.resize(unique(w.begin(), w.end()) - w.begin());
		v = w;
	}
	printf("%d\n", ret);
	return 0;
}

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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;cin>>n>>k;
    ll ans = 0;
    for(int b=k+1; b<=n; b++){
        ans += (b-k)*(n/b);
        int r = n-b*(n/b);
        ans += max(0,r-k+1);
    }
    if(k==0)ans-=n;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, a[100010];
int rin;
vector<int> ta, mu;
int ans;

signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	rin = a[0];
	rep(i, n - 1) {
		rin = gcd(rin, a[i]);
		ta.push_back(rin);
	}
	rin = a[n - 1];
	for (int i = n - 1; i > 0; i--) {
		rin = gcd(rin, a[i]);
		mu.push_back(rin);
	}
	ans = max({ ans,ta[n - 2],mu[n - 2] });
	for (int i = 0; i <= n - 3; i++) {
		ans = max(ans, gcd(ta[i], mu[n - (i + 3)]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int P = scanner.nextInt();
		int Q = scanner.nextInt();
		int R = scanner.nextInt();
		int tmp = Math.min(P + Q, P + R);
		int ans = Math.min(tmp, Q + R);
		System.out.println(ans);
		scanner.close();
	}
}

Measured memory_bytes: 23764
// https://atcoder.jp/contests/dp/tasks/dp_a

#include <iostream>
#include <vector>
#include <tuple>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

void debug_out() {};
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

struct C1 {
    ll N_{};
    vector<ll> v_{};
    vector<ll> dp_{};
    explicit C1(vector<ll> v) : N_(v.size()), v_(move(v)){}
    ll resolve() {
        dp_.resize(N_, 0);
        for(ll i=0; i < N_; ++i) {
            if(i == 0) {
                dp_[i] = 0;
            } else if(i == 1) {
                dp_[i] = abs(v_[1]-v_[0]);
            } else {
                dp_[i] = min(
                        abs(v_[i-2]-v_[i]) + dp_[i-2],
                        abs(v_[i-1]-v_[i]) + dp_[i-1]
                        );
            }
        }
        return dp_[N_-1];
    }
};

int main() {
    ll N;
    cin >> N ;
    vector<ll> v{};
    for (int i=0; i < N; ++i) {
        ll x;
        cin >> x;
        v.emplace_back(x);
    }
    C1 c{move(v)};
    cout << c.resolve() << endl;
    return 0;
}


Measured memory_bytes: 1908
#include <stdio.h>
#include <string.h>

int main(){
    
    long long num;
    scanf("%lld", &num);
    char str[100] ={0};
    int i = 0;
    num--;

    while(num >= 0){
         str[i] = num%26 + 'a';
         num /= 26;
        i++;
        num--;                
    }
    int len = strlen(str);
    
    for(int j=len-1;j>=0;j--){
        printf("%c", str[j]);
    }    

    return 0;
}

Measured memory_bytes: 1664
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	s := next()

	c := 1
	prev := s[0:1]
	for i := 1; i < len(s); i++ {
		if s[i:i+1] != prev {
			prev = s[i : i+1]
			c++
		} else if i+1 < len(s) {
			prev = s[i : i+2]
			i++
			c++
		}
	}

	fmt.Println(c)
}


Measured memory_bytes: 1024
import heapq
N = int(input())
S = input()

ans = 0
w = []
r = []
for i, s in enumerate(S):
    if s == "W":
        w.append(i)
    else:
        r.append(-i)

if w and r:
    heapq.heapify(w)
    heapq.heapify(r)
    while w[0] < -r[0]:
        wi = heapq.heappop(w)
        ri = -heapq.heappop(r)
        heapq.heappush(w, ri)
        heapq.heappush(r, -wi)
        ans += 1

print(ans)

Measured memory_bytes: 81140
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, a, b) for(int i=(a); i<(int)(b); i++)

typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct Node { int from, to, cost; };

int dx[] ={-1, 0, 0, 1};
int dy[] ={0, -1, 1, 0};

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}

int main(void){
	int n; cin >> n;
	int ans = 0;
	/*
	for(int i=10; i<=SIZE; i*=100){
		if(n > i) ans += 9*i/10;
		else if(n/(i/10) > 0){
			ans += n % (i/10);
			ans++;
			break;
		} else break;
	}
	*/
	/*
	if(n >= 10) ans+= 9;
	if(n >= 1000) ans += 900;
	if(n >= 100000) ans += 90000;
	if(n / 10000 > 0 && n < 100000){
		ans += n%10000;
		ans++;
		cout << ans << endl;
		return 0;
	}
	if(n / 100 > 0 && n < 1000){
		ans += n%100;
		ans++;
		cout << ans << endl;
		return 0;
	}
	if(n / 1 > 0 && n < 10){
		ans += n%100;
		cout << ans << endl;
		return 0;
	}
	cout << ans << endl;
	*/

	rep2(i, 1, n+1){
		if(i < 10) ans++;
		else if(100 <= i && i < 1000) ans++;
		else if(10000 <= i && i < 100000) ans++;
	}

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

Measured memory_bytes: 256
#include<stdio.h>

void swap(int *, int *);

int main(){
    int x;
    int y;
    while(1){
       scanf("%d %d\n", &x, &y);
       if(x == 0 && y ==0) break;
       swap(&x, &y);
       printf("%d %d\n", x, y);
       x = y =0;
    }
    return 0;
}
void swap(int *x, int *y){
    int temp;
    if(*x > *y){
        temp = *x;
        *x = *y;
        *y = temp;
    }
}

Measured memory_bytes: 604
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N, W = map(int, input().split())
    value, weight = [0] * N, [0] * N
    for i in range(N):
        value[i], weight[i] = map(int, input().split())


    # この前段階で、荷物の数N、ウェイトの上限W、
    # weightの表weightとvalueの表valueは用意しておく。
    def knapsack(N, W, weight, value):
        dp = [[0] * (W + 1) for _ in range(N + 1)]

        for i in range(N):
            for w in range(W + 1):
                if w >= weight[i]:  # 荷物が加わる可能性がある
                    # max関数の第一引数だと、既存の荷物の方がましな場合。
                    # 第二引数だと、新入りを加えた方が良い場合。
                    dp[i + 1][w] = max(dp[i][w], dp[i+1][w - weight[i]] + value[i])
                else:  # 加わる可能性はない
                    dp[i + 1][w] = dp[i][w]

        return dp[N][W]

    print(knapsack(N, W, weight, value))




resolve()


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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int>  m(N, 0);

    int sum = 0;
    for (auto &x: m) {
        cin >> x;
        sum += x;
    }

    int num = 0;
    X -= sum;
    num += N;
    sort(m.begin(), m.end());
    num += X / m[0];
    cout << num << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,i,x;
    cin >> n;
    for(i=1;i<=n;i++){
        if(i%3==0){
            cout << " " << i;
        }else{
            x = i;
            while(1){
                if(x%10==3){
                    cout << " " << i;
                    break;
                }
                if(x<10) break;
                x /= 10;
            }
        }
    }
    cout << endl;
}
  


Measured memory_bytes: 3100
import java.util.*;
// warm-up
// Knew it.. Some quirky deduction which will always defeat the obvious approach
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		String t = sc.next();
		boolean isEven = (t.length() & 1)==0, areEqual=t.charAt(0)==t.charAt(t.length()-1);
		System.out.println(isEven^areEqual ? "Second" : "First");
		sc.close();			
	}

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

}

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

#pragma ide diagnostic ignored "OCUnusedGlobalDeclarationInspection"
#pragma ide diagnostic ignored "OCUnusedMacroInspection"
using namespace std;

#define sqr(a) ((a)*(a))
#define forn(i, n) for(int i = 0; i < (int)n; ++i)
#define rep(i, k, n) for(int i = (int)k; i <= (int)n; ++i)
#define nrof(i, n) for(int i = (int)n - 1; i >= 0; --i)
#define x first
#define y second
#define mp make_pair
#define sz(a) (int)(a.size())
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int N = 1e6 + 9;
const int M = 2e3 + 9;
const int INFINT = 1e9 + 9;
const ll INFLL = 1e18 + 9;
const ll MOD = (ll) (1000000007);

void solve() {
    string s;
    cin >> s;
    ll sum = 0;
    forn(i, sz(s)) {
        sum += s[i] - '0';
    }
    if (sum == 0) {
        cout << "Yes" << endl;
        return;
    }
//    while (sum > 10) {
//        ll tsum = 0;
//        while (sum > 0) {
//            tsum += sum % 10;
//            sum /= 10;
//        }
//        sum = tsum;
//    }
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}

int main() {
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3800
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) {
        cout << a - 1 << endl;
    }
    else cout << a << endl;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,A;
LL x[50];

LL ans = 0;

void solve(){
	//前からi個目まで見た時、そのうちj個を使って合計がk
	//となる組み合わせをいくつ作れるかを
	//dp[i][j][k]とする
	vector<vector<vector<LL>>> dp(N+1,vector<vector<LL>>(N+1,vector<LL>(2501,0)));
	dp[0][0][0] = 1;
	for(int i=0;i<N;i++){
		for(int j=0;j<=i;j++){
			for(int k=0;k<=2500;k++){
				if(dp[i][j][k]>0){
					dp[i+1][j][k] += dp[i][j][k];
					if(k+x[i]<=2500) dp[i+1][j+1][k+x[i]] += dp[i][j][k];
				}
			}
		}
	}
	for(int j=1;j<=N;j++){
		for(int k=1;k<=2500;k++){
			if(k%j==0 && k/j==A){
				ans += dp[N][j][k];
			}
		}
	}
}

int main(){
    cin >> N >> A;
    for(int i=0;i<N;i++) cin >> x[i];

    solve();

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

Measured memory_bytes: 52224
n = gets.to_i

ans = 1000000000

(1..n-1).each do |i|
  other = n - i
  ans = [ans, i.to_s.split('').map(&:to_i).inject(&:+) + other.to_s.split('').map(&:to_i).inject(&:+)].min
end

puts ans

Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second


void solve(){
	std::cout.precision(10);
	int n;
	cin>>n;
	double arr[n+1];
	rep(i,1,n+1){
		cin>>arr[i];
	}
	double dp[n+1][n+1];
	dp[0][0] = 0;
	dp[1][1] = arr[1];
	dp[1][0] = 1-arr[1];
	rep(i,2,n+1){
		rep(j,0,i+1){
			if(j==0){
				dp[i][j] = dp[i-1][j] * (1-arr[i]);
			}
			else if(j==i)
				dp[i][j] = dp[i-1][j-1] * arr[i];
			else{
				dp[i][j] = (dp[i-1][j-1]*arr[i]) + dp[i-1][j]*(1-arr[i]);
			}
		}
	}
	double ans=0;
	rep(i,n/2+1,n+1)
		ans+=dp[n][i];
	cout<<ans<<endl;

}
signed main(){
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    srand (static_cast <unsigned> (time(0)));
    int t=1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 70528
#!/usr/bin/env python3

import heapq

n, m, *a = map(int, open(0).read().split())

a = [*map(lambda x: -x, a)]
heapq.heapify(a)
for _ in range(m):
    heapq.heappush(a, -(-heapq.heappop(a) >> 1))
print(-sum(a))


Measured memory_bytes: 95196
#include<iostream>

using namespace std;

int main() {
    string S;

    cin >> S;

    int count = 0;

    for(int i = 0; i < S.length(); i++){
        if(S[i] == 'x'){
            count++;
        }
    }

    if(count < 8){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

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

int main(){
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ((A+B) > (C+D)){
    cout << "Left" << endl;
  }
  else if ((A+B) == (C+D)){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}
  

Measured memory_bytes: 256
A,B = map(int,input().split())
S = input()
flag = True

for i in range(A):
  if not '0' <= S[i] <= '9':
    flag = False

if S[A] != '-':
  flag = False

for i in range(B):
  if not '0' <= S[A+i+1] <= '9':
    flag = False

if flag:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
import java.util.Scanner;

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

        int P = sc.nextInt();
        int Q = sc.nextInt();
        int R = sc.nextInt();

        System.out.println(Math.min(Math.min(P + Q, P + R), Q + R));

    }
}

Measured memory_bytes: 22356
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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;} //最小公倍数

//-------------------------------------------------
//コピペするとこ



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


int main()
{
  int n ;
  cin >> n ;
  string s ;
  cin >> s ;
  if(n%2==1){
    cout << "No" <<endl ;
    return 0 ;
  }
  else{
    REP(i,n/2){
      if(s.at(i)!=s.at(n/2+i)){
        cout << "No" <<endl ;
        return 0 ;
      }
    }
  }
  
  cout <<"Yes"<<endl ;

  return 0 ;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[110];
vector<int>odd;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i];if(a[i]&1)odd.push_back(i);
	}
	if(m==1){
		cout<<n<<endl;
		if(n==1){
			cout<<1<<endl<<1<<endl;
			return 0;
		}
		cout<<2<<endl;
		cout<<n-1<<" "<<1<<endl;
		return 0;
	}
	if(odd.size()>2){
		puts("Impossible");
		return 0;
	}
	if(odd.size())swap(a[1],a[odd[0]]);
	if(odd.size()>1){
		swap(a[m],a[odd[1]]);
	}
	for(int i=1;i<=m;i++)cout<<a[i]<<" ";cout<<endl;
	a[1]++;a[m]--;int N=0;
	for(int i=1;i<=m;i++)if(a[i])N++;
	cout<<N<<endl;
	for(int i=1;i<=m;i++){
		if(a[i])cout<<a[i]<<" ";
	}
	return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second

int main(void) 
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 

	string s; 
	cin >> s; 
	if (s=="Rainy") cout << "Sunny\n"; 
	else if (s=="Sunny") cout << "Cloudy\n"; 
	else cout << "Rainy\n";

	
	return false; 
}


Measured memory_bytes: 256
S = list(map(int,input().split()))
N = S[0]
K = S[1]
X = list(map(int,input().split()))

Xnegative = [abs(x) for x in X if x < 0]
Xpositive = [x for x in X if x >= 0]
Xnegative = sorted(Xnegative)

i = 0

if len(Xpositive) >= K:
    sub = Xpositive[K-1]
    while i < len(Xnegative) and K-i-2 >= 0:
        distance = min(Xnegative[i],Xpositive[K-2-i]) + Xnegative[i] + Xpositive[K-2-i]
        if sub > distance:
            sub = distance
        i = i + 1
elif len(Xpositive) == 0:
    sub = Xnegative[K-1]
else:
    l = K-len(Xpositive)
    sub = min(Xnegative[l-1],Xpositive[-1]) + Xnegative[l-1] + Xpositive[-1]
    while i + l < len(Xnegative) and -i-2 >= -len(Xpositive):
        distance = min(Xnegative[i+l],Xpositive[-i-2]) + Xnegative[i+l] + Xpositive[-i-2]
        if sub > distance:
            sub = distance
        i = i + 1

print(sub)

Measured memory_bytes: 14564
import collections
import itertools

H,W = map(int,input().split())

c = [list(map(int,input().split()))for i in range(10)]

a = [list(map(int,input().split()))for i in range(H)]

a_1D =list(itertools.chain.from_iterable(a))

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j],c[i][k]+c[k][j])

a_cnt = collections.Counter(a_1D)

total = 0
for i,j in a_cnt.items():
    if i == -1:
        pass
    else:
        total += c[i][1]*j

print(total)

Measured memory_bytes: 70636
#include<stdio.h>

int main(){
	
	
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a<=9 && b<=9){
		
		printf("%d\n",a*b);
		
		
	}	
	
	else{
		printf("-1\n");
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int a, b;
  cin >> a >> b;
  if(a > 9 || b > 9) {
    cout << "-1";
    return 0;
  }
  cout << a * b;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int vis[210][210]; 
int area(pair<int,int>a,pair<int,int>b,pair<int,int>c)
{
	return a.first*b.second+b.first*c.second+c.first*a.second-a.second*b.first-b.second*c.first-c.second*a.first;
}
int n;
int ans;
pair<int,int>co[210];
int pw[210];
const int md=998244353;
int add(int x,int y)
{
	x+=y;
	if(x>=md)x-=md;
	return x;
}
int main()
{
	scanf("%d",&n);
	pw[0]=1;
	for(int i=1;i<=n;i++)pw[i]=add(pw[i-1],pw[i-1]);
	for(int i=1;i<=n;i++)scanf("%d%d",&co[i].first,&co[i].second);
	ans=pw[n]-1;
	for(int i=1;i<=n;i++)
	{
		ans--;
		if(ans<0)ans+=md;
		for(int j=i+1;j<=n;j++)
		{
			if(vis[i][j])continue;
			int cnt=1;
			for(int k=j+1;k<=n;k++)
			{
				if(area(co[i],co[j],co[k]))continue;
				cnt++;
				vis[i][k]=true;
			}
			ans-=pw[cnt]-1;
			if(ans<0)ans+=md; 
		}
	} 
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

int main(){
    int N,M;
    cin >> N >> M;
    long long H[N],A[M],B[M];
    for(int i=0;i<N;++i){
        cin >> H[i];
    }
    vector<vector<long long>> v(M+1000);
    for(int i=0;i<M;++i){
        cin >> A[i] >> B[i];
        A[i]-=1,B[i]-=1;
        v[A[i]].push_back(B[i]);
        v[B[i]].push_back(A[i]);
    }
    long long good_count=0;
    for(long long i=0;i<N;++i){
        bool no_exist=true;
        bool all_exist=true;
        if(v[i].size()>=1) no_exist=false;
        for(long long j=0;j<v[i].size();++j){
            if(H[i]<=H[v[i][j]]){
                all_exist=false;
            }
        }
        if(no_exist)good_count++;
        else if(all_exist)good_count++;
    }
    cout << good_count;
}

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

int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  char c = s.at(k - 1);
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != c) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}


Measured memory_bytes: 256