akhauriyash/Code-Regression huggingface dataset:
use proconio::{input, marker::Usize1};

fn main() {
    input!(n: usize, m: usize, ab: [(Usize1, Usize1); m]);
    let mut ckd = vec![(false, false); n];
    for (a, b) in ab {
        if a == 0 {
            ckd[b].0 = true;
        }
        if b == 0 {
            ckd[a].0 = true;
        }
        if a == n - 1 {
            ckd[b].1 = true;
        }
        if b == n - 1 {
            ckd[a].1 = true;
        }
    }
    println!(
        "{}",
        if ckd.iter().any(|&(x, y)| x && y) {
            "POSSIBLE"
        } else {
            "IMPOSSIBLE"
        }
    );
}


Measured memory_bytes: 8056
import Data.List (sortBy,group)
import Control.Arrow ((&&&))

main :: IO ()
main = do
  _ <- read <$> getLine :: IO Int
  as <- map (fromIntegral.length&&&head).group.sortBy (flip compare).map read.words <$> getLine :: IO [(Integer,Integer)]
  let ls = filter ((>1).fst) as
  if length ls > 1
    then
      if (fst.head) ls > 4
        then print ((snd.head) ls*(snd.head) ls)
        else print ((snd.head) ls*(snd.head.tail) ls)
    else print 0


Measured memory_bytes: 39932
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,i,n,t,r,cnt=0,x,s=0;
   char ch[100];

   cin>>ch;
    n=*ch;
if(n>='A'&&n<='Z')
{
    cout<<"A"<<endl;
}
else if(n>='a'&& n<='z')
{
    cout<<"a"<<endl;
}
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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 gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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

int main(){
ll n;
cin>>n;
map<string,map<ll,ll>>rensou;
string s;
ll p;
for(int i=0;i<n;i++){
    cin>>s>>p;
    rensou[s][100-p]=i;
}
for(auto f:rensou){
    for(auto g:rensou[f.first]){
        cout<<g.second+1<<endl;
    }
}
}











Measured memory_bytes: 256
_,a,b,c,d=gets.split.map{|m| m.to_i-1 }
s=gets.chomp
if s[a..[c,d].max].index(/\#{2,}/)
  puts "No"
else
  if c > d
    if  s[b-1..d+1].index(/\.{3,}/)
      puts "Yes"
    else
      puts "No"
    end
  else
    puts "Yes"
  end
end

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int N;
vecs(S);

void create(string sum,string code, int count) {
	
	if (count==N) {
		pb(S, sum);
		//ce(sum)
		return;
	}

	for (int i = 1; i <= N; i++) {
		if (code[i-1]=='0') {
			code[i - 1] = '1';
			//sum += to_string(i);
			create(sum+to_string(i), code,count+1);
			code[i - 1] = '0';
			//sum.erase(sum.begin() + count,sum.begin()+count);
		}
	}

}

int find(string X) {
	fx(S.size()) {
		if (S[x]==X) {
			return x;
		}
	}
}

int main()
{

	cin >> N;
	
	for (int i = 1; i <= N;i++) {
		string res = to_string(i);
		string code = string(N,'0');
		code[i - 1] = '1';
		create(res, code, 1);
	}

	sorts(S);
	string P, Q;
	fx(N) {
		string p;
		cin >> p;
		P += p;
	}
	fx(N) {
		string q;
		cin >> q;
		Q += q;
	}

	ce(abs(find(P)-find(Q)))


    return 0;
}



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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PI;

// res: bridges
// v: current node
// from: parent node
int dfs(VVI& g, vector<PI>& res, int v, int& count, int from, VI& low, VI& pre) {
  pre[v] = count++;
  low[v] = pre[v];
  for (VI::iterator it = g[v].begin(); it != g[v].end(); it++) {
    int to = *it;
    if (pre[to] == -1) {
      // destination has not been visited
      // visit destination and update low[v]
      low[v] = min(low[v], dfs(g, res, to, count, v, low, pre));
      if (low[to] == pre[to]) {
        // edge is not contained in a closed path -> bridge
        res.push_back(make_pair(v, to));
      }
    } else {
      if (from == to) {
        // ignore a path to parent
        continue;
      }
      low[v] = min(low[v], low[to]);
    }
  }
  return low[v];
}

// Calculate bridges in a undirected graph.
// Assume graph is connected and has no parallel edges or self-loops.
// g: adjacency list
// V: number of nodes
vector<PI> bridges(VVI& g, int V) {
  vector<PI> res;
  if (V > 0) {
    // assume at least the first vertex exists
    VI low(V, -1);  // lowest reacheable index
    VI pre(V, -1);  // pre-order index
    int count = 0;  // pre-order index counter
    dfs(g, res, 0, count, -1, low, pre);  // start dfs from vertex 0
  }
  return res;
}

int main(void){
    int N,M;
    cin>>N>>M;
    vector<vector<int>> g(N);
    rep(i,M){
        int a,b;
        cin>>a>>b;
        a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<PI> res = bridges(g,N);
    cout<<res.size()<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,s=0;
	cin>>n>>m;
	for(int i = 0,a ; i < m ; i ++){
		cin>>a;s+=a;
	}
	if(s>n)cout<<-1;
	else cout<<n-s;
}

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

using namespace std;

int main() {
  int N, L;
  cin >> N >> L;

  int cand = 100000;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int val = L + i;
    if (abs(cand) >= abs(val)) {
      cand = val;
    }
    sum += val;
  }
  cout << sum - cand << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
P x[8];
int mypow(int a,int b,int c){
	if(b==0)return 1;
	else if(b%2)return mypow(a,b-1,c)*a%c;
	int z=mypow(a,b/2,c);
	return z*z%c;
}
signed main(){
	int n,z=1;
	double ans=0;
	cin>>n;
	f(i,n){
		cin>>x[i].F>>x[i].S;
		z*=i+1;
	}
	sort(x,x+n);
	do{
		f(i,n-1){
			ans+=sqrt(pow(x[i+1].F-x[i].F,2)+pow(x[i+1].S-x[i].S,2));
		}
	}while(next_permutation(x,x+n));
	ans/=z;
	printf("%.100lf",ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a+b == 3)
		printf("3\n");
	else if(a + b == 4)
		printf("2\n");
	else
		printf("1\n");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void){

  int i, j, H, W;

  while(1){
    scanf("%d %d", &H, &W);
    if(H == 0 && W == 0){
      break;
    }
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }


  return 0;

}



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

int main() {
  int N, p[50], count=0;
  cin >> N;
  for(int i=0; i<N; ++i) cin >> p[i];
  for(int i=0; i<N; ++i)
    if(p[i]!=i+1) ++count;
  cout << ((count<=2)?"YES":"NO") << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a-1; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<vector<char>> g;
int main(){
    ll h, w;    cin >> h >> w;
    g.assign(h, vector<char>(w));
    rep(i, h)   rep(j, w) cin >> g[i][j];
    vector<vector<ll>> dp(h, vector<ll>(w, 0));
    dp[0][0] = 1;
    rep(i, h) rep(j, w){
        if(g[i][j]=='#') continue;
        if(0<i) dp[i][j] = (dp[i][j]+dp[i-1][j])%MOD;
        if(0<j) dp[i][j] = (dp[i][j]+dp[i][j-1])%MOD;
    }
    cout << dp.back().back() << endl;
}


Measured memory_bytes: 12212
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
#define pb push_back
#define PI 3.14159265
int M = 1000000007;
int divi[10000001];
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i < 10000001; ++i)
  {
    for (int j = 1; j * i < 10000001; j++)
    {
      divi[i * j]++;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i)
  {
    ans += i * divi[i];
  }
  cout << ans;
}


Measured memory_bytes: 81776
#!/usr/bin/env python3
import sys


def solve(N: int):
    count = 0
    for x in range(1, N+1):
        x_str = str(x)
        if len(x_str) % 2 != 0:
            count += 1
    print(count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
#define LEN  1001
int Position[LEN][LEN];//每个坐标都是LCS的长度
int includeGetLCS(string first, string second)
{
	int firstlen = first.size();
	int secondlen = second.size();//得到string的长度
	first = " " + first, second = " " + second;//在前面加个空格，以便下面；
	int Position[LEN][LEN];//每个坐标都是LCS的长度
	for (int i = 0; i <= secondlen; i++) Position[0][i]=0;//任意一方没有数据，LCS为0；
	for (int i = 1; i <=firstlen; i++)Position[i][0]=0;
	for (int i = 1; i <= firstlen; i++)
	{
		for (int j = 1; j <= secondlen; j++)
		{
			if (first[i] == second[j])//最后一个相等时候
				Position[i][j] = Position[i - 1][j - 1] + 1;//前面的LCS+1；
			else
			{
				if (Position[i][j - 1] >= Position[i - 1][j])//不相等的时候，比较各自减一的LCS，取最大的那个LCS
					Position[i][j] = Position[i][j - 1];
				else
					Position[i][j] = Position[i - 1][j];
			}
		}

	}
int max=0;
	if (max >= Position[firstlen][secondlen])
		return max;
	else
		return	Position[firstlen][secondlen];
}
int main()
{
	string first, second;
	int number;
	cin >> number;
	for (int i = 0; i < number; i++)
	{
		cin >> first>>second;
		cout << includeGetLCS(first, second)<<endl;
	}
}






Measured memory_bytes: 7096
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64

int main(){
    int n;
    cin >> n;
    if(n%10==9 or n/10==9) cout << "Yes" << endl;
    else cout <<"No"<< endl;
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int main(){
  fastIO;
  int n;
  cin >> n;
  int a = (n+1)/2;
  double f = a/(double)n;
  cout << fixed << setprecision(7) << f << "\n";
  return 0;
}

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

int main()
{
    int N, Ma, Mb;

    std::cin >> N >> Ma >> Mb;
    std::vector<int> a(N), b(N), c(N);
    for (int i = 0; i < N; i++) {
        std::cin >> a[i] >> b[i] >> c[i];
    }

    constexpr int MAX = 400;
    constexpr int INF = 1e9;
    std::vector<std::vector<int>> dp(MAX + 1, std::vector<int>(MAX + 1, INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++)
        for (int j = MAX; j >= 0; j--)
            for (int k = MAX; k >= 0; k--) {
                if (dp[j][k] == INF) continue;
                int nj = j + a[i], nk = k + b[i];
                dp[nj][nk] = std::min(dp[nj][nk], dp[j][k] + c[i]);
            }

    int min_cost = INF;
    for (int i = 1; i <= MAX / std::max(Ma, Mb); i++) {
        min_cost = std::min(min_cost, dp[Ma * i][Mb * i]);
    }
    std::cout << (min_cost == INF ? -1 : min_cost) << std::endl;
    return 0;
}

Measured memory_bytes: 896
import bisect
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    A, B, Q = map(int, input().split())
    inf = float('inf')
    S = [-inf] + [int(input()) for _ in range(A)] + [inf]
    T = [-inf] + [int(input()) for _ in range(B)] + [inf]

    for q in range(Q):
        x = int(input())
        i = bisect.bisect_right(S, x)
        j = bisect.bisect_right(T, x)
        d = inf
        for s in [S[i-1], S[i]]:
            for t in [T[j-1], T[j]]:
                d1 = abs(s-x)+abs(s-t)
                d2 = abs(t-x)+abs(s-t)
                d = min(d, d1, d2)
        print(d)


if __name__ == '__main__':
    main()


Measured memory_bytes: 79324
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n ;
  set<char> st;
  rep(i,n){
    char c; cin >> c;
    st.insert(c);
  }

  cout << (st.size()==4?"Four":"Three") << endl;
  return 0;
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> grid(H);
    for (int i=0; i < H; i++){
        cin >> grid[i];
    }

    vector<int> W_no(W, -1);
    for (int i=0; i < W; i++){
        bool loop = false;

        for (int j = 0; j < H; j++){
            if (grid[j][i] == '#'){
                loop = true;
                
               break;
            }
        }

        if (loop == false){
            W_no[i] = i;
                
        }
    }

    string skip(W,'.');
    for (int i = 0; i < H; i++){
        if (grid[i] != skip){
            for (int j = 0; j < W; j++){
                if (count(W_no.begin(), W_no.end(), j) == 0){
                    cout << grid[i][j];
                }
            }
            cout << endl;
        }
    }

}


Measured memory_bytes: 256
import math
MAX = 1000000
A = [1]*MAX

for i in range(2,int(math.sqrt(MAX))+1):
    if A[i]==1:
        for j in range(2*i,MAX,i):
            A[j]=0
A[0]=0
A[1]=0
for i in range(1,MAX):
    A[i] += A[i-1]

while True:
    try:
        n = int(input())
    except:
        break
    print(A[n])


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

using namespace std;

int main(void) {
    string S;
    cin >> S;
    if(S == "Sunny") {
        cout << "Cloudy" << endl;
    } else if(S == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;
	cin >> n;
	vector<int> num(n);
	set<int> ki;
	set<int> gu;
	REP(i, n) {
		cin >> num[i];
		if (i % 2 == 0)
			gu.insert(num[i]);
		else
			ki.insert(num[i]);
	}
	SORT(num);
	int ans = 0;
	REP(i, n) {
		if (i % 2 == 0 && gu.find(num[i]) == gu.end()) {
			ans++;
		}
		if (i % 2 != 0 && gu.find(num[i]) != gu.end()) {
			ans++;
		}
}
	cout << ans / 2 << endl;
}

Measured memory_bytes: 5376
#include <cmath>
#include <string.h>
#include <iostream>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

#define rep(i, j, n) for (int i = j; i < n; i++)
#define rep_nested(i, s, n) for (int i = s; i <= n; i++)
#define ll long long
#define ull unsigned long long

const int N = 500;
const ll INF = 1000000007;

using namespace std;

template <class T>
T limit(T n, T k) {
	return (n > k) ? k : n;
}

template <class T>
T has_order(T a, T b, T c) {
	return (b > a && b < c) || (b < a && b > c);
}

template <class T>
float points_distance(T a) {
	return sqrt(a);
}

template <class T>
T is_integer(T a) {
	return floor(a) == a;
}

int main() {
	int n, d, r = 0, tmp;
	
	cin >> n >> d;
	
	vector<vector<int> > v(n, vector<int>(d));
	
	rep(i, 0, n) rep(j, 0, d) {
		cin >> v[i][j];
	}
	
	rep(i, 0, n - 1) {
		rep(k, i + 1, n) {
			tmp = 0;
			rep(j, 0, d) {
				tmp += (v[i][j] - v[k][j]) * (v[i][j] - v[k][j]);
			}
			r += is_integer(points_distance(tmp));
		}
	}
	
	cout << r << endl;
	
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
template <class T>bool chmax(T &a, const T &b){if (a < b){a = b;return 1;}return 0;}
template <class T>bool chmin(T &a, const T &b){if (b < a){a = b;return 1;}return 0;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

struct UnionFind{
  int num;
  vector<int> rs,ps;
  UnionFind(){}
  UnionFind(int n):num(n),rs(n,1),ps(n,0){iota(ps.begin(),ps.end(),0);}
  int find(int x){
    return (x==ps[x]?x:ps[x]=find(ps[x]));
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  void unite(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(rs[x]<rs[y]) swap(x,y);
    rs[x]+=rs[y];
    ps[y]=x;
    num--;
  }
  int size(int x){
    return rs[find(x)];
  }
  int count() const{
    return num;
  }
};
 

int main(){
  ll n;
  cin >> n;
  ll m;
  cin >> m;
  UnionFind tree(n);
  rep(i,m){
    ll a;
    cin >> a;
    ll b;
    cin >> b;
    tree.unite(a-1,b-1);
  }
  cout<<tree.count()-1<<endl;
}


Measured memory_bytes: 4048
s = input()
if s == "SAT":
    print(1)
elif s == "FRI":
    print(2)
elif s == "THU":
    print(3)
elif s == "WED":
    print(4)
elif s == "TUE":
    print(5)
elif s == "MON":
    print(6)
elif s == "SUN":
    print(7)

Measured memory_bytes: 3064
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<String,Integer> map = new HashMap<>();
        for (int i = 0; i < N; i++) {
            String S = sc.next();
            map.put(S,map.getOrDefault(S,0)+1);
        }

        StringBuilder ans = new StringBuilder();
        ans.append("AC x ").append(map.getOrDefault("AC",0)).append('\n');
        ans.append("WA x ").append(map.getOrDefault("WA",0)).append('\n');
        ans.append("TLE x ").append(map.getOrDefault("TLE",0)).append('\n');
        ans.append("RE x ").append(map.getOrDefault("RE",0)).append('\n');

        System.out.print(ans);
    }
}


Measured memory_bytes: 56292
#include <iostream>

using i64 = long long;

const int N = 500 + 7;

int n;
i64 a[N][N], f[N][N], g[N][N], h[N][N], ans;

i64 s(i64 f[N][N], int i1, int i2, int j1, int j2) {
	return f[i2][j2] + f[i1][j1] - f[i2][j1] - f[i1][j2];
}

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j) {
			if (i != j) scanf("%lld", a[i] + j);
			(i < j ? f[i][j] : g[j][i]) = a[i][j];
		}
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			f[i][j] += f[i - 1][j] + f[i][j - 1] - f[i - 1][j - 1],
			g[i][j] += g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];
	ans = s(g, 0, n, 0, n);
	for (int i = 1; i < n; ++i) {
		h[i][0] = s(f, 0, i, i, i + 1) + s(g, 0, i, 0, i + 1);
		for (int j = 1; j < i; ++j)
			for (int k = 0; k < j; ++k)
				h[i][j] = std::max(h[i][j], h[j][k] + s(f, 0, i, i, i + 1) + s(f, 0, j, j + 1, i) + s(g, j, i, i, i + 1) + s(g, k, i, j + 1, i) );
	}
	for (int i = 1; i < n; ++i)
		for (int j = 0; j < i; ++j)
			ans = std::max(ans, h[i][j] + s(f, 0, i, i + 1, n) + s(g, j, n, i + 1, n));
	printf("%lld\n", s(f, 0, n, 0, n) + s(g, 0, n, 0, n) - ans);
	return 0;
}


Measured memory_bytes: 11756
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    k = int(ipt())
    s = input()
    ls = len(s)
    mod = 10**9+7
    #nCrをmodで割った余りを求める。Nに最大値を入れて使用。
    N = 2*10**6
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    def cmb(n,r,mod):
        if r<0 or r>n :
            return 0
        r = min(r,n-r)
        return g1[n]*g2[r]*g2[n-r]%mod
    for i in range(2,N+1):
        g1.append((g1[-1]*i)%mod)
        inverse.append((-inverse[mod % i]*(mod//i))%mod)
        g2.append((g2[-1]*inverse[-1])%mod)

    ans = 0
    s25 = [1]
    s26 = [1]
    for i in range(k+1):
        s25.append(s25[-1]*25%mod)
        s26.append(s26[-1]*26%mod)

    for i in range(ls):
        ans = (ans+s25[k]*cmb(k+i-1,i,mod)%mod)%mod
    for i in range(1,k+1):
        ans = (ans+s25[k-i]*s26[i]%mod*cmb(k+ls-1-i,ls-1,mod)%mod)%mod
    print(ans)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 243636
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] line = str.split("");
        String temp = line[0];
        int changeIndex = 0;
        int count = 0;
        for(int i = 1; i < line.length; i++){
            if(temp.equals(line[i])){
                if(line[i].equals("0")){
                    line[i] = "1";
                }else{
                    line[i] = "0";
                }
                count++;
            }
            temp = line[i];
        }
        System.out.println(count);
        
    }
}


Measured memory_bytes: 32712
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sA = sum(A)
for i in range(N):
    b = B[i]
    if A[i] != 0:
        x = min(b, A[i])
        A[i] -= x
        b -= x
    x = min(b, A[i+1])
    A[i+1] -= x

print(sA - sum(A))


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

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> x[i] >> y[i] >> a[i];

    int wl = 0, wr = w;
    int hl = 0, hr = h;
    for (int i=0; i<n; i++) {
        if (a[i] == 1) {
            wl = max(wl, x[i]);
        } else if (a[i] == 2) {
            wr = min(wr, x[i]);
        } else if (a[i] == 3) {
            hl = max(hl, y[i]);
        } else if (a[i] == 4) {
            hr = min(hr, y[i]);
        }
    }

    int ww = wr - wl;
    int hh = hr - hl;

    if (ww > 0 && hh > 0) cout << ww * hh << endl;
    else cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	int height,width;
    char dot = '.';
    char frame = '#';
    char printChar;
    bool isOver = false;
    while(!isOver){
        cin>>height>>width;
        if(height ==0 && width == 0){
            isOver = true;
            break;
        }else{
            //add frame ops
            for(int i=0;i<height;i++){
                for(int j = 0;j<width;j++){
                    
                    if(i==0||i==height-1||j==0||j==width-1){
                        printChar = frame;
                    }
                    cout<<printChar;
                    printChar = dot;
                }
                cout<<endl;
            }
        }
        
        cout<<endl;
        
    
    }
	return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;


int main(){
    ll n;
    cin >> n ;
    vector<ll> A(n);
    vector<ll> B(n-1);
    for(int i = 0; i< n-1; i++){
        cin >> B.at(i);
    }
    
    A.at(0) = B.at(0);
    A.at(n-1) = B.at(n-2);

    for(int i = 1; i< n-1; i++){
        A.at(i)= min(B.at(i-1),B.at(i));
    }

    ll sum = 0;
    for(int i = 0; i< n; i++){
        sum += A.at(i);
    }   

    cout << sum << endl;
    
}


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

int main(){
    int N; cin >> N;
    vector<int> H(N);
    rep(i, N) cin >> H[i];

    vector<ll> dp(N);
    dp[0] = 0;
    dp[1] = abs(H[1] - H[0]);
    
    for(int i = 2; i < N; ++i){
        dp[i] = min(dp[i-2] + abs(H[i] - H[i-2]), dp[i-1] + abs(H[i] - H[i-1]));
    }

    cout << dp[N-1] << endl;
}


Measured memory_bytes: 4560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll N;
  cin >> N;
  multiset<ll> S;
  for (ll i = 0; i < 1LL << N; i++)
  {
    ll s;
    cin >> s;
    S.emplace(-s);
  }

  vector<ll> T = {*S.begin()};
  S.erase(S.begin());
  //cerr << T.front() << endl;
  for (ll i = 0; i < N; i++)
  {
    for (ll j = 0; j < (1LL << i); j++)
    {
      auto itr = S.lower_bound(T.at(j) + 1);
      if (itr == S.end())
        FINALANS("No");
      //cerr << T.at(j) << " " << *itr << " " << S.size() << endl;
      if (T.at(j) >= *itr)
        FINALANS("No");
      T.push_back(*itr);
      S.erase(itr);
    }
  }
  FINALANS("Yes");
}

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

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

  int min = 2000000;
  int max = -10;
  int index_A = 0;
  int index_Z = 0;
  for (int i=0; i<s.size(); i++) {
    
    if (s[i] == 'A') {      
      index_A = i;
      
      if (index_A < min) {
        min = index_A;
      }
    }    
    if (s[i] == 'Z') {
      index_Z = i;
      
      if (index_Z > max) {
        max = index_Z;
      }
    }
  }
  cout << max - min + 1 <<endl;
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = n; i > 0; i--)
#define rep3(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep4(i, s, e) for (int i = (e); i < (int)(s); i--)

int main() {
    char s;
    cin >> s;
    if (s == 'a' or s == 'i' or s == 'u' or s == 'e' or s == 'o') {
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
}


Measured memory_bytes: 256
N,*as = `dd`.split.map &:to_i

ans = 0
s = as.reduce(:^)

M = as.max.bit_length
used = {}
(0...M).reverse_each{ |k|
  mask = (1 << (k+1)) - 1
  as.map!{ |a| a &= mask }
  head = (1 << k)
  if (s & head) > 0 

    i = (0...N).find{ |i| !used[i]  && as[i] == head }
    if !i 
      p -1; exit
    end
    used[i] = 1
    as[i] -= 1
    s ^= as[i]
    ans += 1
  end
}

p ans


Measured memory_bytes: 9484
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int n;
            while((n = scn.nextInt()) > 0) {
                ArrayList<char[]> cnvList = new ArrayList<>();
                while(n-- > 0) {
                    char[] ary = new char[] {
                        scn.next().charAt(0),
                        scn.next().charAt(0)
                    };
                    cnvList.add(ary);
                }

                StringBuilder sb = new StringBuilder();
                for(int m = scn.nextInt(); m > 0; m--) {
                    sb.append(scn.next());
                }

                char[] src = sb.toString().toCharArray();
                char[] dest = src.clone();

                for(char[] cnv : cnvList) {
                    for(int i = 0; i < src.length; i++) {
                        if(src[i] == cnv[0]) {
                            dest[i] = cnv[1];
                        }
                    }
                }
                System.out.println(dest);
            }
        }
    }
}

Measured memory_bytes: 69844
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 922337203685477;
const ll mininf = -922337203685477;
const ll nax = 1e5 + 5;

int main(){
	IOS
	ll a, b;
	cin >> a >> b;
	ll fpb=__gcd(a, b);
	cout << a*b/fpb << '\n';
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=1e5+10;
int id[maxn],b[maxn],l[maxn],r[maxn];
ll v[maxn];
inline bool cmp(const int A,const int B){
	return v[A]>v[B];
}
int main(){
	int n=read(),lim=read();
	ll tot=0;
	REP(i,1,n){
		b[i]=read(),l[i]=read(),r[i]=read(),id[i]=i;
		v[i]=(ll)l[i]*b[i]+(ll)r[i]*(lim-b[i]);
		tot-=(ll)l[i]*b[i];
	}
	sort(id+1,id+n+1,cmp);
	ll sum=0,ans=1e18;
	ll val=0;
	REP(i,1,n){
		int u=id[i];
		val=v[u];
		if(tot+v[u]>=0) break;
		tot+=v[u];
		sum+=lim;
	}
	REP(i,1,n) if(tot+v[i]>=0){
		if(v[i]>val) tot+=val-v[i];
		if(tot+(ll)l[i]*b[i]>=0){
			chkmin(ans,b[i]-(tot+(ll)l[i]*b[i])/l[i]);
		}
		else{
			chkmin(ans,lim-(tot+v[i])/r[i]);
		}
		if(v[i]>val) tot-=val-v[i];
	}
	printf("%lld\n",ans+sum);
    return 0;
}

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

int main() {
    long long H;
    long long A;
    cin >> H >> A;
    long long value = 0;
    long long new_value = 0;
    for (long long i = 0; H > 0; ++i) {
        long long difference = (H - A);
        H = difference;
        new_value = ++value;
    } 
    cout << new_value << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int A, B;
 int Sum = 0;
  cin >> A >> B;
  for (int i = A; i <= B; i++){
	if (i / 10000 == i % 10 && i % 10000 / 1000 == i % 100 / 10){
      Sum++;
    }
  }cout << Sum << endl;
} 
 

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vector<int>>;


int cnt1(int a, int &max,int &cnt){
  if(max-1>a){
    a += ((max-a)/2)*2;
  }
  return a;
}

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  int maxi = max(max(a,b),max(b,c));

  int cnt = 0;
  cnt += (maxi-a)/2;
  cnt += (maxi-b)/2;
  cnt += (maxi-c)/2;
  a = cnt1(a,maxi,cnt);
  b = cnt1(b,maxi,cnt);
  c = cnt1(c,maxi,cnt);

  if((maxi*3-a-b-c)==2){
    cout << cnt+1 << endl;
    return 0;
  }

  if((maxi*3-a-b-c)==1){
    cout << cnt+2 << endl;
    return 0;
  }

  if((maxi*3-a-b-c)==0){
    cout << cnt << endl;
    return 0;
  }
}


Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	while(true) {
		auto nm = readInts();
		auto n = nm[0];
		auto m = nm[1];
		if((n|m) == 0) return;

		int[][] tsd;
		for(int i; i < m; ++i) {
			tsd ~= readInts();
		}
		tsd.sort();

		auto infected = new bool[](n+1);
		infected[1] = true;
		for(int i; i < m; ++i) {
			auto t = tsd[i][0];
			auto s = tsd[i][1];
			auto d = tsd[i][2];
			if(infected[s]) infected[d] = true;
		}
		writeln(infected.filter!("a").array.length);
	}
}

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    if(a >= 13)
        ans = b;
    else if (a > 5)
        ans = b / 2;
    
    cout << ans << endl;
    return (0);
}

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

int main() {
	int N;

	int sum = 0;

	cin >> N;

	/*���+1�����邱�ƂŐ؂�グ�ɂ��邱�Ƃ��ł���B
	�Ⴆ�΁AN=5�̏ꍇ�A+1�������Ɋ����2.5�ɂȂ�A������3�Ȃ̂ŕs�����ƂȂ�B
	N=2�̏ꍇ�A(2 + 1)/2�ƂȂ�A1.5�ƂȂ�A�����_�ȉ��͐؂�̂Ă���̂œ�����1�ƂȂ�A�����ƂȂ�B
	*/
	sum = (N + 1) / 2;

	cout << sum << endl;
	
}

Measured memory_bytes: 256
N,M,R=map(int, input().split())
r=list(map(lambda x:int(x)-1, input().split()))
dp=[[10**9]*N for _ in range(N)]
for _ in range(M):
    A,B,C=map(int, input().split())
    A-=1
    B-=1
    dp[A][B]=C
    dp[B][A]=C
for z in range(N):
    for x in range(N):
        for y in range(N):
            dp[x][y]=min(dp[x][y], dp[x][z]+dp[z][y])

import itertools
ans=10**9
for p in itertools.permutations(range(R)):
    t=0
    rp=[r[i] for i in p]
    for i in range(R-1):
        t+=dp[rp[i]][rp[i+1]]
    ans=min(ans,t)
print(ans)

Measured memory_bytes: 47192
#include <stdio.h>
#include <stdlib.h>

int main(void){
    int n,k,q;
    scanf("%d %d %d",&n,&k,&q);
    int a[q],p[n];
    for(int i=0; i<n; i++)
        p[i]=0;
    for(int i=0; i<q; i++){
        scanf("%d",&a[i]);
        p[a[i]-1]++;
    }
    for(int i=0; i<n; i++){
        if(p[i]+k-q>0)
            printf("Yes\n");
        else
            printf("No\n");
    }
}

Measured memory_bytes: 1280
#include <cstdio>
using namespace std;

int Num(int a){
	switch(a){
		case 73 : return 1;
		case 86 : return 5;
		case 88 : return 10;
		case 76 : return 50;
		case 67 : return 100;
		case 68 : return 500;
		case 77 : return 1000;
		default : return 0;
	}
}

int main(){
	char str[110];
	int ch1, ch2, sum;
	
	for(int i = 0; i < 110; i++) str[i] = 0;
	
	while((scanf("%s", str)) != EOF){
		sum = 0;
		
		for(int i = 0; str[i] != 0; i++){
			ch1 = Num(str[i]);
			ch2 = Num(str[i + 1]);
			if(ch1 >= ch2) sum += ch1;
			else sum -= ch1;
		}
		
		printf("%d\n", sum);
		
		for(int i = 0; i < 110; i++) str[i] = 0;
	}
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  string S;
  cin >>  S;
  int height = 0, left = 0;;
  for (int i = 0; i < N; ++i) {
    const int difference = S[i] == '(' ? 1 : -1;
    height += difference;
    if (height < 0) {
      ++left;
      height = 0;
    }
  }
  for (int i = 0; i < left; ++i) cout << "(";
  cout << S;
  for (int i = 0; i < height; ++i) cout << ")";
  cout << endl;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Control.Monad (replicateM, forM_)

main = do
  n <- read <$> getLine :: IO Int
  ts <- fmap read <$> words <$> getLine :: IO [Int]
  m <- read <$> getLine :: IO Int
  pxs <- replicateM m (fmap read <$> words <$> getLine :: IO [Int])
  let _sum = sum ts in
    forM_ [0..m-1] $ \i -> do
      putStrLn $ show $ _sum - (ts !! (pxs !! i !! 0 - 1)) + (pxs !! i !! 1)


Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;

#include <tuple>
#include <string>
#include <vector>   
//入力数の桁数を出力
//https://atcoder.jp/contests/abc057/tasks/abc057_c
int cnt_digits(ll n){

    int digits =0;
    while(n > 0){

        digits++;
        n /= 10;

    }
    return digits;
}

int main() {

    //3200以上は色が自由
    int rate[]={1,400,800,1200,1600,2000,2400,2800,3200};
    int n;
    int a[100] = {0};
    cin >> n ;

    int min = 0;
    int max = 0;

    int color[9] = {0};
    for(int i=0;i < n;i++){
        cin >> a[i];
        for(int j =0;j < 8;j++){
            if(rate[j] <= a[i] && a[i] <rate[j+1]){
                color[j]++;
                
            }
        }
        if(a[i] >= 3200){
            color[8]++;
        }

    }

    //min,max計算
    int sum = 0;
    int numOfKinds =0;
    for(int i = 0;i < 8;i++){
        sum += color[i];
        if(color[i] != 0){
            numOfKinds++;
        }

    }

    if(numOfKinds != 0){
        min = numOfKinds;
    }else if(numOfKinds ==0){
        min = 1;
    }
    max = numOfKinds + color[8];

    cout << min << " "<< max << endl;
    



    
    return 0;
}


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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9

int main(){ 
  int A, B;
  cin >> A >> B;
  cout << max(A-2*B, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int H,W,i,j;

	while(1){
		scanf("%d %d",&H,&W);
		if(H==0 && W==0) break;
		for(j=0;j<H;j++){
			if(j==0 || j==H-1){
				for(i=0;i<W;i++){
					printf("#");
				}
				printf("\n");
			}else{
				for(i=0;i<W;i++){
					if(i==0 || i==W-1){
						printf("#");
					}else{
						printf(".");
					}
				}
				printf("\n");
			}
		}
		printf("\n");
	}


	return 0;

}

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

A = 1
B = 1
C = 1

for i in range(N):
    A *= 10
    A = A % int(1e+9 + 7)

for i in range(N):
    B *= 9
    B = B % int(1e+9 + 7)

for i in range(N):
    C *= 8
    C = C % int(1e+9 + 7)

D = A - 2 * B + C
D = D % int(1e+9 + 7)

print(D)

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

int main(){
	int N;
	cin>>N;
	vector<int>A,B;
	int tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		A.push_back(tmp);
		B.push_back(tmp);
	}
	sort(A.begin(),A.end(),greater<int>());
	int a=A[0],b=A[1];
	for(int i=0;i<N;++i){
		if(B[i]==a)cout<<b<<endl;
		else cout<<a<<endl;
	}
}


Measured memory_bytes: 3436
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define lowbit(x) (x&(-x))
#define PII pair<LL,LL>
#define FOR(i,a,b) for (LL i=(a);i<=(b);++i)
#define ROF(i,b,a) for (LL i=(b);i>=(a);--i)
typedef long long LL;
inline LL read(){
	LL x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const LL MAXN=500005,lx=50000;
LL n,m,x,y,z,a,b;
LL exgcd(LL x,LL y,LL &a,LL &b){
	if (y==0) { a=1; b=0; return x; }
	LL tmp=exgcd(y,x%y,b,a); b-=a*(x/y); return tmp;
}
int main(){
	n=read();
	while (n--) {
		x=read(); y=read(); z=exgcd(x,y,a,b);
		//cout<<a<<' '<<b<<endl;
		if (a<0) a=-a; else if (b<0) b=-b;
		if (z<=lx) printf("3\n0 0\n%lld %lld\n%lld %lld\n",x,y,b,a);
		else printf("4\n0 0\n%lld %lld\n%lld %lld\n%lld %lld\n",x,y-1,x/z,y/z,x-1,y);
	}
	return 0;
}

/*
1
50001 50001

*/

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

typedef std::pair<int, int> P;

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    int N;
    cin >> N;
    int A[N];
    int B[N];
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(A, A + N);
    int count = 1;
    rep(i, N - 1) {
        if (A[i] != A[i + 1]) {
            count++;
        }
    }
    vector<P> pairs;
    int c = 1;
    rep(i, N - 1) {
        if (A[i] == A[i + 1]) {
            c++;
            if (i == N - 2) {
                pairs.push_back(P(A[i], c));
            }
        } else {
            pairs.push_back(P(A[i], c));
            c = 1;
            if (i == N - 2) {
                pairs.push_back(P(A[i + 1], c));
            }
        }
    }
    int all = 0;
    rep(i, count) {
        all += pairs[i].second * (pairs[i].second - 1) / 2;
    }
    rep(i, N) {
        int left = 0, right = count;
        int mid;
        while (left < right) {
            mid = (left + right) / 2;
            if (B[i] == pairs[mid].first) {
                int calc = pairs[mid].second;
                if (calc < 2) {
                    cout << all << endl;
                    break;
                }
                cout << all - calc * (calc - 1) / 2 + (calc - 1) * (calc - 2) / 2 << endl;
                break;
            }
            if (B[i] > pairs[mid].first) {
                left = mid + 1;
            }
            if (B[i] < pairs[mid].first) {
                right = mid;
            }
        }
    }

}


Measured memory_bytes: 6896
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    boolean flag = true;
    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
    }
    for(int j = 0;j < n;j++){
      if(a[j] % 2 == 0){
        if(a[j] % 3 != 0 && a[j] % 5 != 0){
          flag = false;
          break;
        }
      }
    }
    if(flag){
      System.out.println("APPROVED");
    }else{
      System.out.println("DENIED");
    }
  }
}


Measured memory_bytes: 21844