akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

string rankStr = "23456789TJQKA";

int main()
{
    for(;;){
        char trump;
        cin >> trump;
        if(trump == '#')
            return 0;

        vector<vector<int> > rank(4, vector<int>(13));
        vector<vector<char> > suit(4, vector<char>(13));
        for(int i=0; i<4; ++i){
            for(int j=0; j<13; ++j){
                string s;
                cin >> s;
                rank[i][j] = rankStr.find(s[0]);
                suit[i][j] = s[1];
            }
        }

        int led = 0;
        vector<int> win(2, -6);
        for(int i=0; i<13; ++i){
            int maxScore = -1;
            int winPlayer;
            for(int j=0; j<4; ++j){
                int score = rank[j][i];
                if(suit[j][i] == trump)
                    score += 100;
                else if(suit[j][i] == suit[led][i])
                    score += 50;

                if(score > maxScore){
                    maxScore = score;
                    winPlayer = j;
                }
            }
            ++ win[winPlayer&1];
            led = winPlayer;
        }

        if(win[0] > win[1])
            cout << "NS " << win[0] << endl;
        else
            cout << "EW " << win[1] << endl;
    }
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
long M=1e9+7,n,k,ans=1,l,r,b=1,a[1<<18],x,y,i;
main(){
  cin>>n>>k;
  r=n-1;
  for(i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  if(k%2)ans=a[r],r--,k--,b=(ans<0?-1:1);
  while(k){
    x=a[l]*a[l+1],y=a[r]*a[r-1];
    if(x*b>y*b)ans*=x%M,ans%=M,l+=2;
    else ans*=y%M,ans%=M,r-=2;
    k-=2;
  }
  cout<<(ans+M)%M<<endl;
}


Measured memory_bytes: 5140
while True:
    H,W=map(int,input().split())
    if(H==0 and W==0):
        break
    for i in range(H):
        for j in range(W):
            if(i==0 or j==0 or i==H-1 or j==W-1):
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()


Measured memory_bytes: 7008
//待解，&#35843;用函数 
#include<queue>
#include<cctype>
#include<cstdio>
#define mp          make_pair
using namespace std;
typedef pair<int,int> point;
const int maxn = 1005;
int height,width;    //n代表硬度 
char maze[maxn][maxn];
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

bool visited[maxn][maxn];
int shortDistance(int sx,int sy,int ex,int ey)
{
	//初始化visted数&#32452;
	for(int i = 0;i<height;i++)
		for(int j = 0;j<width;j++)
			visited[i][j] = false;
	visited[sy][sx] = true;
	queue<pair<int,point> > q;q.push(mp(0,mp(sy,sx)));
	while(1)
	{
		pair<int,point> a = q.front();q.pop();
		int d=a.first,x=a.second.second,y=a.second.first;
		if(x==ex&&y==ey)
		{
			return d;
		}
		for(int i = 0;i<4;i++)
		{
			 int xx=x+dx[i],yy=y+dy[i];
            if(0<=xx && xx<width && 0<=yy && yy<height && maze[yy][xx]!='X' && !visited[yy][xx]){
                visited[yy][xx]=true;
                q.push(mp(d+1,mp(yy,xx)));
            }
		}
	}
}

int main()
{
	int cx[10],cy[10],n;
	//freopen("I:\\0558-in2.txt","r",stdin);
	scanf("%d%d%d",&height,&width,&n);
	//&#36755;入迷&#23467; 
	for(int i = 0;i<height;i++)
	{
		scanf("%s",maze[i]);
		//&#26597;找老鼠&#24034;的位置
		for(int j = 0;j<width;j++)
		{
			if(maze[i][j]=='S')
			{
				cy[0] = i;
				cx[0] = j;
			}
			else if(isdigit(maze[i][j]))
			{
				int k = maze[i][j]-'0';
				cx[k] = j;cy[k] = i;
			}
			
		}
	}
	int cost = 0;
	
	for(int i = 0;i<n;i++)
		cost += shortDistance(cx[i],cy[i],cx[i+1],cy[i+1]);
	printf("%d\n",cost);
	return 0;
}

Measured memory_bytes: 3020
#include<bits/stdc++.h>
#define  ll  long long
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
int n,d;
cin>>n>>d;
int a[n+1][d+1];
for(int i=0 ; i < n; i++){
    for(int j= 0; j<d;j++){
        cin>>a[i][j];
    }
}
int count = 0;
 for(int i=0; i<n -1; i++){
    for(int j=i+1 ; j< n; j++ ){
            ll ans = 0;
        for(int l=0;l<d;l++){
            ans += abs((a[i][l] - a[j][l])*(a[i][l] - a[j][l])) ;
        }
      if(floor(sqrt(ans))==ceil(sqrt(ans)))
        count++;

    }
 }

cout<<count<<endl;
}


Measured memory_bytes: 256
# Problem: https://atcoder.jp/contests/abc083/tasks/abc083_b
# Python 2nd Try

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque
intm1 = lambda x: int(x) - 1
intp1 = lambda x: int(x) + 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def digitSum(target):
    result = 0
    strTarget = str(target)
    for j in range(0, len(strTarget)):
        result = result + int(strTarget[j])
    return result


def checker(target, fromNumber, toNumber):
    result = False
    x = digitSum(target)
    if fromNumber <= x :
        if  x <= toNumber :
            result = True
    return result


def solver(maxNumber, fromNumber, toNumber):
    result = 0
    for j in range(1, maxNumber + 1):
        if checker(j, fromNumber, toNumber):
#            print("{} is check!".format(j))
            result = result + j
    # algorithm
    return result


if __name__ == "__main__":
    N, A, B = MI()
    print("{}".format(solver(N, A, B)))


Measured memory_bytes: 3192
'use strict';
(function(stdin) {
  var lines  = stdin.toString().split('\n');
  var result = (function(r) {
  	return [
  		Number(Math.PI * r * r).toFixed(6)
  		,Number(Math.PI * 2 * r).toFixed(6)
  	].join(' ');
  }(parseFloat(lines[0])
  ));
  console.log(result);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
    string s = in<string>();
    int n = s.size();
    int m = n - 1;
    LL ans = 0;
    rep(p, 1 << m) {
        LL sum = 0;
        string a = s.substr(0, 1);
        rep(i, m) {
            if (p >> i & 1) {
                sum += fromString<LL>(a);
                a = "";
            }
            a += s[i + 1];
        }
        sum += fromString<LL>(a);
        ans += sum;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
//
int N;
VE D;
bool DFS(int now,int nok){
  if(nok<10){
    return false;
  }else if(now==N-1){
    return true;
  }
  now++;
  nok-=10;
  if(DFS(now,max(D[now],nok))){
    return true;
  }
  return false;
}
int main(){
  cin>>N;
  FOR(i,0,N){
    int d;
    cin>>d;
    D.PB(d);
  }
  if(!DFS(0,D[0])){
    cout<<"no"<<endl;
    return 0;
  }
  reverse(D.begin(),D.end());
  if(!DFS(0,D[0])){
    cout<<"no"<<endl;
  }else{
    cout<<"yes"<<endl;
  }
  return 0;
}


Measured memory_bytes: 13640
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int h, w, a[25][25], ans;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

void dfs(int cnt, int x, int y){
    if(cnt == 11 || cnt >= ans) return;
    rep(i, 4){
        int nx = x + dx[i], ny = y + dy[i];
        if(!(0<=nx && nx<h && 0<=ny && ny<w) || a[nx][ny] == 1) continue;
        for(int tx=x, ty=y;;){
            nx = tx + dx[i]; ny = ty + dy[i];
            if(!(0<=nx && nx<h && 0<=ny && ny<w)) break;
            if(a[nx][ny] == 3){
                chmin(ans, cnt);
                break;
            }
            if(a[nx][ny] == 1){
                a[nx][ny] = 0;
                dfs(cnt + 1, tx, ty);
                a[nx][ny] = 1;
                break;
            }
            if(a[nx][ny] == 0){
                tx = nx; ty = ny;
                continue;
            }
        }
    }
}

void solve(){
    int sx, sy;
    rep(i, h)rep(j, w){
        scanf("%d", &a[i][j]);
        if(a[i][j] == 2) sx = i, sy = j, a[i][j] = 0;
    }
    ans = mod;
    dfs(1, sx, sy);
    printf("%d\n", ans == mod ? -1 : ans);
}

int main(){
    while(scanf("%d%d", &w, &h) && w){
        solve();
    }
}


Measured memory_bytes: 3148
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<algorithm>
#include<string>
using namespace std;
#define int long long
#define vel vector<long long>
#define vvel vector<vel>
#define vvvel vector<vvel>
int root1(vel &par, int ser, vel &path) {
	if (par[ser] == -1) {
		for (int i = 0; i < path.size(); i++) {
			par[path[i]] = ser;
		}
		return ser;
	}
	path.push_back(ser);
	return root1(par, par[ser], path);
}
int root(vel &par, int ser) {
	vel emp(0);
	return root1(par, ser, emp);
}
void uni(int x, int y, vel &par, vel &rank) {
	x = root(par, x);
	y = root(par, y);
	if (x != y) {
		if (rank[x] < rank[y]) { par[x] = y; }
		else if (rank[x] == rank[y]) { par[x] = y; rank[x]++; }
		else { par[y] = x; }
	}
}
bool issame(int x, int y, vel &par) {
	return root(par, x) == root(par, y);
}
signed main() {
	string s; 
	cin >> s;
	int c0 = 0; int c1 = 0;
	int ans = 0;
	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] == '0') {
			c0++;
		}
		else {
			c1++;
		}
	}
	cout << 2*min(c0,c1) << endl;
}

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

int main(void) 
{
   int a, b, h, m;
   cin >> a >> b >> h >> m;

   double hh = (h * 30) + 0.5 * m;
   double mm = m * 6;
   double angle = hh - mm;

   double rad = (angle * M_PI /180);

   double ans = a*a + b*b - 2 * a * b *  cos(rad);
   ans = sqrt(ans);
   printf("%.20f", ans);
}

Measured memory_bytes: 4084
#include <bits/stdc++.h>
#define N 998244353
#define MAX 5000000
using namespace std;

long long factorial[MAX] = {0}, finverse[MAX] = {0},
          inverse[MAX] = {0};

void smodfact() {
  factorial[0] = factorial[1] = 1;
  finverse[0] = finverse[1] = 1;
  inverse[1] = 1;
  for(int i = 2; i < MAX; ++i) {
    factorial[i] = factorial[i - 1] * i % N;
    inverse[i] = N - (inverse[N % i] * (N / i)) % N;
    finverse[i] = finverse[i - 1] * inverse[i] % N;
  }
}

long long calccomb(long long n, long long k) {
  if(n == k && n == 0) return 1;
  if(n < 0 || k < 0 || n < k) return 0;
  return factorial[n] * finverse[k] % N * finverse[n - k] %
         N;
}

long long n, m;

long long solve();

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

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0;
  for(int i = 0; i <= min(m, n); ++i)
    if((m - i) % 2 == 0) {
      long long now = calccomb(n, i),
                dummy1 = calccomb(n - 1, i - 1) * n % N,
                dummy2 = calccomb(n - 1, i) * n % N;
      now *= calccomb(m + (m - i) / 2 + n - 1, n - 1);
      now %= N;
      // dummy1
      dummy1 *= calccomb((m - i) / 2 + n - 1, n - 1);
      dummy1 %= N;
      now -= dummy1;
      while(now < 0) now += N;
      // dummy2
      dummy2 *= calccomb((m - i) / 2 - 1 + n - 1, n - 1);
      dummy2 %= N;
      now -= dummy2;
      while(now < 0) now += N;
      ans += now;
      ans %= N;
    }
  return ans;
}

Measured memory_bytes: 117376
n = int(input())
mod = 10**9 + 7

# 前準備
import sys
input = sys.stdin.readline
from collections import deque

graph = [[] for _ in range(n+1)]
for _ in range(n-1):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

ini = 0

# calcの定義 : 2辺を合わせる演算
def calc(a,b):
    return a+b

# dp1の更新
def calc1(c,p):
    p_num = ini
    for i in graph[c]:
        if i == p:
            continue
        p_num = calc(p_num, dp1[i])
    dp1[c] = (p_num+1) % mod

# dp2の更新　累積和チックにすることでうに対策。
def calc2(p):
    arr = [dp1[c] if c != parent[p] else dp2[p] for c in graph[p]]

    left = [ini]
    for i in arr[:-1]:
        left.append( calc(left[-1], i ) )
    right = [ini]
    for i in arr[:0:-1]:
        right.append( calc(right[-1], i) )
    right = right[::-1]

    prod = []
    for a,b in zip(left,right):
        prod.append( calc(a,b) )

    for c,x in zip(graph[p], prod):
        if(c != parent[p]):
            dp2[c] = (x + 1) % mod


# 根から探索して親と探索順を記録
root = 1
order = []
parent = [0] * (n+1)
stack = deque()
stack.append(root)
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        stack.append(y)
        parent[y] = x

# 親→子の値を算出
dp1 = [0] * (n+1)
for i in order[::-1]:
    calc1(i, parent[i])

# 子→親の値を算出
dp2 = [0] * (n+1)
for i in order:
    calc2(i)

ans = 0
for i in range(1,n+1):
    gr = graph[i]
    if(len(gr) == 1):
        continue
    tmp = pow(2,n-1,mod) - 1
    for v in gr:
        if(v == parent[i]):
            exp_num = dp2[i]
        else:
            exp_num = dp1[v]
        tmp = (tmp - (pow(2, exp_num, mod)-1)) % mod
    ans = (ans + tmp) % mod


ans = ans * pow(pow(2,n,mod), mod-2, mod) % mod
print(ans)

Measured memory_bytes: 105940
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }


template<typename T>
std::vector<std::vector<T>> mk2d(size_t s1, size_t s2, T const& val) {
  std::vector<T> tmp(s2, val);
  return std::vector<std::vector<T>>(s1, tmp);
}


template<typename T>
std::vector<T> mk1d(size_t s, T const& val) {
  return std::vector<T>(s, val);
}

template<int64_t Prime>
struct mod_int {
  int64_t v_;
  mod_int(int64_t x=0) : v_(x) { normalize(); }
  void normalize() { ((v_ %= Prime) += Prime) %= Prime; }
  mod_int operator+=(mod_int const& r){ (v_ += r.v_) %= Prime; return *this; }
  mod_int operator-=(mod_int const& r){ (v_ += Prime - r.v_) %= Prime; return *this; }
  mod_int operator*=(mod_int const& r){ (v_ *= r.v_) %= Prime; return *this; }
  mod_int operator+(mod_int const& r) const { mod_int res(*this); return res += r; }
  mod_int operator-(mod_int const& r) const { mod_int res(*this); return res -= r; }
  mod_int operator*(mod_int const& r) const { mod_int res(*this); return res *= r; }
  mod_int pow(int x) const {
    int64_t res = 1, v = v_;
    while(x > 0) {
      if(x&1) (res *= v) %= Prime;
      x/=2; (v *= v) %= Prime;
    }
    return mod_int(res);
  }
  mod_int inv() const { return pow(Prime-2); }
};

int64_t const MOD = 998244353;
typedef mod_int<MOD> mint;

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string S; int K; std::cin >> S >> K;
  std::vector<int> a;
  int sum_one = 0, k = 0;
  for(auto it = S.rbegin(); it!= S.rend(); ++it) {
    if(*it == '1') ++sum_one;
    else if(sum_one > 0) { 
      a.push_back(sum_one);
      k += sum_one;
    }
  }
  if(K > sum_one*2) K = sum_one*2;
  auto tmp = mk2d(K+1, sum_one+1, mint(0)); 
  auto dp = mk1d(a.size()+1, tmp);
  dp[0][0][0] = 1;
  for(int i = 0; i < a.size(); ++i) {
    std::vector<std::vector<mint>>& cur = dp[i+1];
    std::vector<std::vector<mint>>& pre = dp[i];
    int ai1 = 0;
    if(i > 0) ai1 = a[i-1];
    for(int l = 0; l <= ai1; ++l) {
      int p = ai1 - l;
      for(int k = 0; k <= K; ++k) {
        int ma = std::min(K-k+p, a[i]-l);
        for(int j = 0; j <= std::min(p, ma); ++j) cur[k][a[i]-j] += pre[k][l];
        for(int j = p+1; j <= ma; ++j) cur[k+j-p][a[i]-j] += pre[k][l];
      }
    }
  }
  mint ans;
  for(int k = 0; k <= K; ++k) for(int l = 0; l <= sum_one; ++l) ans += dp[a.size()][k][l];
  fin(ans.v_);
  return 0;
}


Measured memory_bytes: 58572
import numpy as np
N = int(input())
value = 1

A = list(map(int, input(" ").split()))

if 0 in A:
  print(0)
else:
  for a in A:
    if value * a > 10**18:
      value = -1
      break
    else:
      value *= a
  print(value)

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    string S; cin >> S;
    int Q; cin >> Q;
    vector<char> p, q;
    bool f = false;
    rep(_, Q) {
      int T; cin >> T;
      if (T == 1) {
        f = !f;
      } else {
        int F; cin >> F;
        char c; cin >> c;
        if (!f) {
          if (F == 1) {
            p.pb(c);
          } else {
            q.pb(c);
          }
        } else {
          if (F == 1) {
            q.pb(c);
          } else {
            p.pb(c);
          }
        }
      }
    }
    if (f) reverse(all(S));
    if (!f) {
      string tmp = "";
      rrep(i, p.size()) tmp += p[i];
      tmp += S;
      S = tmp;
      rep(i, q.size()) S += q[i];
    } else {
      string tmp = "";
      rrep(i, q.size()) tmp += q[i];
      tmp += S;
      S = tmp;
      rep(i, p.size()) S += p[i];
    }
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 1476
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	n <- readInt
	ss <- group . sort <$> replicateM n getLine
	let
		kv = map ( head &&& length ) ss
 	printf "AC x %d\n" $ fromMaybe 0 $ lookup "AC" kv 
 	printf "WA x %d\n" $ fromMaybe 0 $ lookup "WA" kv 
 	printf "TLE x %d\n" $ fromMaybe 0 $ lookup "TLE" kv 
 	printf "RE x %d\n" $ fromMaybe 0 $ lookup "RE" kv 

Measured memory_bytes: 38692
n, m = map(int, input().split())
x = list(map(int, input().split()))

def solve():
  if n>=m:
    print(0)
    return
  x.sort()
  x_differ = [x[i+1]-x[i] for i in range(len(x)-1)]
  x_differ.sort(reverse=True)
  print(sum(x_differ[n-1:]))

solve()


Measured memory_bytes: 13968
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

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

    map<pair<int, int>, int> mp;

    rep(i, m) {
        int a, b;
        cin >> a >> b;
        mp[make_pair(a, b)] = 1;
        mp[make_pair(b, a)] = 1;
    }

    int flag = 0;
    for(int i = 2; i <= n-1; i++) {
        if(mp[make_pair(1, i)] && mp[make_pair(i, n)]) {
            flag = 1;
            break;
        }
    }

    if(flag) {
        cout << "POSSIBLE";
    }
    else {
        cout << "IMPOSSIBLE";
    }
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 37760
import java.util.Scanner;

public class Main {
	public static void main(String [] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		
		for(int i = 1; i <= n; i++) {
			 if (i % 3 == 0 || Integer.toString(i).contains("3")) {
		            System.out.print(" " + i);
		        } 
		}
		System.out.println();
	}
}


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

#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vl vector<ll>
#define vll vector<pll>
#define pb push_back
#define pll pair<ll,ll>
#define sl set<ll>
#define sll set<pll>
#define mp make_pair
#define ff first
#define ss second
#define rep(i,m,n) for(ll i=(m);i<=(n);i++)
#define rem(i,m,n) for(ll i=(m);i>=(n);i--)
#define FOR(i,v) for(auto &(i) : (v))
#define ub upper_bound
#define lb lower_bound
#define mset(x,val) memset((x),(val),sizeof((x)))
#define MAP map<ll,ll>
#define MAPs map<ll,sl>
#define MAPv map<ll,vl>

const ll   INF = 0x7f7f7f7f7f7f7f7f;
const ll NINF = -INF;
const ll MAXN  = 1e+6 + 8;

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

//<---------------------Declare global variables here------------------>//

//<---------------------Implement functions here------------------------->//



//<----------------------------Start of solve()------------------------------->//

void solve()
{
    string s;
    cin>>s;
    ll k=0;

    rep(i,0,s.size()-1)
    {
        k += (ll)(s[i]-48);
    }

    if(k%9)
    cout<<"No";
    else
    {
        cout<<"Yes";
    }
    

}


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

#ifndef ONLINE_JUDGE
    cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif

    return 0;
}

Measured memory_bytes: 3736
import sys
from collections import Counter
input = sys.stdin.readline
N = int(input())
xy = [tuple([int(i) for i in input().split()]) for _ in range(N)]
ary = []
if N == 1:
    print(1)
    exit()
for i, t in enumerate(xy[:-1]):
    x = t[0]
    y = t[1]
    for x2, y2 in xy[i+1:]:
        ary.append((x2-x, y2-y))
        ary.append((x-x2, y-y2))
c = dict(Counter(ary))
print(N-max(c.values()))


Measured memory_bytes: 39408
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string a;
	cin>>a;
	int tmp=a.find("ST");
	while(a.length()>0&&tmp>=0)
	{
		a.erase(tmp,2);
		int x=max(tmp-1,0);
		tmp=a.find("ST",x);
		if(tmp==x&&(a[tmp]!='S'||a[tmp+1]!='T'))
			tmp=-1;
	}
	cout<<a.length()<<endl;
	return 0;
} 

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

int a, b;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	if (b%a == 0) cout << a + b;
	else cout << b - a;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a[3], b[3];
  scanf("%d %d %d", &a[0], &a[1], &a[2]);
  if (a[0] < a[1]) {
    if (a[0] < a[2]) {
      b[0] = a[0];
      if (a[1] < a[2]) {
	b[1] = a[1];
	b[2] = a[2];
      }
      else {
	b[1] = a[2];
	b[2] = a[1];
      } 
    }
    else {
      b[0] = a[2];
      b[1] = a[0];
      b[2] = a[1];
    }
  }
  else {
    if ( a[2] < a[1] ) {
      b[0] = a[2];
      b[1] = a[1];
      b[2] = a[0];
    }
    else {
      b[0] = a[1];
      if (a[0] < a[2]){
	b[1] = a[0];
	b[2] = a[2];
      }
      else {
	b[1] = a[2];
	b[2] = a[0];
      }
    }
  }
  printf ("%d %d %d\n", b[0], b[1], b[2]);
  return 0;
}



Measured memory_bytes: 2120
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		
		long ans = 0;
		
		for(long mod=1; (N-mod)/mod > mod; mod++) {
			if((N-mod)%mod==0)
				ans += (N-mod)/mod;
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ll long long int
using namespace std;

const ll mod = 1000000007;

void solve() {
	int n; cin >> n;
	vector<ll> a(n);
	ll s = 0, ss = 0;
	for (auto &x : a) {cin >> x; s = (s + x) % mod; ss = (ss + (x * x)) % mod;}
	s = (s * s) % mod;
	cout << (((s - ss + mod) % mod) * 500000004) % mod;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin >> t;
	t = 1;
	while (t--) {
		solve();
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 4728
def bfs(G, s):
    d = {key: -1 for key in G.keys()}
    d[s] = 0
    Q = [s]
    while len(Q) > 0:
        u = Q.pop(0)
        for v in G[u]:
            if d[v] < 0:
                d[v] = d[u] + 1
                Q.append(v)

    return d


if __name__ == '__main__':
    G = {}
    n = int(input())
    for _ in range(n):
        tmp = list(map(int, input().split()))
        u = tmp.pop(0)
        k = tmp.pop(0)
        G[u] = tmp
    d = bfs(G, 1)
    for node in G:
        print('{0} {1}'.format(node, d[node]))

Measured memory_bytes: 7700
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

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;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n, d, a; cin >> n >> d >> a;
    vector<P> x_h(n);
    rep(i, n) cin >> x_h[i].first >> x_h[i].second;
    sort(ALL(x_h));
    ll ans = 0, range_sum = 0;
    queue<P> bombs;
    rep(i, n) {
        while (!bombs.empty() && bombs.front().first < x_h[i].first) {
            range_sum -= bombs.front().second * a;
            bombs.pop();
        }
        x_h[i].second = max(0ll, x_h[i].second - range_sum);
        if (x_h[i].second <= 0) continue;
        ll cur = x_h[i].first + 2 * d;
        ll cur_need = (x_h[i].second + a - 1) / a;
        ans += cur_need;
        range_sum += cur_need * a;
        bombs.push(P(cur, cur_need));
    }
    cout << ans << endl;
}

Measured memory_bytes: 7884
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 105000000000

const int maxn = 1e5 + 10;

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

	int idx[50] = { 0 };

	rep(i, s.length()) {
		if (idx[(int)(s[i] - 'a')] == 1) { no; return 0; }
		idx[(int)(s[i] - 'a')] = 1;
	}
	yes;
	return 0;
	
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] l=new String[6];
        Arrays.fill(l, ":");
        while (n-- > 0) {
           int t=((int)sc.nextDouble()-160)/5;
           l[t<0?0:t>5?5:t]+="*";
        }
        for(int i=1;i<7;i++) {
            System.out.println(i+l[i-1]);
        }
    }
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n+1);
  vector<int> c(n+1);
  for(int i = 0; i <= n; ++i){
    c[i] = 0;
  }
  for(int i = 0; i < n; ++i){
    cin >> a[i];
    c[a[i]]++;
  }
  int p = 0;
  for(int i = 0; i <= n; ++i){
    if(c[i] != 0){
      ++p;
    }
  }
  sort(c.begin(),c.end());
  int res = 0;
  int j = 0;
  while(p > k){
    if(c[j] == 0){
      ++j;
      continue;
    }
    res += c[j];
    c[j] = 0;
    --p;
  }
  cout << res;
}

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

int main() {
  int N;
  cin >> N;
  vector<string>W(N);
  for (int i = 0; i < N; i++) {
    cin >> W.at(i);
  }
  bool ans = true;
  for (int i = 0; i < N - 1; i++) {
    if (W.at(i)[W.at(i).length() - 1] != W.at(i + 1)[0]) {
      ans = false;
    }
  }
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (W.at(i) == W.at(j)) {
        ans = false;
      }
    }
  }
  if (ans) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

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

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

	int res = 1e6;
	for (int i = 0; i < pow(10, n); i++) {
		int j = i;
		int tres = 0;
		for (int idx = 0; idx < n; idx++) {
			tres += c[j % 10];
			j /= 10;
		}
		if (tres <= m)	res = min(res, i);
	}
	if (res == 1e6)cout << "NA" << endl;
	else {
		string s = to_string(res);
		while (s.size() < n)s = "0" + s;
		cout << s << endl;
	}
	return 0;
}


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

import numpy
import scipy

N = int(input())
A = list(map(int, input().split()))
#print(A)

c = 0
flg = False
while True:
    #print(A)
    for i, a in enumerate(A):
        if a%2 == 0:
            A[i] /= 2
            #pass
        else:
            flg = True
            break
    if flg:
        break
    c += 1
print(c)

Measured memory_bytes: 12508
H,W = map(int,input().split())
A = []
for i in range(H):
  A.append(list(input()))

for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      print("#",end="")
    elif A[h][w] == ".":
      c = 0 
      for i in range(-1,2):
        for j in range(-1,2):
          if 0<=h+i<=H-1 and 0<=w+j<=W-1 and A[h+i][w+j]=="#":
            c+=1
      print(c,end="")
  print("")

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
int main(){
    LL ans = 0, l, r;
    scanf("%d", &n);
    for(LL i = 1; i <= n; i++){
        ans += i * (n - i + 1);
    }
    for(int i = 1; i < n; i++){
        scanf("%lld%lld", &l, &r);
        if(r < l) swap(l, r);
        ans -= l * (n - r + 1);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    string s;cin >> s;
    vector<int> ans(s.size());
    int ind;
    vector<int> q;
    bool change = false;
    rep(i,s.size()){
        if(s[i]=='R' && !change){
            q.push_back(i);
        }else if(s[i]=='L' && !change){
            ind = i;
            change = true;
            for(auto t : q){
                if((i-t)%2==0){
                    ans[i]++; // R
                }else{
                    ans[i-1]++; // R
                }
            }
            ans[i]++; // L
        }else if(change && s[i]=='L'){
            if((i-ind)%2==0){
                ans[ind]++;
            }else{
                ans[ind-1]++;
            }
        }else{
            change = false;
            q.clear();
            q.push_back(i);
        }
    }
    for(auto t : ans){
        cout << t << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1528
A = input()
arr1 = [i for i in A.split(' ')]
if(arr1[0]==arr1[1]==arr1[2]):
	print('No')
elif((arr1[0]!=arr1[1]) and (arr1[0]!=arr1[2]) and (arr1[1]!=arr1[2])):
	print('No')
else:
	print('Yes')

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  string s;
  cin >> s;
  int ans=0;
  int d=0;
  vector<int> count={0,0,0,0};
  rep(i,s.length()){
    if(s[i]=='L'){
      d=(d+3)%4;
    }else if(s[i]=='R'){
      d=(d+1)%4;
      count[d]++;
    }
    if(d==0){
      rep(i,4) if(count[i]==0) goto next;
      ans++;
      next:;
      count={0,0,0,0};
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3204
//cara pikir 
//pake recursive tapi gak 3 x
// C++ program for implementation of Ford Fulkerson algorithm 
#include <iostream> 
#include <limits.h> 
#include <string.h> 
#include <queue> 
#include <iostream> 
#include <set> 
#include <iterator> 
#include <algorithm>
#include <map>
using namespace std;
int main(){
  int num,base,digit;
  digit=0;
  cin>>num>>base;
 
    while(num/base!=0)
    {digit++;
    num=num/base;
    }
  
  cout<<digit+1;
 
}

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

using namespace std;
typedef pair<pair<int, int>, string> P;

int main() {
	int n;
	cin >> n;
	P a[100];
	for (int i = 0; i < n; i++) {
		cin >> a[i].second >> a[i].first.second;
		a[i].first.first = i;
	}
	sort(a, a + n, [](P b, P c) {
		{
			for (int i = 0; i < min(b.second.size(), c.second.size()); i++) {
				if (b.second[i] < c.second[i])return true;
				else if (b.second[i] > c.second[i])return false;
			}
			if (b.second.size() > c.second.size())return false;
			if (b.second.size() < c.second.size())return true;
		}
		if (c.first.second < b.first.second)return true;
		else if (c.first.second > b.first.second)return false;
	});

	for (int i = 0; i < n; i++) {
		cout << a[i].first.first + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define fore(e, u, v) for (int p = e(u), v = e[p].y; p; v = e[p = e[p].nxt].y)
#define ri rd<int>
using namespace std;
const int maxN = 207;
const int maxM = 10007;
const int INF = 1e9 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

int n, m;
char s[maxN][maxN];
int S = 0, T = 202;
int sx, sy, tx, ty;
int lev[maxN];

struct vec {
	static const int maxE = maxM;
	int g[maxN], te;
	struct edge {int y, f, nxt;} e[maxE << 1];
	vec() {te = 1;}
	inline void push(int x, int y, int f) {e[++te] = (edge){y, f, g[x]}; g[x] = te;}
	inline void push2(int x, int y, int f) {push(x, y, f), push(y, x, f);}
	inline void link(int x, int y, int f) {push(x, y, f), push(y, x, 0);}
	inline int& operator () (int x) {return g[x];}
	inline edge& operator [] (int x) {return e[x];}
}e;

bool bfs() {
	static int q[maxN]; int h = 0, t = 1;
	q[1] = S; memset(lev, 0, sizeof lev); lev[S] = 1;
	while (h != t) {
		int x = q[++h];
		fore (e, x, y) if (e[p].f && !lev[y]) {
			lev[y] = lev[x] + 1;
			q[++t] = y;
			if (y == T) return 1;
		}
	}
	return 0;
}

int dfs(int x, int fl) {
	if (x == T) return fl;
	int tp, res = 0;
	fore (e, x, y) if (e[p].f && lev[x] + 1 == lev[y]) {
		tp = dfs(y, min(fl, e[p].f));
		if (tp) {
			fl -= tp;
			res += tp;
			e[p].f -= tp;
			e[p^1].f += tp;
			if (fl == 0) return res;
		}
	}
	if (res == 0) lev[x] = 0;
	return res;
}

int main() {

	n = ri(), m = ri();
	rep (i, 1, n) scanf("%s", s[i]+1);

	rep (i, 1, n) rep (j, 1, m) if (s[i][j] != '.')
		e.push2(i, n+j, s[i][j] == 'o' ? 1 : INF);
	rep (i, 1, n) rep (j, 1, m) {
		if (s[i][j] == 'S') e.link(S, sx = i, INF), e.link(S, sy = n+j, INF);
		if (s[i][j] == 'T')	e.link(tx = i, T, INF), e.link(ty = n+j, T, INF);
	}

	if (sx == tx || sy == ty) {puts("-1"); return 0;}

	int ans = 0;
	while (bfs())
		ans += dfs(S, INF);
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <cstdlib>
#include <cstring>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <random>

#define ll long long

using namespace std;

const ll mod = 1e9 + 7;

vector<int> top_sort;

void dfs(vector<vector<int>> &g, int v, int p) {
    for (int next : g[v]) {
        if (next != p) {
            dfs(g, next, v);
        }
    }
    top_sort.push_back(v);
}

int main() {
    //freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
    int n;
    scanf("%d", &n);
    vector<vector<int>> g(n + 1);
    for (int i = 1; i < n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        g[x].push_back(y);
        g[y].push_back(x);
    }
    vector<vector<ll>> dp(n + 1, vector<ll>(2 + 1, 0));
    dfs(g, 1, -1);
    vector<bool> used(n + 1, false);
    for (int i = 0; i < top_sort.size(); i++) {
        int v = top_sort[i];
        used[v] = true;
        bool isLeaf = true;
        ll k1 = 1;
        ll k2 = 1;
        for (int next : g[v]) {
            if (used[next]) {
                isLeaf = false;
                k1 = (k1 * ((dp[next][1] + dp[next][2]) % mod)) % mod;
                k2 *= dp[next][1];
                k1 %= mod;
                k2 %= mod;
            }
        }
        if (isLeaf) {
            dp[v][1] = 1ll;
            dp[v][2] = 1ll;
        } else {
            dp[v][1] += k1;
            dp[v][2] += k2;
        }
    }
    printf("%lld", (dp[1][1] + dp[1][2]) % mod);
    return 0;
}

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

int main()
{
  int N, count;
  count = 0;
  cin >> N;
  
  int A[N];
  for(int i = 0; i < N; i++)
    cin >> A[i];
  
  bool canCalc = true;
  while(canCalc)
  {
    for(int i = 0; i < N; i++)
    {
      if(A[i] % 2 == 0)
        A[i] /= 2;
      else
      {
        canCalc = false;
		cout << count << endl;
	    return 0;
      }        
    }
    
    if(canCalc)
      count++;
  }
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
#define INF (1e9)

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

typedef long long ll;

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

    int n;
    cin >> n;

    ll big_sum = 0;
    vector<ll> cum_sum(n);
    rep(i, n){
        ll a;
        cin >> a;
        big_sum += a;

        if(i > 0){
            cum_sum[i] = cum_sum[i-1] + a;
        }else{
            cum_sum[i] = a;
        }
    }


    ll min_val = LLONG_MAX;
    rep(i, n-1){
        min_val = min(min_val, llabs(2 * cum_sum[i] - big_sum));
    }

    cout << min_val << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main (void){

    int b = 0, c;
    string a;
    cin >> a;
    if(a[0] == '0'){
        cout << "Yes" << endl;
        return 0;
    }
    c = a.length();
    for(int i = 0;i < c;i++){
        b = b + a[i] -'0';
    }

    if(b % 9 == 0)
        cout << "Yes" << endl;
    else 
        cout << "No" << endl;
}

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

const int maxn = 1e5+5;
int n, a[maxn];
const int M = 1e9+7;
int mult(int a, int b) {
    return (1LL*a*b) % M;
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    int r = -1, b = -1, g = -1;
    int ans = 1;
    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        if (r == a[i]-1) cnt++;
        if (g == a[i]-1) cnt++;
        if (b == a[i]-1) cnt++;
        //cout << i << ": " << cnt << '\n';
        ans = mult(ans,cnt);
        if (r == a[i]-1) r++;
        else if (b == a[i]-1) b++;
        else if (g == a[i]-1) g++;
    }
    cout << ans << '\n';
}



Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define SG getchar()
#define SR ((bool)(SG-48))
using namespace std;
signed main()
{
	printf("%d",(SR+SR+SR+SR+SR+SR));
	return putchar(10),0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;

int main() {
    string s;
    cin >> s;
    int start = s.find('A');
    int end = s.find_last_of('Z');
    cout << end - start + 1 << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second

using namespace std;

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

const int N = 100;
int v[N][N];

vector<int> G[N];

int used[N];

int dfs(int v){
	used[v] = 1;
	int res = 0;
	for (auto &to : G[v]){
		if (used[to]) continue;
		res = max(res, dfs(to)+1);
	}
	used[v] = 0;
	return res;
}

int main(){
	int n;
	while(cin >> n, n){
		MEMSET(v, 0);
		rep(i, N) G[i].clear();
		rep(i, n){
			int x, y;
			cin >> x >> y;
			--x, --y;
			v[x][y] = v[y][x] = 1;
		}
		rep(i, N) rep(j, N) if (v[i][j]) G[i].push_back(j);
		int ans = 2;
		rep(i, N) ans = max(ans, dfs(i)+1);
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1256