akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    rep(i,n){
        ll a;
        cin>>a;
        if(a%2!=0){
            cout<<"first"<<endl;
            return 0;
        }
    }
    cout<<"second"<<endl;
    return  0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string b; cin >> b;
	if (b == "A") {
		cout << "T" << endl;
	}
	else if (b == "C") {
		cout << "G" << endl;
	}
	else if (b == "G") {
		cout << "C" << endl;
	}
	else if (b == "T") {
		cout << "A" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b;
  cin >> a >> b;
  int answer = -1;
  
	int x,y;
  for(int i = 1; i <= 1000; i++){
    x = i*0.08;
    y = i*0.1;
    if((x == a) && (y == b)){
      answer = i;
      break;
    }
    
  }
  
  
  cout << answer << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

int n, i, x;
vector<int> aux;
ll ans;

int main()
{
    //freopen("test.in","r",stdin);

    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> x;
        aux.pb(x - i);
    }

    sort(aux.begin(), aux.end());
    x = aux[aux.size() / 2];

    for (auto e : aux)
        ans += abs(1LL * x - e);

    cout << ans;


    return 0;
}


Measured memory_bytes: 1400
from sys import stdin
N = int(stdin.readline().rstrip())
data = [int(x) for x in stdin.readline().rstrip().split()]

ans = []
for _ in range(N):
    for i in range(len(data) - 1, -1, -1):
        #print(data,i)
        if data[i] == i+1:
            #print(data[i-1],i,data)
            ans.append(data.pop(-(len(data)-i)))
            break
if data:
    print(-1)
else:
    for j in reversed(ans):
        print(j)

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

int main() {
	int x;
	cin >> x;
	ll ans = (x / 500) * 1000;
	x %= 500;
	ans += (x / 5) * 5;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	string s;
	cin>>s;
	int n=s.size();
	int ans[n]={0};
	for(int i=0;i<n;i++){
		int st=i;
		char x=s[i];
		for(;i<n;i++){
			if(s[i]!=x) break;
		}
		i--;
		if(x=='R'){
			for(int j=st;j<=i;j++){
				int g=i-j;
				if(g%2==0) ans[i]++;
				else ans[i+1]++;
			}
		}
		else{
			for(int j=st;j<=i;j++){
				int g=j-st;
				if(g%2==0) ans[st]++;
				else ans[st-1]++;
			}
		}
	}
	for(int i=0;i<n;i++) cout<<ans[i]<<" ";
}

Measured memory_bytes: 1104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
const ll INF = 1LL<<60;
const ll M = 1000000007;
ll mpow(ll a,ll b){ll res=1;while(b!=0){if(b&1)res=res*a%M;a=a*a%M;b=b>>1;}return res;}
ll mcomb(ll n,ll k){if(k>n/2)return mcomb(n,n-k);ll res=1;for(ll i=0;i<k;i++){res=res*(n-i)%M;res=res*mpow(k-i,M-2)%M;}return res;}
/*template*/

ll hpow(ll a,ll b){
  ll res=1;
  while(b!=0){
    if(b&1)res=res*a%2019;
    a=a*a%2019;
    b=b>>1;
  }
  return res;
}

int main()
{
  string s;cin>>s;
  ll n=s.length();
  ll a[2019]={0};
  ll hoge=0;
  for(ll i=0;i<n;i++){
    hoge=(hoge+(s[n-1-i]-'0')*hpow(10,i))%2019;
    a[hoge]++;
  }
  ll ans=0;
  for(ll i=0;i<2019;i++){
    ans+=a[i]*(a[i]-1)/2;
  }
  cout<<ans+a[0]<<endl;
  return 0;
}


Measured memory_bytes: 3692
#include<stdio.h>

#define N 100

int main(){
  int a,i,j,count = 0;
  int A[N+1];
  int k,l;

  scanf("%d",&a);

  for(i = 1;i <= a;i++){
    scanf("%d",&A[i]);
  } 
    for (i = 1;i <= a;i++){
      k = i;
      for(j = i;j <= a;j++){
	if(A[j] < A[k]){
	  k = j;
	  }
      }
      l = A[i];
      A[i] = A[k];
      A[k] = l;
      if(k != i){
      count++;
      }
    }
    
  for(i = 1;i <= a;i++){
    if(i == a){
      printf("%d",A[i]);
    }
    else
    printf("%d ",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  
  return 0;
}




Measured memory_bytes: 2048
#include <stdio.h>

/** Application main entry point. */
int main (
  int argc,
  char *argv[ ]
  )
{
  int a, b;

  while ( scanf ( "%d%d", &a, &b ) == 2 )
  {
    printf ( "%d\n", a + b );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#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-1; i >= 0; i--)
#define all(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    priority_queue<int> pq;
    rep(i, n) {
        cin >> a[i];
        pq.push(a[i]);
    }
    rep(i, m) {
        int x = pq.top();
        pq.pop();
        x /= 2;
        pq.push(x);
    }
    ll sum = 0;
    rep(i, n) {
        sum += pq.top();
        pq.pop();
    }
    cout << sum << endl;
}

Measured memory_bytes: 4284
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N,K = II()
H = III()

if N==K:
    print(0)
    exit()

dp = [[float('inf')]*(N-K+1) for _ in range(N)]

for x in range(N):
    for y in range(N-K+1):
        if x+1<y:
            continue
        elif y==0:
            dp[x][y] = float('inf')
        elif y==1:
            dp[x][y] = H[x]
        else:
            val = float('inf')
            for i in range(x):
                now = dp[i][y-1] + max(0,H[x]-H[i])
                if now<val:
                    val = now
            dp[x][y] = val

ans = float('inf')
for i in range(N):
    if dp[i][N-K]<ans:
        ans = dp[i][N-K]

print(ans)

Measured memory_bytes: 46600
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;

string s;
int c[9];
int ct[9];
vector<int> ans;

bool puzzle(int k){
	bool f;
	rep(i,9){
		if(k==4){
			if(c[i]==2) return true;
		}
		if(i<=6&&c[i]&&c[i+1]&&c[i+2]){
			c[i]--; c[i+1]--; c[i+2]--;
			f = puzzle(k+1);
			c[i]++; c[i+1]++; c[i+2]++;
			if(f) return f;
		}
		if(c[i]>2){
			c[i]-=3;
			f = puzzle(k+1);
			c[i]+=3;
			if(f) return f;
		}
	}
	return false;
}



int main(){
	while(cin>>s){
		rep(i,9){
			ct[i]=0;
		}
		rep(i,13){
			ct[s[i]-'1']++;
		}
		rep(i,9){
			rep(j,9){
				c[j]=ct[j];
			}
			if(c[i]>=4) continue;
			c[i]++;
			if(puzzle(0)) ans.PB(i+1);
		}
		if(ans.empty()) cout<<0;
		else rep(i,ans.size()) cout<<(i==0?"":" ")<<ans[i];
		cout<<endl;
		memset(ct,0,sizeof(ct));
		ans.clear();
	}
	return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
vector<int> a;
bool dp[100005][2];
int main() {
    int n,K;
    cin>>n>>K;
    a.resize(n);
    int minv = INT_MAX;
    for(int i = 0;i<n;i++) {
        cin>>a[i];
        if(minv > a[i]) {
            minv = a[i];
        }
    }
    sort(a.begin(),a.end());
    //dp[k][0] is true if first wins when first starts and vice versa
    //dp[k][1] is true when two wins if two starts and vice versa
    // dp[k][0] = for all i &dp[k-a[i]][1]
    //dp[0][0] = false
    //dp[0][1] = false

    for(int k = 1;k<=K;k++) {
        int ok1 = 0;
        int ok2 = 0;
        for(int i = 0;i<n;i++) {
            if(k < a[i]) break;

            if(k >= a[i] && dp[k-a[i]][0] == false) {
                dp[k][1] = true;
                ok1++;
            }
            if(k >= a[i] && dp[k-a[i]][1] == false) {
                dp[k][0] = true;
                ok2++;
            }
            if(ok1 > 0 && ok2 > 0) break;
        }
       // printf("dp[%d][0] = %d , dp[%d][1] = %d \n",k,dp[k][0],k,dp[k][1]);
    }

    if(dp[K][0]) printf("First\n");
    else printf("Second\n");

}

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

int main() {
	
	int N;
	cin >> N;
	int A[21]{};
	int B[51]{};
	int C[51]{};
	for (int i = 0; i < N; i++) cin >> A[i];
	for (int i = 0; i < N; i++) cin >> B[i];
	for (int i = 0; i < N - 1; i++) cin >> C[i];

	int count = 0;
	for (int i = 0; i < N; i++)
	{
		count += B[A[i] - 1];
		if (i == 0) continue;
		if (A[i - 1] + 1 == A[i])
		{
			count += C[A[i - 1] - 1];
		}
	}

	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#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,m;
  cin >> n >> m;
  vector<P> v(m);
  rep(i,m) cin >> v[i].first >> v[i].second;
  sort(v.begin(),v.end());

  int ans = 1;
  P p = v[0];
  rep(i,m){
    if(p.second<=v[i].first){
      ++ans;
      p = v[i];
    }else{
      p.first = max(p.first,v[i].first);
      p.second = min(p.second,v[i].second);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
typedef long long ll;
const int MAXN = 200005;

int n, k, Index, a[MAXN];
ll ans, sum[MAXN];
namespace BIT{
	ll c[MAXN];
	inline int lowbit( int x ){ return x&-x; }
	inline void add( int pos, int x ){
		for( int i = pos; i <= Index; i += lowbit(i) )
			c[i] += x;
	}
	inline ll query( int pos ){
		ll ret = 0;
		for( int i = pos; i; i -= lowbit(i) )
			ret += c[i];
		return ret;
	}
}

namespace Discrete{
	int pcnt; ll *ptr[MAXN];
	inline bool cmp( ll *a, ll *b ){
		return *a < *b;
	}
	inline void insert( ll *p ){
		ptr[++pcnt] = p;
	}
	inline void init(){
		sort( ptr+1, ptr+pcnt+1, cmp );
		Index = 1; ll last = *ptr[1];
		for( int i = 1; i <= pcnt; ++i ){
			if( last == *ptr[i] ) *ptr[i] = Index;
			else last = *ptr[i], *ptr[i] = ++Index;
		}
	}
}

int main(){
	scanf( "%d%d", &n, &k );
	for( int i = 1; i <= n; ++i ){
		scanf( "%d", &a[i] );
		sum[i] = sum[i-1] + a[i];
	}
	sum[0] = 0;
	for( int i = 0; i <= n; ++i ){
		sum[i] -= (ll)i * k;
		Discrete::insert(sum+i);
	}
	Discrete::init();
	for( int i = 0; i <= n; ++i ){
		ans += BIT::query( (int)sum[i] );
		BIT::add( (int)sum[i], 1 );
	}
	printf( "%lld\n", ans );
	return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug0(x) printf("! %d\n", x);
#define debug1(x, a, b) for(int (ii)=(a);(ii)<(b);(ii++)) printf("%d: %d\n", ii, x[ii]);
#define nono(x, ite) for(__typeof((x).begin()) (ite)=(x).begin();(ite)!=(x).end();(ite++))

typedef long long ll;

const int N = 1e5 + 10;

bool flag;
int n, cnt, m, vis[N], col[N];
vector<int> G[N];
vector<int> comp;

void dfs(int u, int c) {
  vis[u] = 1;
  cnt++;
  col[u] = c;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!vis[v]) {
      dfs(v, c ^ 1);
    } else {
      if (c ^ 1 != col[v]) {
        flag = false;
      }
    }
  }
}

int main() {
  memset(col, -1, sizeof col);
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    cnt = 0;
    flag = true;
    dfs(i, 1);
    if (cnt != 1) {
      if (flag) ans += 2;
      else ans += 1;
    }
    if(flag == true) comp.push_back(cnt);
    else comp.push_back(-cnt);
  }
  int mul_one = 0;
  int mul_1 = 0, mul_2 = 0;
  for (int i = 0; i < comp.size(); i++) {
    if (comp[i] == 1) {
      ans += (long long)2 * (n - 1) + 1 - mul_one * 2;
      mul_one++;
    } else {
      if(comp[i] > 0) mul_2++;
      else mul_1++;
    }
  }
  ans += (long long) mul_1 * (mul_1 - 1);
  ans += (long long) mul_2 * mul_1 * 2;
  ans += (long long) mul_2 * (mul_2 - 1)* 2;
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 10368
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i ,a) for(int i = 0; i < (a); i++)
#define	all(u) (u).begin(), (u).end()
using namespace std;
typedef	pair<int, int> pii;

int N, M;
vector<pii> inter;

int main() {
  cin >> N >> M;
  inter.resize(M);
  rep(i, M) cin	>> inter[i].first >> inter[i].second;
  sort(all(inter));
  int right = 0, cur = 0;
  int cnt	= 0;
  bool used[128] = {false};
  while(true) {
    if(right == N) {
      cout << cnt << endl;
      return 0;
    }
    int use	= -1;
    while(cur < inter.size() && inter[cur].first <= right + 1){ 
      if(use < inter[cur].second) use = inter[cur].second;
      cur++;
    }
    if(use == -1) break;
    right =	use;
    cnt++;
  }
  cout << "Impossible" << endl;
  return 0;
}



Measured memory_bytes: 3108
#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
//bを何回足せばaを超えるか
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
const int INF=100000001,ID_MAX=20;
int bi_e[ID_MAX]={0};
//2進数表示したときの最高桁
int bi_max(long n){
    int m=0;
    for(m;pow(2,m)<=n;m++);m=m-1;
    return m;
}
//bi_eに二進数表示したやつを代入
void bi_exs(long n){
    rep(i,ID_MAX){
        bi_e[i]=0;
    }
    if(n<pow(2,ID_MAX)){
        int m=bi_max(n);
        long l;
        for(m;m>-1;m--){
            l=pow(2,m);
            bi_e[m]=n/l;
            n=n%l;
        }
    }
}



int main(){
    int i,n,m,x;
    long s=0;
    //入力
    cin>>n>>m;
    rep(i,m){
        cin>>x;
        s+=x;
    }
    //処理
    //出力
    if(s>n)cout<<-1<<endl;
    else cout<<n-s<<endl;
}

Measured memory_bytes: 3684
from heapq import heappop, heappush

N = int(input())
L = [[] for i in range(N + 1)]
Fd = [float("inf") for i in range(N + 1)]
Sd = [float("inf") for i in range(N + 1)]
Fd[1] = 0
Sd[N] = 0

for i in range(N - 1):
    a, b = list(map(int, input().split()))
    L[a].append(b)
    L[b].append(a)

Q = []
heappush(Q, 1)
while Q:
    n = heappop(Q)
    d = Fd[n]
    for x in L[n]:
        if Fd[x] == float("inf"):
            Fd[x] = d + 1
            heappush(Q, x)

Q = []
heappush(Q, N)
while Q:
    n = heappop(Q)
    d = Sd[n]
    for x in L[n]:
        if Sd[x] == float("inf"):
            Sd[x] = d + 1
            heappush(Q, x)

f = 0
s = 0
for i in range(1, N + 1):
    if Fd[i] <= Sd[i]:
        f += 1
    else:
        s += 1

if f > s:
    print("Fennec")
else:
    print("Snuke")

Measured memory_bytes: 38980
N, A, B = list(map(int, input().split()))

if A > B:
    ans = 0
elif A == B:
    ans = 1
elif N == 1:
    ans = 0
else:
    mn = A + B + A * (N-2)
    mx = A + B + B * (N-2)
    ans = mx - mn + 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};

void solve(int cn) {
    int N; string S;
    cin>>N>>S;
    int rcnt=0,wcnt=0;
    for(char c:S) if(c=='R') rcnt++;
    if(rcnt==N){
        cout<<0<<endl;
        return;
    }
    if(S[0]=='W') wcnt++;
    for(int i=1;i<S.length();++i){
        if(S[i-1]=='R') rcnt--;
        if(S[i]=='W') wcnt++;
        if(rcnt<=wcnt){
            cout<<rcnt<<endl;
            return;
        }
    }
}


#define SINGLE
int main() {
#ifdef SINGLE
    solve(1);
#else
    int N;
    cin>>N;
    for(int i=0;i<N;++i){
        solve(i);
    }
#endif
    return 0;
}


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

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

  string s,t;
  cin>>s>>t;
  int sl=s.size(), tl=t.size();
  int dp[sl+1][tl+1];
  memset(dp,0,sizeof(dp));

  for (int i = 1; i <= sl; ++i)
  {
  	for(int j=1; j <= tl ; ++j)
  	{
  		if(s[i-1]==t[j-1])
         dp[i][j] = dp[i-1][j-1] + 1;
        else
        	dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
  	}
  }

  string lcs="";

  int i=sl,j=tl;
  while(i>0 && j>0)
  {
  	if(s[i-1] == t[j-1] )
  	{
      lcs = s[i-1] + lcs;
      i--;
      j--;
  	}
  	else
  	{
  		if(dp[i-1][j]>dp[i][j-1])
  			i--;
  		else
  			j--;
  	}
  }

  cout<<lcs;


  return 0;
}

Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=1000010,O=998244353;
inline int fpow(int x,int n){
	int a=1;
	for(;n;n>>=1,x=(lint)x*x%O){
		if(n&1){
			a=(lint)a*x%O;
		}
	}
	return a;
}
inline int inv(int x){
	return fpow(x,O-2);
}
int fac[N],invfac[N];
inline int F(int a,int b){
	return (lint)fac[a+b]*invfac[a]%O*invfac[b]%O;
}
inline void gmath(int n){
	fac[0]=1;
	for(int i=1;i<=n;i++){
		fac[i]=(lint)fac[i-1]*i%O;
	}
	invfac[n]=inv(fac[n]);
	for(int i=n;i>=1;i--){
		invfac[i-1]=(lint)invfac[i]*i%O;
	}
}
int main(){
	int n=ni,m=ni;
	gmath(n+m);
	lint ans=0;
	for(int i=1,ti=min(n,m);i<=ti;i++){
		ans+=(lint)F(i,i)*F(n-i,m-i)%O;
	}
	ans=ans%O*inv((F(n,m)<<1)%O)%O;
	printf("%lld\n",(ans+max(n,m))%O);
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main () {
  string s, t;
  cin >> s >> t;
  int a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  
  if (u==s) a-=1;
  else b-=1;
  printf("%d %d", a, b);
}


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

int main(){
	string s;
	cin >> s;
	int head = 0;
	int tail = 0;
	rep(i, s.size()){
		if(s.at(i) == 'A'){
			head = i;
			break;
		}
	}

	rep(i, s.size()){
		if(s.at(i) == 'Z')
			tail = i;
	}

	cout << tail - head + 1 << endl;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
      	String A = sc.next();
      	String B = sc.next();
      	String C = sc.next();
      	StringBuffer chA =new StringBuffer(A);
      	StringBuffer chB =new StringBuffer(B);
      	StringBuffer chC =new StringBuffer(C);
		int cnt = 0;
      	for(int i=0;i<N;i++){
        	if(chA.charAt(i) == chB.charAt(i) && chB.charAt(i) == chC.charAt(i)){
            	cnt += 0;
            }else if(chA.charAt(i) == chB.charAt(i) ||
                     chB.charAt(i) == chC.charAt(i) ||
                     chC.charAt(i) == chA.charAt(i)){
              	cnt += 1;
            }else{
            	cnt += 2;
            }
        }
        System.out.println(cnt);
    }
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  int n;
  cin >> n;
  cout << n * n * n << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <iostream>
#include <fstream>

using namespace std;

const int DIV = 1000000007;

void execute(int test, istream &in) {
    int x, y;
    in >> x >> y;
    bool yes = false;
    for (int i = 0; i <= x; i++) {
        int j = x - i;
        int a = i * 4 + j * 2;
        if (a == y) {
            yes = true;
        }
    }
    printf("%s", yes ? "Yes" : "No");
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
    //FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
#else
    //FILE *f = stdin;
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        execute(test, f);
    }
    return 0;
}


Measured memory_bytes: 3764
import java.util.Scanner;

public class Main {
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
       while(true){
           int h = scan.nextInt();
           int w = scan.nextInt();
           if(h == 0 && w == 0)break;

           for(int i = 0;i < h;i++){
               for(int j = 0;j < w;j++)System.out.print("#");
               System.out.println();
           }
           System.out.println();
       }
       scan.close();
    }
}


Measured memory_bytes: 32656
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    map<int, bool> mp;
    map<int, int> mpp;

    int ac = 0, pena = 0;
    rep(i, m)
    {
        int p;
        string s;
        cin >> p >> s;
        if (s == "AC")
        {
            if (mp[p] == false)
            {
                ac++;
                mp[p] = true;
            }
        }
        else
        {
            if (mp[p] == false)
            {
                mpp[p]++;
            }
        }
    }
    rep(i, n + 1)
    {
        if (mp[i] == true)
        {
            pena += mpp[i];
        }
    }
    cout << ac << " " << pena << endl;
    return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define out(v) cout<<v<<"\n"

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N, K; cin >> N >> K;

  int a[N];
  rep(i, N) {
    cin >> a[i];
  }
  vector<ll> sum;
  rep(l, N) {
    rep(r, l, N) {
      ll s = 0;
      rep(i, l, r+1) {
        s += a[i];
      }
      sum.push_back(s);
    }
  }
  ll x = 0;
  ll t = 1LL;
  rep(i, 39) t *= 2;
  rep(k, 40) {
    int count = 0;
    rep(i, sum.size()) {
      if (((x + t) & sum[i]) == x + t)
        ++count;
    }
    if (count >= K)
      x += t;
    t /= 2;
  }
  out(x);

  return 0;
}


Measured memory_bytes: 6512
#pragma GCC optimize(3 , "Ofast" , "inline")

#include <bits/stdc++.h>

#define rep(i , a , b) for(register int i=(a);i<=(b);i++)
#define per(i , a , b) for(register int i=(a);i>=(b);i--)


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int , int> pi;

template<class T>
inline void read (T &x) {
    x = 0;
    int sign = 1;
    char c = getchar ();
    while (c < '0' || c > '9') {
        if ( c == '-' ) sign = - 1;
        c = getchar ();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar ();
    }
    x = x * sign;
}

const int maxn = 2e5 + 10;
const int inf = int (1e9);
const ll INF = ll (1e18);
const double PI = acos (- 1);
const int mod = 1e9+7;
const double eps = 1e-8;

unordered_map<string,int>mp;
vector<string>v;
int main () {
    int n;
    read (n);
    int ma=0;
    rep (i,1,n) {
        string s;
        cin>>s;
        mp[s]++;
        ma=max (ma,mp[s]);
    }
    map<string,int>::iterator it;
    for(auto x:mp) {
        if(x.second==ma) {
            v.push_back (x.first);
        }
    }
    sort (v.begin (),v.end ());
    for( auto x:v) {
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 26692
//
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        c: chars,
    }
    let num: u8 = c[0] as u8;
    let res: char = (num + 1) as char;
    println!("{}", res);
}


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S; S = "#" + S;
    int N = S.length();
    vector<ll> A(N, -1);
    rep(i, N-1){
        if(S[i] == '>' && S[i+1] == '<'){
            A[i] = 0;
            int pl = i, pr = i;
            while(pl >= 0 && S[pl] == '>'){
                A[pl-1] = max(A[pl-1], A[pl]+1);
                pl--;
            }
            while(pr < N-1 && S[pr+1] == '<'){
                A[pr+1] = max(A[pr+1], A[pr]+1);
                pr++;
            }
        }
    }
    if(A[0] == -1){
        A[0] = 0;
        for(int i = 1; i < N && S[i] == '<'; i++) A[i] = max(A[i], A[i-1]+1);
    }
    if(A[N-1] == -1){
        A[N-1] = 0;
        for(int i = N-1; i >= 0 && S[i] == '>'; i--) A[i-1] = max(A[i-1], A[i]+1);
    }

    ll ans = 0;
    rep(i, N) ans += A[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4784
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int H, W, Q;
  cin >> H >> W >> Q;
  ++H;
  ++W;
  vector<vector<int>> S(H, vector<int>(W, 0));
  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      char c;
      cin >> c;
      S[i][j] = c - '0';
    }
  }
  vector<vector<int>> dpv(H, vector<int>(W, 0)), dpe(H, vector<int>(W, 0)),
      rowe(H, vector<int>(W, 0)), cole(H, vector<int>(W, 0));
  for (int i = 1; i < H; i++) {
    for (int j = 1; j < W; j++) {
      dpv[i][j] = dpv[i - 1][j] + dpv[i][j - 1] - dpv[i - 1][j - 1];
      dpe[i][j] = dpe[i - 1][j] + dpe[i][j - 1] - dpe[i - 1][j - 1];
      rowe[i][j] = rowe[i][j - 1];
      cole[i][j] = cole[i - 1][j];
      if (S[i][j]) {
        dpv[i][j] += 1;
        dpe[i][j] += S[i - 1][j] + S[i][j - 1];
        rowe[i][j] += S[i - 1][j];
        cole[i][j] += S[i][j - 1];
      }
    }
  }
  for (int q = 0; q < Q; q++) {
    int y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    int v =
        dpv[y2][x2] - dpv[y1 - 1][x2] - dpv[y2][x1 - 1] + dpv[y1 - 1][x1 - 1];
    int e =
        dpe[y2][x2] - dpe[y1 - 1][x2] - dpe[y2][x1 - 1] + dpe[y1 - 1][x1 - 1];
    e -= rowe[y1][x2] - rowe[y1][x1 - 1];
    e -= cole[y2][x1] - cole[y1 - 1][x1];
    cout << v - e << endl;
  }
  return 0;
}


Measured memory_bytes: 80384
#include<stdio.h>
#define M 100000

int f[M];

int partition_s(int f[],int g,int h){
  int x,y,z,s;
  x=f[h];
  y=g-1;
  for(z=g;z<h;z++){
    if(f[z]<=x){
      y++;
      s=f[y];
      f[y]=f[z];
      f[z]=s;
    }
  }
  s=f[y+1];
  f[y+1]=f[h];
  f[h]=s;
  return y+1;
}


int main()
{
  int i,lo,re;

  scanf("%d",&lo);

  for(i=0;i<lo;i++){
    scanf("%d",&f[i]);
  }

  re=partition_s(f,0,lo-1);
  for(i=0;i<lo;i++){
    if(i>0) printf(" ");
    if(i==re) printf("[");
    printf("%d",f[i]);
    if(i==re) printf("]");
  }
  printf("\n");

  return 0;
}

  



Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
using namespace std;
int main(){
int n;
cin >> n;
int h[100];
for(int i=0;i<100;i++){
cin >> h[i];
}

int count=0;

for(int i=0;i<n;i++){
 for(;h[i]>0;){
  for(int j=i;j<n && h[j]>0;j++){
   
     h[j]--;
   }
   count++;

 }

}
cout << count;


return 0;
  
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189
AC
"""
import sys
from sys import stdin
input = stdin.readline


def warshallFloyd(V, dp):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                dp_ik = dp[i][k]
                dp_kj = dp[k][j]
                if dp[i][j] > dp_ik + dp_kj:
                    dp[i][j] = dp_ik + dp_kj


def main(args):
    while True:
        n_max = 9+1
        n = int(input())
        if n == 0:
            break
        dp = [[float('inf')] * n_max for _ in range(n_max)]
        for i in range(n_max):
            dp[i][i] = 0

        max_town = 0
        for _ in range(n):
            a, b, c = map(int, input().split())
            dp[a][b] = c
            dp[b][a] = c
            if a > max_town:
                max_town = a
            if b > max_town:
                max_town = b

        warshallFloyd(max_town + 1, dp)


        min_dist = float('inf')
        town_live = -1
        for i, d in enumerate(dp[:max_town+1]):
            sum_dist = sum(d[:max_town+1])
            if sum_dist < min_dist:
                min_dist = sum_dist
                town_live = i

        print('{} {}'.format(town_live, min_dist))



if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7764
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

const int MAX = 510000; //nCrのr
//const ll INF = (ll)1e18 + 1;

#include <cassert>
long long fac[MAX], finv[MAX], inv[MAX], facn[MAX];
class mint {
public:
    long long x;
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    //mint operator-() const{ return mint(-x);}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

};

struct combination {
    vector<mint> fact, ifact;
    combination(long long n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(long long n, long long k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};


int main(){
  combination C(1000000);
  int H, W, A, B; cin >> H >> W >> A >> B;
  mint ans = 0;
  for (int i = 0; i <= H - A - 1; ++i){
    ans += C(B - 1 + i, B - 1) * C(H + W - B - 2 - i, W - B - 1);
  }
  cout << ans.x << endl;
}


Measured memory_bytes: 15872
N,M,C=map(int,input().split())
B=list(map(int,input().split()))
A = []
for _ in range(N):
  a=list(map(int,input().split()))
  A.append(a)

ans = 0
for n in range(N):
  score = 0
  a = A[n]
  for m in range(0,M):
    score += a[m] * B[m]
  if score + C > 0:
    ans += 1
print(ans)



Measured memory_bytes: 3064
let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let ab = Array.init n (fun _ -> Scanf.scanf " %d %d" (fun x y -> x, y)) in
  Array.sort compare ab;
  Array.fold_left (fun (c, t) (a, b) ->
    if t >= m then (c, t)
    else
    let d = min (m - t) b in
    (c + a * d, t + d)) (0, 0) ab
  |> fst |> Printf.printf "%d\n"


Measured memory_bytes: 6656
#include<bits/stdc++.h>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int fir[100010],dis[400010],nxt[400010],id;
void link(int a,int b){nxt[++id]=fir[a],fir[a]=id,dis[id]=b;}
bool col[100010],vis[100010],yes;int cnt;
void dfs(int x){
	vis[x]=1;++cnt;
	for(int i=fir[x];i;i=nxt[i]){
		if(!vis[dis[i]])col[dis[i]]=!col[x],dfs(dis[i]);
		else if(col[dis[i]]==col[x])yes=1;
	}
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),a,b;
	for(int i=1;i<=m;++i)a=gi(),b=gi(),link(a,b),link(b,a);
	int c1=0,c2=0,c3=0;
	for(int i=1;i<=n;++i)
		if(!vis[i]){
			yes=0,cnt=0,dfs(i);
			if(cnt==1)++c3;
			else if(yes)++c1;
			else ++c2;
		}
	printf("%lld\n",1ll*c2*c2+1ll*(c1+c2)*(c1+c2)+2ll*c3*n-1ll*c3*c3);
	return 0;
}


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

int main() {
   int N;
   cin >> N;
   int C[N-1],S[N-1],F[N-1];
   for (int i=0; i<N-1; i++) {
       cin >> C[i] >> S[i] >> F[i];
   }
   for (int i=0; i<N-1; i++) {
       int t=S[i];
       for (int j=i; j<N-1; j++) {
           if (t<S[j]) t=S[j];
           while (t%F[j]!=0) {
               t++;
           }
           t+=C[j];
       }
       cout << t << endl;
   }
   cout << 0 << endl;
}

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


int main() {
  int N;
  string S;
  ll ans=1;
  cin >> N >> S;
  for(int i=1; i<N; i++){
    if(S.at(i)!=S.at(i-1)){ans++;}
  }
   cout << ans << endl;
}

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

using namespace std;

int main ()
{
    int n, r;
    scanf("%d %d", &n, &r);
    if (n >= 10)
        printf("%d\n", r);
    else {
        int ans = 100 * (10 - n);
        printf("%d\n", ans + r);
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int a,b;
   cin>>a>>b;
   if(a==1){
    a=14;
   }
   if(b==1){
    b=14;
   }
   if(a==b){
    cout<<"Draw";
   }
   else if(a>b){
    cout<<"Alice";
   }
   else if(b>a){
    cout<<"Bob";
   }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    else {
        return gcd(b, a % b);
    }
}
int main() {
    ll n, k;
    cin >> n >> k;
    ll a[n + 1];
    ll M = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (a[i] > M) M = a[i];
    }
    ll g = a[1];
    for (int i = 2; i <= n; i++) {
        g = gcd(g, a[i]);
    }
    if ((k % g)||(k > M)) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        cout << "POSSIBLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 4400
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		
		double x = 0;
		double y = 0;
		double r = 0;
		double w = 90;
		double t;
		String[] inputData = new String[2];

		while (true) {
			inputData = sc.nextLine().split(",");
	
			r = Double.valueOf(inputData[0]);
			t = Double.valueOf(inputData[1]);
			x += r * Math.cos(w / 180 * Math.PI);
			y += r * Math.sin(w / 180 * Math.PI);
			w -= t;
			
			if (r == 0 && t == 0) {
				break;
			}
		}
		System.out.println((int) x);
		System.out.println((int) y);
	}

}

Measured memory_bytes: 26156
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll = long long int;

const ll INF = 1<<30;
const ll LINF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void) {
    int n, k; cin >> n >> k;
    vector<int> p(n);
    REP(i, n) cin >> p[i];
    sort(ALL(p));
    int sum = 0;
    REP(i, k) sum += p[i];
    cout << sum << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <iomanip>  //桁数を指定するためのヘッダー
#include <bits/stdc++.h>
using namespace std;

int main(){
    double r;
    cin >> r;
    double p = M_PI;
    cout << fixed << setprecision(6);
    cout << p*r*r << " " << 2*p*r << endl;
    return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
   int64_t N, ans = 1;
   cin >> N;
   vector<int64_t> A(1000, 1);
   for (int i = 2; i < N + 1; i++) {
       int k = i;
       for (int j = 2; k > 1; j++) {
           while(k % j == 0) {
               A.at(j)++;
               k /= j;
           }
       }
   }
   for (int i = 0; i < 1000; i++) {
       ans = ans * A.at(i) % 1000000007;
   }
   cout << ans << endl;

}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
import fractions


lcm=int(c*d/fractions.gcd(c,d))

cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
cd=b//lcm-(a-1)//lcm

print((b-a+1)-(cc+dd-cd))


Measured memory_bytes: 5304
#include<bits/stdc++.h>
using namespace std;
int a[3][101]={0};
int f[3][101]={0};
int main()
{
	int i,j,b,c,n;
	scanf("%d",&n);
	for(i=1;i<=2;i++)
	{
		for(j=1;j<=n;j++)
		{
			scanf("%d",&a[i][j]);
			
		} 
	}
	for(i=1;i<=2;i++)
	{
		for(j=1;j<=n;j++)
		{
			if(f[i-1][j]>f[i][j-1])
			{
				f[i][j]=f[i-1][j]+a[i][j];
			}
			else
			{
				f[i][j]=f[i][j-1]+a[i][j];
			}
		}
	}
	printf("%d",f[2][n]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,u,v,i,j;
	scanf("%i",&n);
	set<pair<int,int>> es;
	if(n&1)
	{
		for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) es.insert({i,j});
		for(i=1;i<n-i;i++) es.erase({i,n-i});
		printf("%i\n",es.size());
		for(auto e:es) printf("%i %i\n",e.first,e.second);
	}
	else
	{
		for(i=1;i<=n;i++) for(j=i+1;j<=n;j++) es.insert({i,j});
		es.erase({1,n});
		for(i=2;i<n-i+1;i++) es.erase({i,n-i+1});
		printf("%i\n",es.size());
		for(auto e:es) printf("%i %i\n",e.first,e.second);
	}
	return 0;
}

Measured memory_bytes: 512
I=lambda:list(map(int,input().split()))
n,m=I()
s=eval('I(),'*m)
p=I()
a=0
r=range
for i in r(1<<n):
 c=[0]*m
 for j in r(n):
  for k in r(m):c[k]+=i>>j&1and j+1in s[k][1:]
 a+=all(j==i%2for i,j in zip(c,p))
print(a)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
struct edge{int from, to;};

int main(){
    int n;
    cin>>n;
    vector<int> d(n);
    rep(i,n) cin>>d.at(i);
    sort(d.begin(), d.end(), greater<int>());
    int count=0,tmp=d[0];
    rep(i,n){
        if(tmp>d[i]){
            tmp=d[i];
            count++;
        }
    }
    cout << count+1 << endl;
    return 0;
}

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

#define LL long long
#define LB long double
#define ull unsigned long long
#define x first
#define y second
#define pb push_back
#define pf push_front
#define mp make_pair
#define Pair pair<int,int>
#define pLL pair<LL,LL>
#define pii pair<double,double>

const int INF=2e9;
const LL LINF=2e16;
const int magic=348;
const int MOD=998244353;
const double eps=1e-10;
const double pi=acos(-1);

inline int getint()
{
	bool f;char ch;int res;
	while (!isdigit(ch=getchar()) && ch!='-') {}
	if (ch=='-') f=false,res=0; else f=true,res=ch-'0';
	while (isdigit(ch=getchar())) res=res*10+ch-'0';
	return f?res:-res;
}

const int MAXN=2e5;

int n;
int a[MAXN+48],b[MAXN+48];

int main ()
{
	int i;n=getint();
	for (i=1;i<=n*2-1;i++) a[i]=getint();
	int l=1,r=n*2-1,mid;
	while (l<=r)
	{
		mid=(l+r)>>1;
		for (i=1;i<=n*2-1;i++) if (a[i]<=mid) b[i]=0; else b[i]=1;
		int L=n,R=n,res;
		while (b[L]!=b[L-1] && b[R]!=b[R+1] && L>=2) L--,R++;
		if (L==1) res=b[1]; else if (b[L]==b[L-1]) res=b[L]; else res=b[R];
		if (!res) r=mid-1; else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000007
using namespace std;
ll a[200009],b[200009];
ll pow1(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y%2)
            res=res*x%inf;
        x=x*x%inf;
        y/=2;
    }
    return res;
}
int main()
{
    ll n,k,ans=0;
    scanf("%lld%lld",&n,&k);
    a[0]=1,b[0]=1;
    for(int i=1;i<=n;i++)
        a[i]=a[i-1]*(ll)(i)%inf,b[i]=b[i-1]*pow1((ll)i,inf-2)%inf;
    for(int i=1;i<=min(n-1,k);i++)
        ans=(ans+a[n]*b[i]%inf*b[n-i]%inf*a[n-1]%inf*b[i]%inf*b[n-i-1]%inf)%inf;
    if(k>=2)
        ans=(ans+1)%inf;
    printf("%lld",ans);
    return 0;
}


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

int main(){
	int n;cin >> n;
	long long a = 1;
	 /*while(n){
	 	a*=n--;
	 }*/
	for(int i = 1;i <= n;i++)a*=i;
	cout << a << endl;
	return 0; 
}

Measured memory_bytes: 3088
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,K;
ll A,B,C,D,X,Y;
ll ans=INF;
vector<ll> G[100010];
string S,T,U;
ll F[100010];
bool ok=true;
std::queue<ll> Q;

int main(){
    cin>>N>>M;
    REP(i,100010)F[i]=-1;
    REP(i,M){
        ll a,b;cin>>a>>b;a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    Q.push(0);
    while (!Q.empty()){
        ll loop=Q.size();
        REP(qwe,loop){
            ll pos=Q.front();Q.pop();
            for(auto x:G[pos]){
                if(F[x]==-1){
                    F[x]=pos;
                    Q.push(x);
                }
            }
        }
    }
    REP(i,N){
        if(F[i]==-1){
            cout<<"No";return 0;
        }
    }
    cout<<"Yes"<<endl;
    REP(i,N-1){
        cout<<F[i+1]+1<<endl;
    }
    

    

}


Measured memory_bytes: 12964
#ひとまず長さだけ持つ，後から表を後ろ向きに見て復元を試みる

s=input()
t=input()

ls=len(s)
lt=len(t)
    
    
#sのi文字目とtのj文字目までで取れる最長部分列の長さ
dp=[[0]*(lt+1) for _ in range(ls+1)]

for i in range(ls):
    for j in range(lt):
        if s[i]==t[j]:
            dp[i+1][j+1]=dp[i][j]+1
        else:
            dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])

ans=""
i=ls
j=lt
while(i>0 and j>0):
    if dp[i][j]==dp[i-1][j]:
        i-=1
    elif dp[i][j]==dp[i][j-1]:
        j-=1
    else:
        i-=1
        j-=1
        ans+=s[i]
        


print(ans[::-1])

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> a(n),b(m);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<m; i++){
		cin >> b[i];
	}
	vector<int> res_and, res_or;
	set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res_and));
	set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(res_or));
	cout << res_and.size() << " " << res_or.size() << endl;
	for(int i: res_and){
		cout << i << endl;
	}
	for(int i: res_or){
		cout << i << endl;
	}
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    string A, B, C; cin >> A >> B >> C;
    if(A.back() == B[0] && B.back() == C[0]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3628