akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll s,t;
 ll n;
 cin>>s>>t;
 cout<<max(t+100*(10-s),t)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
int main(void){
    // Your code here!
    int n,k=0;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
        k+=a.at(i);
    }
    cout<<k-n<<endl;
}


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

string s;

int main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')
		cout<<"Yes";
	else
		cout<<"No";
	return 0; 
} 

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

int main() {

  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  string str;
  cin >> str;
  int res = 0;
  int act = 0;
  for (int i = 0; i < str.size(); ++i) {
    if (str[i] == 'A' || str[i] == 'C' || str[i] == 'G' || str[i] == 'T') {
      act++;
    }
    else {
      act = 0;
    }
    res = max(res, act);
  }
  cout << res << "\n";

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   int ans = 1e18;
   for(int i=1;i*i<=n;i++){
      if(n%i==0){
         ans = min(ans,i-1+n/i-1);
      }
   }
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
// typedef __int128_t Int;
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF =
    sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
using pii = pair<int, int>;
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;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vector<int> a(N);
  rep(i, 0, N) {
    cin >> a[i];
    a[i]--;
  }
  cout << accumulate(all(a),0) << endl;

  return 0;
}


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

#文字列の数、文字数の入力
num,len = map(int, input().split())
#文字列の入力
str = list(input() for i in range(num))
last_str = ""

str.sort() #ソート
#文字列の合体
for s in str:
  last_str = last_str + s
print(last_str)

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

#define ll long long
#define f(i,s,e) for(int i=s;i<e;i++)
#define rf(i,s,e) for(int i=e;i>=s;i--)
#define fr first
#define sc second
#define pb push_back
#define  vii vector<int>
#define vll vector<ll>
#define vpii vector<pair<int ,int >>
#define vpll vector<pair<ll, ll> >
#define  pii pair<int,int>
const long mod =998244353;
const int N = 2e3+5;
const long long inf= 1e18;

ll gcd(ll a ,ll b){if(b==0) return a;return gcd(b,a%b);}
ll mul(ll a ,ll b){return (a%mod * b%mod )%mod;}
ll mpower(ll a, ll b){if(b==0) return 1;ll temp=mpower(a,b/2);if(b%2==0){return mul(temp,temp);}else{	return mul(mul(temp,temp) , a);}}
ll inv(ll a){return mpower(a,mod-2);}
ll ncr(ll n, ll r){if(r==0)return 1;ll ans=n%mod;ans=mul(ans,ncr(n-1,r-1));ans=mul(ans,inv(r));	return ans;}
ll power(ll a, ll b){if(b==0) return 1;ll temp=power(a,b/2);if(b%2==0)return temp*temp;else return temp*temp*a;}

string str;
ll nb,ns,nc,p_b,ps,pc,r;
ll b=0,c=0,s=0;

bool isp(ll ans)
{
     ll b_t=b*ans, c_t=c*ans,s_t=s*ans;
     ll k=0;
     if(b_t>nb)k+=(b_t-nb)*p_b;
     if(c_t>nc)k+=(c_t-nc)*pc;
     if(s_t>ns)k+=(s_t-ns)*ps;
    return k<=r;
    
}
void solve()
{
    ll s,w;cin>>s>>w;
    if(w>=s)cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    
} 

int main()
{
	ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--)
    {
        solve();
    }
}

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

#define ll long long
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); (i)++)
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;
#define vec vector
#define vvi vector<vector<int>>

void print(vec<ll> &dist) {
   for (int x : dist) {
      cout << x << " ";
   }
   cout << endl;
} 

struct Edge {
   int to, cost;
};
const ll INF = 4e18;
int N, M;
vec<vec<Edge>> G;

void dfs(int pos, vec<ll> &dist) {
   for (Edge e : G[pos]) { // 地点posの遷移先を全探索
      if (dist[e.to] == INF) { // 遷移先の値が定まっていないなら
         dist[e.to] = dist[pos] + e.cost; // 遷移先の値を定める
         // debug(dist[e.to])
         dfs(e.to, dist);
      }
   }
}

int main() {
   cin >> N >> M;
   G = vec<vec<Edge>>(N);
   rep (i, 0, M) {
      int l, r, d;
      cin >> l >> r >> d;
      l--, r--;
      G[l].push_back(Edge{r, d});
      G[r].push_back(Edge{l, -d});
   }

   // rep (i, 0, N) {
   //    for (Edge e : G[i]) {
   //       printf("(%3d, %3d, %3d)\n", i, e.to, e.cost);
   //    }
   // }

   vector<ll> dist(N, INF);
   rep (i, 0, N) {
      if (dist[i] == INF) { // 現在地の値が定まっていないなら
         // debug(i)
         dist[i] = 0;
         dfs(i, dist);
      }
   }

   // line()
   // print(dist);
   // line()

   rep (i, 0, N) {
      for (Edge e : G[i]) {
         // 遷移先の値 - 現在地 != 遷移コスト
         if (dist[e.to] - dist[i] != e.cost) {
            puts("No");
            return 0;
         }
      }
   }
   puts("Yes");

   return 0;
}

Measured memory_bytes: 12416
#include<iostream>
#include<queue>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

int m[4][4];
int ans=6;
bool haveans=false;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

bool isok(){
  rep(i,4)rep(j,4)if (m[i][j] != 0)return false;
  return true;
}

bool isout(int y,int x){
  return x==-1||y==-1||x==4||y==4;
}

typedef pair<int,int> pii;
void hit(int y,int x){
  /*
cout <<"initial state "<< endl;
  cout << y <<" " << x << endl;
  rep(i,4){
    rep(j,4){
      cout << m[i][j];
    }
    cout << endl;
  }
  */
  queue<pii> Q[2];
  m[y][x]=0;
  rep(k,4){
    Q[0].push(make_pair(y*4+x,k));
  }
  int now = 0;
  while(!Q[now].empty()){
    int next=(now+1)%2;
    while(!Q[now].empty()){
      int nx=Q[now].front().first%4,ny=Q[now].front().first/4;
      int dir=Q[now].front().second;
      Q[now].pop();
      while(!isout(ny,nx)){
	if (m[ny][nx] != 0){
	  m[ny][nx]++;
	  break;
	}
	nx+=dx[dir],ny+=dy[dir];
      }
    }
    rep(i,4)rep(j,4){
      if (m[i][j] >= 5){
	m[i][j]=0;
	rep(k,4)Q[next].push(make_pair(i*4+j,k));
      }
    }
    now = next;
  }
  /*
  cout << "final state " << endl;
  rep(i,4){
    rep(j,4){
      cout << m[i][j]; 
    }
    cout << endl;
  }
  cout << endl;
  */
}

void test(){
  while(true){
    if (cin.eof())return;
    rep(i,4)rep(j,4)cin>>m[i][j];
    int y,x;
    cin>>y>>x;
    hit(y,x);
  }
}

void search(int cnt){
  //cout <<"search " << cnt <<" " <<  ans << endl;
  /*
  rep(i,4){
    rep(j,4)cout << m[i][j];
    cout << endl;
  }
  */

  if (cnt >= ans)return;
  int tmp[4][4];
  if (isok()){
    ans=cnt;
    haveans=true;
    return;
  }
  if (cnt+1 >= ans)return;
  

  rep(i,4)rep(j,4)tmp[i][j]=m[i][j];
  rep(i,4){
    rep(j,4){
      m[i][j]++;
      if (m[i][j] == 5)hit(i,j);
      search(cnt+1);
      rep(ii,4)rep(jj,4)m[ii][jj]=tmp[ii][jj];
    }
  }
}



main(){
  //test();

  rep(i,4)rep(j,4)cin>>m[i][j];
  search(0);
  if (haveans)cout << ans << endl;
  else cout << -1 << endl;

}

Measured memory_bytes: 872
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 2e5 + 10;
#define singleCase
// #define multipleCase
ll n,a[N],ps[N];
map <ll , ll> freq;

void work() {
   in(n);
   for (ll i = 1 ; i <= n ; i++) {
      in(a[i]);
      ps[i] = ps[i - 1] + a[i];
   }
   for (ll i = 0 ; i <= n ; i++) {
      freq[ps[i]]++;
   }
   ll sol = 0;
   for (ii x : freq) {
      sol += (x.se * (x.se - 1)) / 2;
   }
   printf("%lld\n" , sol);
   return;
}

int main() {
   #ifdef multipleCase
      ll nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(ll &x) {
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 19216
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(){
	int i,N,r=0,b=0;
	scanf("%d",&N);
	char ss[1000];
	scanf("%s",ss);

	for(i=0;i<N;i++){
		if(ss[i]=='R'){
			r++;
		}
		if(ss[i]=='B'){
			b++;
		}
	}
	if(r>b){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
import Data.List
import Data.Char
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as BS8

main :: IO ()
main = do
    [n,a,b] <- unfoldr (BS8.readInteger . BS8.dropWhile isSpace) <$> BS8.getLine

    let
        diff = b - a
        nb = n - b
        na = a - 1
        nmin = (na + 1) + ((b - (na + 1) - 1) `div` 2)
        nmax = (nb + 1) + ((n - (a + (nb + 1))) `div` 2)

    print $ if diff `mod` 2 == 0
        then div diff 2
        else min nmin nmax


Measured memory_bytes: 380
import collections

n = int(input())
a = []
for i in range(n):
    a.append(input())

c = collections.Counter(a)
d = c.most_common()
e = d[0][1]
f = []
for i, j in d:
    if e == j:
        f.append(i)
f.sort()

for i in f:
    print(i)

Measured memory_bytes: 47668
N, M = map(int, input().split())
cities = []
for i in range(0, M):
	P, Y = map(int, input().split())
	cities.append([i, P, Y])
cities.sort(key = lambda v: v[2])
cities.sort(key = lambda v: v[1])
idkeylist = [[cities[0][0], cities[0][1], 1]]
cnt = 2
for i in range(1, M):
	if cities[i][1] != idkeylist[-1][1]:
		idkeylist.append([cities[i][0], cities[i][1], 1])
		cnt = 2
	else:
		idkeylist.append([cities[i][0], cities[i][1], cnt])
		cnt += 1
idkeylist.sort(key = lambda v: v[0])
for i in range(0, M):
	ansP = str(idkeylist[i][1])
	while len(ansP) < 6:
		ansP = '0' + ansP
	ansT = str(idkeylist[i][2])
	while len(ansT) < 6:
		ansT = '0' + ansT
	print(ansP+ansT)

Measured memory_bytes: 88792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()

using namespace std;

using ll = long long;

vector<long long> divisors(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; i++) { if (n % i == 0) {
      res.push_back(i);
      if (i * i != n) {
        res.push_back(n / i);
      }
    }
  }
  return res;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll d : divisors(N)) {
    ll m = d - 1;
    ll x = N / d;
    // x = N/m
    // x = N%m
    if (m != 0 && N/m == x && N%m == x) {
      ans += m;
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cstdlib>
using namespace std;

int n, a, f;

inline int getint() {
	char ch = getchar(); int res = 0, ops = 1;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') ops = 0;
	for(; isdigit(ch); ch = getchar()) res = res * 10 + ch - '0';
	return ops ? res : -res;
}


int main() {
	n = getint();
	for(int i = 1; i <= n; i++) {
		a = getint();
		if(a & 1) f = 1;
	}
	if(f) puts("first");
	else puts("second");
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const long long INF = 2e18;
const long long MOD = 1e9+7;

#define sx(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(a) begin(a),end(a)

int main(void) {
    
    int n;
    while (cin >> n ,n) {
        vector<int> a(n);
        REP(i,n) cin >> a[i];
        int sum = 0;
        REP(i,n) sum += a[i];
        double ave = (double) sum/n;
        int count = 0;
        REP(i,n) {
            if (a[i] <= ave ) count++;
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
#include <iostream>
#include <math.h>
using namespace std;

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

    if (b < 10) {
        c = a * 10 + b;
    } else if (b < 100){
        c = a * 100 + b;
    } else {
        c = a * 1000 + b;
    }

    int d = sqrt(c);
    if (d * d == c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b


def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def warikirenai(n, c, d):
    num =  n - n // c
    num += n - n // d
    num -= n - n // lcm(c, d)
    return num

def main():
    A, B, C, D = map(int, input().split())

    print(warikirenai(B, C, D) - warikirenai(A - 1, C, D))


if __name__ == '__main__':
    main()


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

using namespace std;
int memo[10000][10000];
int road[10000][10000];
int ho=0,le=0;
int c=0,d=0,e=0,f=0;
int miti(int a,int b){
    if(memo[a][b]==-1)return 0;
    if(a==1&&b==1)return 1;
    if(a==1)memo[a][b]=miti(a,b-1);
    else if(b==1)memo[a][b]=miti(a-1,b);
    else if(memo[a][b]==0)
        memo[a][b]=miti(a-1,b)+miti(a,b-1);
        return memo[a][b];
}
int main(){
    while(1){
    cin >> c >> d;
    if(c==0&&d==0)break;
    cin >> e;
    fill(memo[0],memo[c+d]+d+c,0);
    for(int i=0;i<e;i++){
        cin >> ho >> le;
        memo[ho][le]=-1;
    }
    f=miti(c,d);

    cout << f << endl;
    }
return 0;
}

Measured memory_bytes: 5256
import sys

def func(d, S, D):
    if S[d] == []:
        return 2, [d]
    else:
        tmp = 1
        used=[d]
        for k in S[d]:
            ret = func(k,S,D)
            tmp *= ret[0]
            used += ret[1]
        return tmp+1 , used

sys.setrecursionlimit(100000)
N,M=map(int,raw_input().split())
S=[[] for i in range(N)]
D=[-1 for i in range(N)]
for i in range(M):
    s,d=map(lambda x: int(x)-1 ,raw_input().split())
    D[s] = d
    S[d].append(s)

unevaled=range(N)
bans=[]
while(len(unevaled)>0):
    #find root
    tmp=unevaled[0]
    T=[tmp]
    while (1):
        if D[tmp]==-1:
            root=tmp
            break
        elif D[tmp] in T:
            root=D[tmp]
            D[root]=-1
            rebase=T[ T.index(root) : ]
            Stmp=[]
            for r in rebase:
                for rs in S[r]:
                    if rs not in rebase:
                        D[rs]=root
                        Stmp.append(rs)
                if r!=root:
                    unevaled.remove(r)
            S[root]=Stmp[:]
            break
        else:
            tmp=D[tmp]
            T.append(tmp)
    b = func(root, S, D)
    bans.append(b[0])
    for r in b[1]:
        unevaled.remove(r)
ans = reduce(lambda x,y: x*y, bans)
print ans%1000000007



Measured memory_bytes: 4904
n,m = map(int,input().split())
li = []
for _ in range(m):
    tmp = list(map(int,input().split()))
    li.append(tmp)
#print(li)
ma = [[] for i in range(n)]
#print(ma)[[], [], [], []]
for l in li:
    a = l[0]-1
    b = l[1]-1
    ma[a].append(b)
    ma[b].append(a)
#print(ma)
# [[1], [0, 2, 3], [1, 3], [2, 1]]
ans = [-1]*(n) # 最後に先頭削除
q = [0]
while q:
    #print(q)
    que = q.pop(0)
    for e in ma[que]:
        if ans[e]== -1:
            ans[e] = que
            q.append(e)
ans.pop(0)
if -1 in ans:
    print('No')
else:
    print('Yes')
    for aaa in ans:
        print(aaa+1) 

Measured memory_bytes: 69996
# AOJ GRL_1_A
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A

from heapq import heappush, heappop

INF = 10000000000

def solve(r, v, dic):
    dp = []
    q = []
    dp = [INF] * v
    dp[r] = 0
    heappush(q, (0, r))
    while q:
        cost, vtx = heappop(q)
        if dp[vtx] < cost:
            continue
        if vtx not in dic:
            continue
        for vtx1, cost1 in dic[vtx]:
            if cost + cost1 < dp[vtx1]:
                dp[vtx1] = cost + cost1
                heappush(q, (cost + cost1, vtx1))
    return dp

dic = {}
dp = []
line = input()
v, e, r = list(map(int, line.split()))
for _ in range(0, e):
    line = input()
    s, t, d = list(map(int, line.split()))
    if s not in dic:
        dic[s] = [[t, d]]
    else:
        dic[s] += [[t, d]]
dp = solve(r, v, dic)
for t in range(0, v):
    print(dp[t] if dp[t] != INF else "INF")


Measured memory_bytes: 105292
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define vvs vector<vs>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

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

  int i = s.size();
  while (i > 0) {
    if (s == t) {
      cout << "Yes" << endl;
      return 0;
    }
    s = s.substr(s.size() - 1, 1) + s.substr(0, s.size() - 1);
    i--;
  }
  cout << "No" << endl;

  return 0;
}

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

signed main(){
    int t = 1; //cin >> t;
    while(t--){
    	int n; cin >> n;
    	vector<int> a(n);
    	int ans = 0, f = 0;
    	for (int i = 0; i < n; ++i)
    	{
    		cin >> a[i];
    		f += a[i] - 1;
    	}
    	cout << max(ans,f);
    }    
}

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

int main(void) {
	int a, b, c;
	int tmp;
	cin >> a >> b >> c;
	if (a > b) {
		tmp = b;
		b = a;
		a = tmp;
	}
	if (b > c) {
		tmp = c;
		c = b;
		b = tmp;
	}
	if (a > b) {
		tmp = b;
		b = a;
		a = tmp;
	}
	cout << a << " " << b << " " << c << endl;
	return 0;
}




Measured memory_bytes: 3100
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <utility>
#include <string>
#include <vector>

using namespace std;

long MOD = 1e9 + 7;
string s;

long dp(int pos, char next) {
    if (pos == s.size()) return next == 'D' ? 1 : 0;
    if (s[pos] == '?') {
        long consume = next != 'D' ? dp(pos + 1, next + 1) : 0;
        return (3 * dp(pos + 1, next) + consume) % MOD;
    } else {
        long consume = s[pos] == next ? dp(pos + 1, next + 1) : 0;
        return (dp(pos + 1, next) + consume) % MOD;
    }
}

int main() {
    cin >> s;

    vector<vector<long>> dp(s.size(), vector<long>(4));
    dp.push_back({0, 0, 0, 1});
    for (int i = s.size()-1; i >= 0; i--) {
        if (s[i] == '?') {
            for (char c = 'A'; c < 'D'; c++) {
                dp[i][c - 'A'] = (3 * dp[i + 1][c - 'A'] + dp[i + 1][c - 'A' + 1]);
            }
            dp[i]['D' - 'A'] = 3 * dp[i + 1]['D' - 'A'];
        } else {
            for (char c = 'A'; c < 'D'; c++) {
                if (s[i] == c) {
                    dp[i][c - 'A'] = dp[i + 1][c - 'A'] + dp[i + 1][c - 'A' + 1];
                } else {
                    dp[i][c - 'A'] = dp[i + 1][c - 'A'];
                }
            }
            dp[i]['D' - 'A'] = dp[i + 1]['D' - 'A'];
        }
        for (char c = 'A'; c <= 'D'; c++) {
            dp[i][c - 'A'] %= MOD;
        }
    }
    cout << dp[0][0] << endl;
}


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

int main() {
    clock_t cTimeStart, cTimeEnd;
    cTimeStart = clock();           // 現在時刻
    int H[10];
    for(int i=0;i<10;++i){
    	cin>>H[i];
    }
    sort(H,H+10);
    for(int i=0;i<3;++i){
    	    cout<<H[9-i]<<endl;
    }

    cTimeEnd = clock();           // 現在時刻
//    cout<< "処理時間:" <<(cTimeEnd - cTimeStart)/1000 << "[ms]" << endl;

	return 0;
}

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

int A[205];

int N, Ans;

int main() {
	cin >> N; N <<= 1;
	for(int i = 0; i < N; i++) cin >> A[i];
	sort(A, A+N);
	for(int i = 0; i < N; i += 2) Ans += A[i];
	cout << Ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T> void map_init(map<S, T> &m, S k, T v){if(!m.count(k)) m[k] = v;}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    string S;
    cin >> S;
    bool ans = true;
    set<char> s0 = {'R', 'U', 'D'};
    set<char> s1 = {'L', 'U', 'D'};
    for(int i = 0; i < S.size(); i++) {
        if(i % 2 == 0) {
            if(!s0.count(S[i])) ans = false;
        } else {
            if(!s1.count(S[i])) ans = false;
        }
    }
    R_YesNo(ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] array = new int[n + 1];
        int limit = (int)Math.sqrt(n);
        for (int x = 1; x <= limit; x++) {
            for (int y = 1; y <= limit; y++) {
                for (int z = 1; z <= limit; z++) {
                    if (x*x + y*y + z*z + x*y + y*z + x*z <= n)
                        array[x*x + y*y + z*z + x*y + y*z + x*z]++;
                    else
                        break;
                }    
            }
        }
        for (int i = 1; i <= n ; i++)
            System.out.println(array[i]);
    }
}

Measured memory_bytes: 38820
#include <bits/stdc++.h>
using namespace std;
int arr1[100005];
int arr2[100005];
vector <pair<int,int> > v1,v2;
bool cmp(pair<int,int> a,pair<int,int> b){
	return a.first>b.first;
}
int main(){
	int n; cin >> n;
	for(int i=1;i<=n;i++){
		int tmp; cin >> tmp;
		if(i%2==1) arr1[tmp]++;
		else arr2[tmp]++;
	}
	int idx=1; int idy=1;
	for(int i=1;i<=100000;i++){
		if(arr1[i]!=0) v1.push_back({arr1[i],i});
		if(arr2[i]!=0) v2.push_back({arr2[i],i});
	}
	sort(v1.begin(),v1.end(),cmp);
	sort(v2.begin(),v2.end(),cmp);
	//cout << v1.size()<<' '<<v2.size()<<endl;
	if(v1[0].second != v2[0].second) cout << n-v1[0].first-v2[0].first<<endl;
	else {	
	    if(v1.size()==1 && v2.size()==1){
			cout << n/2 << endl;
		}	
		else if(v1.size()>1 && v2.size()>1){
			cout << min(n-v1[0].first-v2[1].first,n-v1[1].first-v2[0].first) << endl;
		}
		else if(v1.size()==1)
			cout << n-v1[0].first-v2[1].first<<endl;
		else
			cout << n-v2[0].first-v1[1].first<<endl;
	}
	
}

Measured memory_bytes: 2044
import sys
n = int(input())
a = list(map(int, input().split()))
c = a[0] + a[1]

t = 0

for ai in a[2:]:
    t = t ^ ai

bit_len = c.bit_length()+1

if c < t:
    print(-1)
    sys.exit()

if (c-t) % 2:
    print(-1)
    sys.exit()

b1 = (c - t) // 2


a1 = b1
a2 = b1


if a1 > a[0]:
    print(-1)
    sys.exit()
    

for i in reversed(range(bit_len)):
    if t & (1 << i):
        if b1 & (1 << i):
            print(-1)
            sys.exit()
        if a1 + 2 ** i <= a[0]:
            a1 += 2 ** i

if a1 == 0:
    print(-1)
else:
    print(a[0]-a1)
    



Measured memory_bytes: 62184
import sys

def print_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print()

n = int(input())
arr = list(map(int, input().split()))

swap_count = 0
for i in range(n):
	mini = i
	for j in range(i, n):
		if arr[j] < arr[mini]:
			mini = j
	temp = arr[i]
	arr[i] = arr[mini]
	arr[mini] = temp
	if i != mini:
		swap_count += 1

print_arr(arr)
print(swap_count)



Measured memory_bytes: 5616
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <map>

using namespace std;

struct UnionFind {
    vector<long long> par; // 親ノード
    vector<long long> rank; // ランク

    UnionFind(long long n = 1) {
        init(n);
    }

    void init(long long n = 1) {
        par.resize(n); rank.resize(n);
        for (long long i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }

    long long root(long long x) {
        if (par[x] == x) {
            return x;
        }
        else {
            long long r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(long long x, long long y) {
        return root(x) == root(y);
    }

    bool merge(long long x, long long y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

int main(){
    long long N;
    cin >> N;
    UnionFind UF(N);

    long long M; cin >> M;
    long long K; cin >> K;

    map<long long, long long> m;
    vector<long long> path_num(N);

    for(long long i=0; i<M; ++i){
        long long a, b; cin >> a >> b;
        a--; b--;
        path_num[a]++;
        path_num[b]++;
        if(a > b) swap(a,b);
        UF.merge(a, b);    
    }

    for(long long i=0; i<N; ++i){
        UF.root(i);
    }


    for(long long i=0; i<N; ++i){
        if(m.count(UF.par[i]) > 0){
            m[UF.par[i]]++;
        }else{
            m[UF.par[i]] = 1;
        }
    }

    vector<long long> node_edges(N);
    for(long long i=0; i<N; ++i){
        node_edges[i] = m[UF.par[i]] -1;
    }

    //delete block
    for(long long i=0; i<K; ++i){
        long long c, d; cin >> c >> d;
        c--; d--;
        if(UF.issame(c, d)){
            path_num[c]++;
            path_num[d]++;
        }
    }

    for(long long i=0; i<N; ++i){
        cout << node_edges[i] - path_num[i] << endl;
    }

}

Measured memory_bytes: 12284
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s;
  int n=s.size();
  t.push_back(s[0]);
  string u="";
  int cnt=1;
  for(int i=1;i<n;i++){
    u.push_back(s[i]);
    if(t!=u){
      cnt++;
      t=u;
      u="";
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
import java.util.Scanner;

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

	public static void main(String[] args) {
		boolean n=false,w=false,s=false,e=false;

		for(char c:Main.s.next().toCharArray()) {
			switch (c) {
			case 'N':
				n=true;
				break;
			case 'W':
				w=true;
				break;
			case 'S':
				s=true;
				break;
			case 'E':
				e=true;
				break;
			}
		}

		System.out.println(n^s||w^e?"No":"Yes");
	}
}


Measured memory_bytes: 23636
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<utility>
using namespace std;

class P{
public:
  string word;
  int edge;
  P(string a, int b){
    word = a;
    edge = b;
  }
  bool operator < (const P &a) const { return word > a.word; }
};

int main(){
  int n,a,s,g;
  int from[400],to[400];
  string spell[400];
  string ans[250][40];
  bool use[250][40];
  int prvx[250][40],prvy[250][40];

  while(1){
    cin >> n >> a >> s >> g;
    if(!n && !a && !s && !g)break;

    for(int i=0;i<a;i++)cin >> from[i] >> to[i] >> spell[i];
    for(int i=0;i<250;i++){
      for(int j=0;j<n;j++){
	ans[i][j] = "NO";
	prvx[i][j] = -1;
	prvy[i][j] = -1;
	use[i][j] = false;
      }
    }
    ans[0][s] = "";
    use[0][s] = true;

    priority_queue< P > str;
    for(int i=0;i<a;i++){
      if(from[i] == s)str.push(P(spell[i],i));
    }
    bool f = false;
    while(str.size()){
      P hoge = str.top();
      string tmp = hoge.word;
      int num = hoge.edge;

      if(!use[tmp.size()][to[num]]){
	ans[tmp.size()][to[num]] = tmp;
	prvx[tmp.size()][to[num]] = tmp.size() - spell[num].size();
	prvy[tmp.size()][to[num]] = from[num];
	use[tmp.size()][to[num]] = true;
	if(to[num] == g)break;
	for(int i=0;i<a;i++){
	  int sum = tmp.size() + spell[i].size();
	  if(from[i] == to[num] && sum < 250 && !use[sum][to[i]])str.push(P(tmp+spell[i],i));
	}
      }
      str.pop();
    }
    
    if(f)cout << "NO" << endl;
    else{
    string res = "NO";
    int posx = -1, posy = -1;
    for(int i=0;i<250;i++){
      if(res == "NO"){
	res = ans[i][g];
	posx = i;
	posy = g;
      }else if(ans[i][g] != "NO" && res > ans[i][g]){
	res = ans[i][g];
	posx = i;
	posy = g;
      }
    }

    if(posx>=0){
      vector<int> visit;
      int x = posx, y = posy;
      bool loop = false;
      visit.push_back(y);
      while(x>=0 && y>=0){
	int t = prvx[x][y];
	y = prvy[x][y];
	x = t;

	for(int i=0;i<(int)visit.size();i++){;
	  if(visit[i] == y)loop = true;
	}
	if(loop)break;
	visit.push_back(y);
      }
      if(loop)res = "NO";
    }
    cout << res << endl;
    }
  }
}

Measured memory_bytes: 10000
#include<stdio.h>
int main(){
	int x,y;
	x=1;
	y=1;
	while(x!=0||y!=0){
	scanf("%d %d", &x, &y);
	if(x!=0||y!=0){
		if(x<y){
			printf("%d %d\n",x,y);
		}else{
			printf("%d %d\n",y,x);;  
		}
	}else{
	}
}	
return 0;
}


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

int main(){
  int a,b,c,d;
  cin>>a;
  cin>>b;
  cin>>c;
  cin>>d;
  int cnt;
  if(a<b)cnt=cnt+a;
  else cnt=cnt+b;
  if(c<d)cnt=cnt+c;
  else cnt=cnt+d;
  cout << cnt;
}

Measured memory_bytes: 256
S = input()
T = S[:-1]

if S[0] == "0" or S[-1] == '1' or T != T[::-1]:
    print(-1)
    quit()

u = 1
for v in range(2, len(S) + 1):
   print(u, v)
   if S[v - 2] == '1':
       u = v

Measured memory_bytes: 4652
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
//#include <cmath>
//#include <iomanip>
//#include <map>
//#include <unordered_map>
//#include <cstring>
#include <queue>

using namespace std;
using ll = long long;
// using pint = pair<int, int>;
// ll INF = 1LL << 60;

int dp[100000];

int main() {
	int N, W;
	cin >> N >> W;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int v, w;
		cin >> v >> w;
		for (int j = 0; j < W; j++) {
			dp[j + w] = max(dp[j + w], dp[j] + v);
		}
	}
	for (int i = 0; i <= W; i++) ans = max(ans, dp[i]);
	cout << ans << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll MAX_N = 2e+5;


int main(int argc, char const *argv[]) {
  ll n, a[MAX_N];
  cin >> n;
  for (ll i = 0; i < n; i++) cin >> a[i];

  ll r = 0, sum = 0, ans = 0;

  for (ll l = 0; l < n; l++) {
    while (r<n && ((sum^a[r])==sum+a[r])) {
      sum += a[r];
      r++;
    }

    ans += r-l;

    if (r==l) r++;
    else sum -= a[l];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
<?php
fscanf(STDIN,"%d",$n);
$p_li = explode(" ",trim(fgets(STDIN)));
$c = 0;
for($i=1;$i<$n-1;$i++){
  $min = min($p_li[$i-1],$p_li[$i],$p_li[$i+1]);
  $max = max($p_li[$i-1],$p_li[$i],$p_li[$i+1]);
  if($p_li[$i]!=$min && $p_li[$i]!=$max){
    $c++;
  }
}
           

echo $c;

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

int main(){
	int N, M, i;
	scanf("%d%d", &N, &M);
	vector<int> x(N, -1);
	for(i = 0; i < M; i++){
		int s, c;
		scanf("%d%d", &s, &c);
		s--;
		if(x[s] != -1 && x[s] != c){
			printf("-1\n");
			return 0;
		}
		else{
			x[s] = c;
		}
	}
	if(N == 1){
		x[0] = max(0, x[0]);
	}
	else{
		if(x[0] == 0){
			printf("-1\n");
			return 0;
		}
		else if(x[0] == -1){
			x[0] = 1;
		}
		for(i = 1; i < N; i++){
			x[i] = max(0, x[i]);
		}
	}
	int ans = 0;
	for(i = 0; i < N; i++){
		ans *= 10;
		ans += x[i];
	}
	printf("%d\n", ans);
	return 0;
}

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

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

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

   val a = (0 until 3).map{ i => StdIn.readLine().split(' ').map(_.toInt)}.toArray
   
   // c11 - c21 - (c12 - c22)
   val b1 = a(0)(0) - a(1)(0) - (a(0)(1) - a(1)(1))

   // c12 - c22 - (c13 - c23)
   val b2 = a(0)(1) - a(1)(1) - (a(0)(2) - a(1)(2))
   
   // c21 - c31 - (c22 - c32)
   val b3 = a(1)(0) - a(2)(0) - (a(1)(1) - a(2)(1))

   // c22 - c32 - (c23 - c33)
   val b4 = a(1)(1) - a(2)(1) - (a(1)(2) - a(2)(2))

   println(if(b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0) "Yes" else "No")
}


Measured memory_bytes: 27176
function Main(input) {
	const s = input.split('\n')[0];
  	const t = input.split('\n')[1];
  	
  	const s_sort = s.split('').sort().join('');
  	const t_sort = t.split('').sort().reverse().join('');
  
	console.log(s_sort < t_sort ? "Yes" : "No" );

}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7500
def init_rectangle(w, h):
    rectangle = []
    for x in range(w):
        x_list = []
        for y in range(h):
            x_list.append(True)
        rectangle.append(x_list)
    return rectangle

def area(rectangle):
    count = 0
    for i in rectangle:
        for j in i:
            if j:
                count += 1
    return count

def paint_point(rectangle, w, h, x1, x2, y1, y2):
    for x in range(x1, x2):
        for y in range(h):
            rectangle[x][y] = False
    for x in range(w):
        for y in range(y1, y2):
            rectangle[x][y] = False
        
def paint(rectangle, w, h, points):
    for x, y, a in points:
        x1 = x2 = y1 = y2 = 0
        if a == 1:
            x2 = x
        elif a == 2:
            x1 = x
            x2 = w
        elif a == 3:
            y2 = y
        else:
            y1 = y
            y2 = h
        paint_point(rectangle, w, h, x1, x2, y1, y2)


if __name__ == '__main__':
    w, h, n = list(map(int, input().split()))
    points = [list(map(int, input().split())) for _ in range(n)]
    rectangle = init_rectangle(w, h)
    paint(rectangle, w, h, points)
    print(area(rectangle))

Measured memory_bytes: 3192
#include <bits/stdc++.h> 
#define pb push_back
#define sp " "
#define sl "\n"
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())
#define PI 3.141592

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N=500,mod=1000000007;
int a[N];
int main() { 
	cin.tie(0); cout.tie(0); 
	ios_base::sync_with_stdio();
	for (int i=1;i<=5;i++) { cin>>a[i]; if (a[i]==0) { cout<<i; return 0; }}
	return 0;
}
// Recuerda limites 
// Recuerda casos especiales


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
// 型エイリアス
using pii = pair<int, int>;
using tisb = tuple<int, string, bool>;
using vi = vector<int>;
using vii = vector<vi>;

void print(vi A, int N){
  for(int i=0; i<N; ++i){
    if(i>0) cout << " ";
    cout << A[i];
  }
  cout << endl;
}

void insertionSort(vi A, int N){
  for(int i=1; i<N; ++i){
    int v = A[i];
    int j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1] = A[j];
      --j;
    }
    A[j+1] = v;
    print(A, N);
  }
}

int main(){
  int N; cin >> N;
  vi A(N);
  for(int i=0; i<N; ++i) cin >> A[i];
  
  print(A, N);
  insertionSort(A, N);
}


Measured memory_bytes: 3156
use proconio::*;
use proconio::marker::*;
use std::cmp::*;

pub trait MoOperator {
    type Value;
    type Query;
    type Answer;
    fn init(&mut self);
    fn insert(&mut self, v: &Self::Value);
    fn delete(&mut self, v: &Self::Value);
    fn answer(&mut self, q: Self::Query) -> Self::Answer;
    fn solve(
        &mut self,
        array: &[Self::Value],
        mut query: Vec<(usize, usize, Self::Query)>,
        answer: &mut [Self::Answer],
    ) {
        let state = self;
        let size = array.len();
        assert!(query.len() <= answer.len());
        assert!(query.iter().all(|p| p.0 < p.1 && p.1 <= size));
        if query.is_empty() {
            return;
        }
        let batch = (size as f64 / (query.len() as f64).sqrt()).ceil() as usize;
        let mut q = vec![];
        std::mem::swap(&mut q, &mut query);
        let mut query = (0..(size / batch + 1)).map(|_| vec![]).collect::<Vec<_>>();
        for (i, (l, r, op)) in q.into_iter().enumerate() {
            query[l / batch].push((r, l, i, op));
        }
        state.init();
        let mut x = 0;
        let mut y = 0;
        for (i, mut query) in query.into_iter().enumerate() {
            query.sort_unstable_by_key(|p| p.0);
            if i & 1 == 1 {
                query.reverse();
            }
            for (r, l, k, op) in query.into_iter() {
                // 変更始まり
                while l < x {
                    x -= 1;
                    state.insert(&array[x]);
                }
                while y < r {
                    state.insert(&array[y]);
                    y += 1;
                }
                while x < l {
                    state.delete(&array[x]);
                    x += 1;
                }
                while r < y {
                    y -= 1;
                    state.delete(&array[y]);
                }
                // 変更終わり
                answer[k] = state.answer(op);
            }
        }
    }
}

struct State {
    cnt: Vec<u32>,
    ans: usize,
}

impl MoOperator for State {
    type Value = usize;
    type Query = ();
    type Answer = usize;
    fn init(&mut self) {
        for c in self.cnt.iter_mut() {
            *c = 0;
        }
        self.ans = 0;
    }
    #[inline(never)]
    fn insert(&mut self, x: &Self::Value) {
        let c = &mut self.cnt[*x];
        if *c == 0 {
            self.ans += 1;
        }
        *c += 1;
    }
    #[inline(never)]
    fn delete(&mut self, x: &Self::Value) {
        let c = &mut self.cnt[*x];
        if *c == 1 {
            self.ans -= 1;
        }
        *c -= 1;
    }
    fn answer(&mut self, _q: Self::Query) -> usize {
        self.ans
    }
}

#[fastout]
fn run() {
    input! {
        n: usize,
        q: usize,
        c: [Usize1; n],
        ask: [(Usize1, usize); q],
    }
    let ask: Vec<_> = ask.into_iter().map(|(l, r)| (l, r, ())).collect();
    let mut ans = vec![0; q];
    State {
        cnt: vec![0; n],
        ans: 0,
    }.solve(&c, ask, &mut ans);
    for a in ans {
        println!("{}", a);
    }
}


fn main() {
    run();
}


Measured memory_bytes: 41680
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int[] cost = new int[n];
        int[] time = new int[n];
        int min = 1001;
        for (int i = 0; i < n; i++) {
            cost[i] = sc.nextInt();
            time[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            if (time[i] <= t) {
                if (min > cost[i])
                    min = cost[i];
            }
        }
        if (min != 1001)
            System.out.println(min);
        else
            System.out.println("TLE");
    }
}

Measured memory_bytes: 22740
using System;

class MyClass
{
    static void Main(string[] args)
    {
        int n;
        while ((n = int.Parse(Console.ReadLine())) != 0)
        {
            int pointa = 0;
            int pointb = 0;
            for (int i = 0; i < n; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                int a = int.Parse(str[0]);
                int b = int.Parse(str[1]);
                if (a>b)
                {
                    pointa += a + b;
                }
                else if (a<b)
                {
                    pointb += a + b;
                }
                else
                {
                    pointa += a;
                    pointb += b;
                }
            }
            Console.WriteLine(pointa.ToString() + " " + pointb.ToString());
        }
    }
}


Measured memory_bytes: 20160
my $s = <STDIN>;
my @s = split(//,$s);
my @R;
my @L;
my @ans;

my $R_count = 0;
my $L_count = 0;
my $sakai  = 0;

for( $i = 0; $i<$#s; $i++){
  $R[$i] = 0;
  $L[$i] = 0;
  $ans[$i] = 0;
}

for( $i = 0; $i<$#s; $i++){

  if( $s[$i] eq "R"){
    if( $L_count > 0 ){
      $L[$sakai]  = $L_count;
    }   
    $R_count = $R_count + 1;
    $L_count = 0;
  }else{
    if( $R_count > 0 ){
      $sakai  = $i;
      $R[$i]  = $R_count;
    }
    $L_count = $L_count + 1;
    $R_count = 0;
  }
}

if( $L_count > 0 ){
  $L[$sakai]  = $L_count;
}  
for( $i = 1; $i<=$#s; $i++){
  if($R[$i] >0){
    $ans[$i-1] =  int($R[$i]/2+0.5);
    $ans[$i] =    int($R[$i]/2);
  }
  #print "$R[$i] ";
}

for( $i = 1; $i<$#s; $i++){
  if($L[$i] >0){
    $ans[$i-1] = $ans[$i-1] + int($L[$i]/2);
    $ans[$i] = $ans[$i] + int(($L[$i]/2) + 0.5); 
  }
  #print "$L[$i] ";
}

print "@ans";

Measured memory_bytes: 30412
#include<iostream> 
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
	int x=0,f=1;char c=getchar();
	while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
	while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
int a[5],fa[5];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int main()
{
	for (int i=1;i<=4;i++) fa[i]=i;
	for (int i=1;i<=3;i++)
	{
		int x=read(),y=read();
		a[x]++,a[y]++;fa[find(x)]=find(y);
	}
	for (int i=1;i<=4;i++)
	if (find(i)!=find(1)) {cout<<"NO";return 0;}
	int cnt=0;
	for (int i=1;i<=4;i++)
	{
		if (a[i]&1) cnt++;
	}
	if (cnt==2) cout<<"YES";
	else {cout<<"NO";return 0;}
	return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<queue>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int pow(int x, int a){
    int t = 1;
    for(int i = 0 ; i < a ; i++){
        t *= x;
    }
    return t;
}

int main(){
    int d, n;
    cin >> d >> n;
    int ans = pow(100, d) * n;
    if(n == 100){
        ans += pow(100, d);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<int> a(n, 0);
    int maxe = 0;
    for(int i = 0; i < n; ++i){
        int foo;
        cin >> foo;
        ++a[foo];
        chmax(maxe, foo);
    }

    int d = maxe;
    for(int i = 0; i <= d; ++i){
        int x = max(i, d - i);
        --a[x];
        if(a[x] < 0){
            cout << "Impossible\n";
            return 0;
        }
    }
    
    int bound = ceil((double)d / 2) + 1;
    for(int i = 1; i < n; ++i){
        if(!a[i])   continue;
        if(i < bound){
            cout << "Impossible\n";
            return 0;
        }
    }

    cout << "Possible\n";
}

Measured memory_bytes: 256
import math
a,b, A = map(float, input().split())

h = b*math.sin(math.radians(A))
S = a*h*0.5
L = a + b + math.sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*math.cos(math.radians(A)))

print(S)
print(L)
print(h)



Measured memory_bytes: 5692
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	private static Node[] V;
	private static int N;
	private static int M;
	private static int black = 0;
	private static int white = 0;
	
	public static void main(String[] args) {
		N = sc.nextInt();
		M = sc.nextInt();
		V = new Node[N];
		for(int i=0; i<N; i++) {
			V[i] = new Node();
			V[i].id = i;
		}
		for(int i=0; i<M; i++) {
			int l = sc.nextInt() - 1;
			int r = sc.nextInt() - 1;
			V[l].nbr.add(r);
			V[r].nbr.add(l);
		}
		V[0].dfs(0);
		System.out.println((long)black * (long)white - (long)M);
	}
	
	static class Node {
		int id;
		ArrayList<Integer> nbr = new ArrayList<>();
		boolean used;
		int d;
		
		void dfs(int d) {
			used = true;
			this.d = d;
			if(d%2 == 0) {
				black++;
			} else {
				white++;
			}
			for(int x : nbr) {
				if(!V[x].used) {
					V[x].dfs(d+1);
				} else {
					if(Math.abs(V[x].d - d)%2 == 0) {
						System.out.println((long)N*((long)N-1)/2 - (long)M);
						System.exit(0);
					}
				}
			}
		}
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 57504
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=2e5+5,MOD=1e9+7;
int n,m,ans;
int bin[N],inv[N];

inline int pow(int a,int n)
{
	int res=1ll;
	while (n)
	{
		if (n&1ll) res=res*a%MOD;
		a=a*a%MOD;
		n>>=1ll;
	}
	return res;
}

inline int C(int n,int m)
{
	if (n<m) return 0ll;
	if (!m || n==m) return 1ll;
	return bin[n]*inv[n-m]%MOD*inv[m]%MOD;
}

signed main(){
	scanf("%lld%lld",&n,&m);
	bin[0]=1; inv[0]=1;
	for (register int i=1; i<=n; ++i) bin[i]=bin[i-1]*i%MOD;
	for (register int i=1; i<=n; ++i) inv[i]=pow(bin[i],MOD-2ll);
	for (register int i=1; i<=n; ++i) if (n-i<=m) ans=(ans+C(n,i)*C(n-1,i-1)%MOD)%MOD;
	//i表示一共有i个房间有人
	//原本每个房间有1个人，n个房间有人，所以如果当i个房间有人时，至少要进行n-i步
	//所以当n-i<=m时才可以累加答案
	//每次累加答案时：C(n,i)表示在n个房间内选择i个房间存在人，
	//C(n-1,i-1)表示把n个人分成i组的方案数，用隔板法进行理解 
	printf("%lld\n",ans);
return 0;
}

Measured memory_bytes: 3328