akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num[] = new int[6];
		int upSide, frontSide;
		for (int i = 0; i < 6; i++) {
			num[i] = sc.nextInt();
		}
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			Dice d = new Dice(num);
			upSide = sc.nextInt();
			frontSide = sc.nextInt();
			d.printDiceSide(upSide, frontSide);
		}

	}
}

class Dice {
	int num[];
	int temp;

	public Dice(int num[]) {
		this.num = num;
	}

	void printDiceSide(int upSide, int frontSide) {
		while (true) {
			if (upSide == num[0] && frontSide == num[1]) {
				break;
			}

			if (upSide == num[1]) {
				rollSouth();
			} else if (upSide == num[2]) {
				rollEast();
			} else if (upSide == num[3]) {
				rollWest();
			} else if (upSide == num[4]) {
				rollNorth();
			} else if (upSide == num[5]) {
				rollSouth();
				rollSouth();
			}
			if (frontSide == num[2]) {
				rollRight();
			} else if (frontSide == num[3]) {
				rollLeft();
			} else if (frontSide == num[4]) {
				rollRight();
				rollRight();
			}
		}
		System.out.println(num[2]);
	}

	void rollWest() {
		temp = num[0];
		num[0] = num[2];
		num[2] = num[5];
		num[5] = num[3];
		num[3] = temp;
	}

	void rollNorth() {
		temp = num[0];
		num[0] = num[1];
		num[1] = num[5];
		num[5] = num[4];
		num[4] = temp;
	}

	void rollEast() {
		temp = num[0];
		num[0] = num[3];
		num[3] = num[5];
		num[5] = num[2];
		num[2] = temp;
	}

	void rollSouth() {
		temp = num[0];
		num[0] = num[4];
		num[4] = num[5];
		num[5] = num[1];
		num[1] = temp;
	}

	void rollRight() {
		temp = num[1];
		num[1] = num[3];
		num[3] = num[4];
		num[4] = num[2];
		num[2] = temp;
	}

	void rollLeft() {
		temp = num[1];
		num[1] = num[2];
		num[2] = num[4];
		num[4] = num[3];
		num[3] = temp;
	}
}

Measured memory_bytes: 26240
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1){
                break;
            }else{
                if(m == -1 || f == -1){
                    System.out.println("F");
                }else if((m + f) >= 80){
                    System.out.println("A");
                }else if((m + f) >= 65 && (m + f) < 80){
                    System.out.println("B");
                }else if((m + f) >= 50 && (m + f) < 65){
                    System.out.println("C");
                }else if((m + f) >= 30 && (m + f) < 50){
                    if(r >= 50){
                        System.out.println("C");
                    }else{
                        System.out.println("D");
                    }
                }else if((m + f) < 30){
                    System.out.println("F");
                }
            }
        }
    }
}


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

int main() {
    int N,r=INF;
    cin >> N;

    rep(i,N+1) {
        int t1=i, t2=N-i, c=0;
        while(t1 != 0) {
            c += t1%6;
            t1 /= 6;
        }
        while(t2 != 0) {
            c += t2%9;
            t2 /= 9;
        }
        r = min(r,c);
    }
    cout << r << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
p=list(map(int,input().split()))
class UnionFind:
    #def   -> foo=UnionFind(n,1)  <- 1-based index, default is 0
    #method -> foo.hoge(huga)
    __slots__ = ["_size", "_first_idx", "_parents"]
    def __init__(self, size: int, first_index: int = 0) -> None:
        self._size = size
        self._first_idx = first_index
        self._parents = [-1] * (size + first_index)
    def find(self, x: int) -> int:
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]
    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)
    def unite(self, x: int, y: int) -> bool:
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x
        return True
    def size(self, x: int) -> int:
        return -self._parents[self.find(x)]
    def group_count(self) ->int:
        return sum(1 for i in  self._parents if i<0)-self._first_idx
    def connected(self) ->bool:
        return self._parents[self.find(self._first_idx)]==-self._size
uf=UnionFind(n,1)

for i in range(m):
    uf.unite(*map(int,input().split()))
print(len(tuple(1 for i in range(n) if uf.same(i+1,p[i]))))

Measured memory_bytes: 20344
#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int fact(int n){
  if(n == 0){
    return 1;
  }
  else{
    return n * fact(n-1);
  }
}
int getnum(vector<int> & s, int n){
  vector<int> elim;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int count = 0;
    for(const auto & x : elim){
      if(x < s[i]){
        count++;
      }
    }
    int dmy = (s[i] - 1 - count) * fact(n-i-1);
    ans += dmy;
    //cout << dmy << " (" << fact(n-1) << ") ";
    elim.push_back(s[i]);
  }
  return ans;
}
int main()
{
  int n;
  cin >> n;
  vector<int> p;
  vector<int> q;
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    p.push_back(x);
  }
  for(int i = 0; i < n; i++){
    int x;
    cin >> x;
    q.push_back(x);
  }
  int a = getnum(p, n);
  //cout << endl;
  int b = getnum(q, n);
  //cout << endl;
  //cout << a << " " << b;
  cout << abs(a - b);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int n;
long long tot=1,d[99001],e[99001],s=0;
int main()
{
	cin>>n;
	d[0]=e[0]=1;
	for(int i=1,x;i<=n;i++)
	{
		cin>>x;
		s+=x;
		tot=tot*3%mod;
		for(int j=i*301;j>=0;j--)
		{
			d[j]=(d[j]*2+d[max(0,j-x)])%mod;
			e[j]=(e[j]+e[max(0,j-x)])%mod;
		}
	}
	cout<<((tot+3*(e[(s+1)/2]-e[s/2+1]-d[(s+1)/2]))%mod+mod)%mod<<'\n';
}


Measured memory_bytes: 1664
#include <stdio.h>
#include <ctype.h>

int main(){
  char ch;

  while(1){
    scanf("%c",&ch);
    
    if(('A'<= ch) && (ch <='Z')) ch+=('a'-'A');
    else if(('a'<= ch) && (ch <='z')) ch-=('a'-'A');

    printf("%c",ch);
    if(ch=='\n') break;
  }

 
  return 0;
}

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

bool check(string s){
  //  文字数を確認
  if(s.size()<4 || s.size()>10){
    return false;
  }
  
  // 全ての文字を走査
  int index = 0;
  int uppercaseCount = 0;
  int cCount = 0;

  for (auto c : s){
    // 先頭文字が'A'か調べる
    if(index==0 && !(c=='A')){
      return false;
    }

    // 'C'を調べる
    if(index>=2 && index <=s.size()-2){
      if(c=='C'){
        cCount++;
      }
    }

    // 大文字の個数を調べる
    if(c>='A' &&c<='Z'){
      uppercaseCount++;
    }

    index++;
  }

  if(cCount!=1 || uppercaseCount!=2){
    return false;
  }

  return true;
}

int main(void){
  string S;
  cin >> S;
  bool result = check(S);
  if(result){
    cout << "AC" << endl;
  }else{
    cout << "WA" << endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		try (Stream<String> lines = new BufferedReader(new InputStreamReader(System.in)).lines()) {
			new Main().exec(lines.toArray(String[]::new));
		}
	}

	void exec(String[] args) {
		int S = Integer.parseInt(args[0].split(" ")[0]);
		BigInteger n = bi(0);
		for (int i = 1; i <= S / 3; i++) {
			n = n.add(c(S, i));
		}
		System.out.println(n.remainder(bi(10).pow(9).add(bi(7))));
	}

	BigInteger bi(int n) {
		return new BigInteger(String.valueOf(n));
	}

	BigInteger c(int s, int n) {
		int a = Math.min(s - 3 * n, n - 1);
		return f(s - 2 * n - 1, a).divide(f(a, a));
	}

	BigInteger f(int a, int b) {
		BigInteger n = bi(1);
		for (int i = 0; i < b; i++) {
			n = n.multiply(bi(a).subtract(bi(i)));
		}
		return n;
	}

}


Measured memory_bytes: 56896
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

long long  mod = 1000000007;

ll dp[210][10010];

int main(){
	int n,w;
	cin >> n >> w;
	VI v(n+1),s(n+1);	
	rep(i,n){
		cin >> v[i+1];
	}
	sort(v.begin(),v.end(),greater<int>());
	s[1] = v[1-1];
	for(int i=2;i<=n;i++){
		s[i] = s[i-1]+v[i-1];
	}
	dp[0][0] = 1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=w;j++){
			if(dp[i-1][j]==0)continue;
			if(w-j-(s[n]-s[i])>=v[i-1]){
				dp[i][j+v[i-1]] = (dp[i-1][j]+dp[i][j+v[i-1]])%mod;
			}else{
				dp[i][j] = (dp[i][j]+dp[i-1][j])%mod;
				if(j+v[i-1]<=w){
					dp[i][j+v[i-1]] = (dp[i][j+v[i-1]]+dp[i-1][j])%mod;
				}
			}
		}
	}
	ll ans = 0;
	rep(i,10001){
		ans = (ans+dp[n][i])%mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10512
import sys
def input(): return sys.stdin.readline().strip()
mod = 10**9+7

def main():
    L = input()
    l = len(L)
    """
    LについてbitDP、かつa, bは同じ桁に1, 1とならない
    """
    stoic = 2
    affordable = 1
    for i in range(1, l):
        if L[i] == '1':
            affordable = (stoic + affordable * 3) % mod
            stoic = (stoic * 2) % mod
        else:
            affordable = (affordable * 3) % mod

    print((stoic + affordable) % mod)







if __name__ == "__main__":
    main()


Measured memory_bytes: 39536
n, m = [int(x) for x in input().split()]

if n >= m:
    print(0)
    exit()

x_list = sorted([int(x) for x in input().split()])
gap_list = sorted([x_list[i] - x_list[i - 1] for i in range(1, m)], reverse=True)
print(sum(gap_list[(n - 1):]))

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

#define MAX 100

int N;
char S[MAX];

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

	int l = 0;
	int r = 0;
	for( int i = 0; i < N; i++ ) {
		if( S[i] == '(' ) {
			l++;
		}
		else {
			if( l > 0 ) {
				l--;
			}
			else {
				r++;
			}
		}
	}
	string str;
	for( int i = 0; i < r; i++ ) {
		str.push_back( '(' );
	}
	for( int i = 0; i < N; i++ ) {
		str.push_back( S[i] );
	}
	for( int i = 0; i < l; i++ ) {
		str.push_back( ')' );
	}

	cout << str << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

#define EPS 1e-12

int _h[100], *h = &_h[50];
int R, N;
bool f(double y, int x) {
	int xx = x < 0 ? x+1 : x;
	double yy = sqrt(R*R - xx*xx) + y - R;
	return yy <= h[x] + EPS;
}
bool f(double y) {
	for (int dx = 0; dx < R; ++dx) {
		if ( !f(y, dx) || !f(y, -dx-1) ) return false;
	}
	return true;
}
int main() {
	while (cin >> R >> N, R || N) {
		fill(&_h[0], &_h[0]+100, 0);
		for (int i = 0; i < N; ++i) {
			int l, r, y; cin >> l >> r >> y;
			for (int j = l; j < r; ++j) h[j] = max(h[j], y);
		}
		double l = 0, r = 20;
		for (int t = 0; t < 100; ++t) {
			double m = (l + r) / 2;
			if ( f(m) ) l = m;
			else r = m;
		}
		printf("%.10f\n", l);
	}
}

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

using namespace std;

typedef long long ll;

int main(){
  int n;
  while(cin >> n && n){
    vector<ll> P,J;
    ll sum = 0,ans;

    for(int i = 0; i < n; i++){
      ll in;
      cin >> in;
      sum += in;
      P.push_back(in);
    }

    ans = sum*n;

    for(int i = 0; i < n-1; i++){
      ll in;
      cin >> in;
      J.push_back(in);
    }

    sort(J.begin(),J.end());
    reverse(J.begin(),J.end());

    for(int i = 0; i < n-1; i++){
      sum += J[i];
      ans = max(ans,(n-i-1)*sum);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 2660
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 //   freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);
    int n;
    cin>>n;
    int v[n],c[n];
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    for(int i=0;i<n;i++)
    {
        int temper;
        cin>>temper;
        v[i]-=temper;
    }
    long long int ans =0;
    for(int i=0;i<n;i++)
    {
        if(v[i]>0)
            ans+=v[i];
    }
    cout<<ans;

    return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i], a[i]--;
  
  ll ans=0;
  rep(i,n){
    if(i<a[i]){
      if(i==a[a[i]]) ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<iostream>
#include<list>
#include<cstring>
#include<stack>
#include<string>
#include<vector>
#include<set>
using namespace std;
int main()
{
	int n, q;
	set<int> s1, s2;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		int tmp;
		scanf("%d", &tmp);
		s1.insert(tmp);
	}
	scanf("%d", &q);
	for (int i = 1; i <= q; i++)
	{
		int tmp;
		scanf("%d", &tmp);
		s2.insert(tmp);
	}
	int ans = 0;
	for(auto it=s1.begin();it!=s1.end();it++)
	{
		if (s2.find(*it) != s2.end())
			ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3224
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[1002],b[1002];
int main()
{
    int n,sum=0;
    scanf("%d",&n);
    int i;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    int ssum=0;
    for(i=1;i<=n;i++)
    {
        ssum+=a[i];
        b[i]=sum-ssum*2;
        if(b[i]<0)
            b[i]=0-b[i];
    }
    sort(b+1,b+1+n);
    printf("%d\n",b[1]);
    return 0;
}


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

int main(){ 
 int N, M, C;
 int ans=0;
  cin >> N >> M >> C;
 vector<int> B(M,0);
 for(int i=0; i<M; i++) cin>>B[i];
  
 for(int i=0; i<N; i++) {
   int sum=C;
  for(int i=0; i<M; i++) {
    int t; cin>>t; 
    sum += t*B[i] ;
  }
   if(sum>0) ans++;
 }
 cout << ans <<endl;
  return 0;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vp;
set<char> st;
string s;
int n,m,k;
int food[35];
int ans=0;
int main(int argc,char const* argv[])
{
  cin >> n >> m;
  memset(food,0,sizeof(food));
  for(int i=0;i<n;i++)
    {
      cin >> k;
      for(int j=0;j<k;j++)
	{
	  int a;
	  cin >> a;
	  a--;
	  food[a]++;
	}
    }
  for(int i=0;i<m;i++)
    {
      if(food[i]==n)
	{
	  ans++;
	}
    }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
a = list(map(lambda x:x//400, a))
a.sort()
tourist = 0
for i in range(n):
	if a[i]>=8:
		tourist = n-i
		break
min = len(set(a[:n-tourist]))
max = min + tourist
if min==0:
	min=1
print(min, max)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    int Mc = E;
    int Mp = 100 + E;

    int maxcc = 0, maxcp = 1;
    int aw, sw;

    for (int w = 0; 100 * A * w <= F; ++w) {
        int w0 = 100 * A * w;
        for (int x = 0; w0 + 100 * B * x <= F; ++x) {
            int w1 = 100 * B * x;
            for (int y = 0; w0 + w1 + C * y <= F; ++y) {
                int s0 = C * y;
                for (int z = 0; w0 + w1 + s0 + D * z <= F; ++z) {
                    int s1 = D * z;
                    if ((w0 + w1) == 0) continue;

                    int cc = s0 + s1;
                    int cp = w0 + w1 + s0 + s1;

                    if (cp * maxcc <= cc * maxcp && cc * Mp <= cp * Mc) {
                        maxcc = cc;
                        maxcp = cp;
                        aw = w0 + w1 + s0 + s1;
                        sw = s0 + s1;
                    }
                }
            }
        }
    }

    cout << aw << " " << sw << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
int main()
{
    int n;
    cin>>n;
    map<int,int> mp;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        mp[a]++;
    }
    int count=0;
    for(auto it=mp.begin();it!=mp.end();it++)
    {
        if(it->second-it->first>=0)
        {
            count+=it->second-it->first;
        }
        else count+=it->second;
    }
    cout<<count;
}

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


signed main(){
	int x,a,b;
	cin>>x>>a>>b;
	if(abs(x-a)<abs(x-b))cout<<"A"<<endl;
	else cout<<"B"<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>

#define FOR(n) for(int i=0;i<n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c\n",c)
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int main(void){
  int n,a,b;
  scanf("%d %d %d",&n,&a,&b);
  PRN(min(n*a,b));
  return 0;
}


Measured memory_bytes: 128
export class Main {
  static main(input: string): string {
    const tmp = input.split("\n");
    const [n, m] = tmp[0].split(" ").map(Number);
    if (n >= m) {
      return "0";
    }
    const xList = tmp[1].split(" ").slice(0, m).map(Number);
    xList.sort((a, b) => a-b);
    const diffList = [];
    for (let i = 0, len xList.length - 1; i < len; i++) {
      diffList.push(xList[i + 1] - xList[i]);
    }
    diffList.sort((a, b) => a-b);
    let tmp = 0;
    for (let i = 0, len = m - n; i < len; i++) {
      tmp += diffList[i];
    }
    return `${tmp}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

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

const int S = 100010;
const int INF = 1 << 30;
int N, K, L[S], R[S], P[S], ans[S];
bool valid;
vector<int> G[S];

void dfs(int p, int par=-1) {
    for(auto to : G[p]) {
        if(to == par) continue;
        dfs(to, p);
        L[p] = max(L[p], L[to] - 1);
        R[p] = min(R[p], R[to] + 1);
    }
}

void printans(int p, int val, int par=-1, int oe=-1) {
    if(oe < 0) oe = (val % 2);
    ans[p] = val;
    for(auto to : G[p]) {
        if(to == par) continue;
        int cur = val - 1;
        valid = false;
        for(int i=0; i<3; i++) {
            int nval = cur + i;
            if(oe != (nval % 2) && L[to] <= nval && nval <= R[to]) {
                valid = true;
                printans(to, nval, p, nval % 2);
                break;
            }
        }
        if(!valid) {
            cout << "No" << endl;
            exit(0);
        }
    }
}

int main() {
    for(int i=0; i<S; i++) {
        P[i] = -INF;
        L[i] = -INF;
        R[i] = INF;
    }

    cin >> N;
    for(int i=0; i<N-1; i++) {
        int a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int root = -1;
    cin >> K;
    for(int i=0; i<K; i++) {
        int v, p; cin >> v >> p; v--;
        L[v] = R[v] = P[v] = p;
        root = v;
    }

    dfs(root);
    
    for(int i=0; i<N; i++) {
        if((L[i] > R[i]) || (P[i] != -INF && (P[i] < L[i] || R[i] > P[i]))) {
            cout << "No" << endl;
            return 0;
        }
    }

    printans(root, L[root]);
    cout << "Yes" << endl;
    for(int i=0; i<N; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 15744
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	string s; cin>>s;
	(s=="ABC")?cout<<"ARC\n":cout<<"ABC\n";
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
ll n,ans;

int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			if(n/i==i+1)continue;
			if(n/i==i)continue;
			ans+=n/i-1;
		}
	}
	cout<<ans<<endl;
    return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		String s = scan.next();
		int b = scan.nextInt();
		char c = s.charAt(0);
		if (c == '+') {
			System.out.println(a+b);
		}
		else
		System.out.println(a-b);
	}
}


Measured memory_bytes: 21844
#! /usr/bin/env python
# -*- coding: utf-8 -*-

sN = []
sQ = []
dQ = []
Q = 0
N = 0


def gor(pos):
    for i in range(Q):
        if sN[pos] == sQ[i]:
            if dQ[i] == 'R':
                pos = pos + 1
            else:
                pos = pos - 1

            if pos < 0:
                return False
            if pos > N - 1:
                return True

    return False


def getr():
    l = 0
    r = N - 1
    res = N
    while r >= l:
        mid = (l + r) // 2
        if gor(mid):
            res = mid
            r = mid - 1
        else:
            l = mid + 1
    return res


def gol(pos):
    for i in range(Q):
        if sN[pos] == sQ[i]:
            if dQ[i] == 'L':
                pos = pos - 1
            else:
                pos = pos + 1

            if pos > N - 1:
                return False
            if pos < 0:
                return True

    return False


def getl():
    l = 0
    r = N - 1
    res = -1
    while l <= r:
        mid = (l + r) // 2
        if gol(mid):
            res = mid
            l = mid + 1
        else:
            r = mid - 1
    return res


if __name__ == '__main__':
    N, Q = map(int, input().split())  # N, Q for number

    sN = input()  # squares

    for i in range(0, Q):
        t, d = input().split()
        sQ.append(t)
        dQ.append(d)
        #sQ.append({'t': t, 'd': d})

    removed_l = getl() + 1
    removed_r = N - getr()

    print(N - removed_l - removed_r)


Measured memory_bytes: 85324
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n, a, b; cin >> n >> a >> b;
    puts((a-b)%2 ? "Borys" : "Alice");    
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 競プロ使い捨て
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Benri.StdIn.ReadStdInStr()[0];
            var m = n.Insert(4, " ");
            Console.WriteLine(m);
        }
    }

    public static class Benri
    {
        public static class StdIn
        {
            public static int[] ReadStdIn()
            {
                string[] str = Console.ReadLine().Split(' ');

                List<int> list = new List<int>();
                foreach (var s in str)
                {
                    try
                    {
                        list.Add(int.Parse(s));
                    }
                    catch
                    {
                        return null;
                    }
                }

                return list.ToArray();
            }

            public static string[] ReadStdInStr()
            {
                string[] str = Console.ReadLine().Split(' ');

                List<string> list = new List<string>();
                foreach (var s in str)
                {
                    try
                    {
                        list.Add(s);
                    }
                    catch
                    {
                        return null;
                    }
                }

                return list.ToArray();
            }
        }

        public static class Sort
        {
            public static void RadixSort(int[] array)
            {
                var bucket = new List<int>[256];

                for (int d = 0, logR = 0; d < 4; d++, logR += 8)
                {
                    for (int i = 0; i < array.Length; i++)
                    {
                        int key = (array[i] >> logR) & 255;

                        if (bucket[key] == null)
                        {
                            bucket[key] = new List<int>();
                        }
                        bucket[key].Add(array[i]);
                    }

                    for (int j = 0, i = 0; j < bucket.Length; j++)
                    {
                        if (bucket[j] != null)
                        {
                            foreach (int val in bucket[j])
                            {
                                array[i++] = val;
                            }
                        }
                    }

                    for (int j = 0; j < bucket.Length; j++)
                    {
                        bucket[j] = null;
                    }
                }
            }
        }
    }
}



Measured memory_bytes: 2648
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 
using namespace std;
int main()
{
    int n,m,a1,a2;
    while (~scanf("%d %d", &n,&m)) {
        a1 = 1;
        a2 = n;
        REP(i,1,m) {
            int x,y;
            scanf("%d %d",&x,&y);
            a1 = max(a1, x);
            a2 = min(a2, y);
        }
        printf("%d\n", max(0, a2-a1+1));
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int n;
  cin >> n;
  long long l[n+1];
  l[0] = 2; l[1] = 1;
  int i;
  for(i = 2;i <= n;++i){
    l[i] = l[i-1] + l[i-2];
  }
  cout << l[n] << endl;
  return 0;
}



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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

struct UnionFind
{
    int i;
    vector<int> par;
    vector<int> size;
    UnionFind(int n): par(n),size(n,1){
        for(i = 0;i < n;++i){
            par.at(i) = i;
        }
    }
    
    int root(int x){
        if(par.at(x) == x){
            return x;
        }else{
            return par.at(x) = root(par.at(x));
        }
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return;
        }else{
            if(size.at(rx) < size.at(ry)){
                swap(rx,ry);
            }
            par.at(ry) = rx;
            size.at(rx) += size.at(ry);
            return;
        }
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size.at(root(x));
    }
};

int main()
{
    ll i,j;
    ll n,m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<vector<ll>> graph(n);
    UnionFind uf(n);
    rep(i,m){
        ll x,y;
        cin >> x >> y;
        graph.at(x).push_back(y);
        graph.at(y).push_back(x);
        uf.unite(x, y);
    }
    vector<pair<ll,ll>> vp;
    rep(i,n){
        if(uf.root(i) == i){
            vp.emplace_back(uf.get_size(i), i);
        }
    }
    sort(all(vp), greater<pair<ll,ll>>());
    priority_queue<ll> pq;
    
    queue<ll> que;
    vector<ll> vdis(n,-1);
    ll top = vp[0].second;
    vdis.at(top) = 0;
    que.emplace(top);
    pq.emplace(-a[top]);
    while(!que.empty()){
        ll now = que.front();
        que.pop();
        for(i = 0;i < graph.at(now).size();++i){
            ll next = graph.at(now).at(i);
            if(vdis.at(next) == -1){
                vdis.at(next) = 0;
                que.emplace(next);
                pq.emplace(-a[next]);
            }
        }
    }
    ll ans = 0;
    for(i = 1;i < vp.size();++i){
        top = vp[i].second;
        vdis[top] = 0;
        priority_queue<ll> pq2;
        que.emplace(top);
        pq2.emplace(-a[top]);
        while(!que.empty()){
            ll now = que.front();
            que.pop();
            for(j = 0;j < graph.at(now).size();++j){
                ll next = graph.at(now).at(j);
                if(vdis.at(next) == -1){
                    vdis.at(next) = 0;
                    que.emplace(next);
                    pq2.emplace(-a[next]);
                }
            }
        }
        if(pq.empty()){
            cout << "Impossible" << endl;
            return 0;
        }else{
            ans += -pq.top() -pq2.top();
            pq.pop();
            pq2.pop();
            while(!pq2.empty()){
                pq.emplace(pq2.top());
                pq2.pop();
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 12672
n, a, b = map(int, input().split())
ans = 0
for i in range(1, n+1):
    str_i = str(i)
    sum_i = 0
    for j in range(len(str_i)):
        sum_i += int(str_i[j])
    
    if a <= sum_i and sum_i <= b:
        ans += i

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define PB push_back
#define SP << " " <<

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;

__attribute__((constructor))
void initial(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed <<setprecision(15);
}


int main(void){
	ll A, B, M;
    cin >> A >> B >> M;
    VL a, b, c, x, y;
    ll ans = INF;
    ll sum = 0;
    ll a_min = 100000;
    ll b_min = 100000;
    rep(i,A){
        ll a0;
        cin >> a0;
        a.PB(a0);
        chmin(a_min,a0);
    }
    rep(i,B){
        ll b0;
        cin >> b0;
        b.PB(b0);
        chmin(b_min,b0);
    }
    rep(i,M){
        ll x0, y0, c0;
        cin >> x0 >> y0 >> c0;
        x.PB(x0);
        y.PB(y0);
        c.PB(c0);
        sum = a[x0-1] + b[y0-1] -c0;
        chmin(ans,sum);
    }
    chmin(ans,a_min+b_min);


    cout << ans << endl;

    return 0;
}


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

int main() {
    ll n,m,d;
    cin >> n >> m>> d;
   
    long double ans = ((max(n-2*d,0LL)%n +n) *(m-1))/(long double)(n*n);
    cout << setprecision(10)<< ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 9e18;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  ll A,B,K;
  cin >> A >> B >> K;
  if(K <= A){
    cout << A-K << " " << B << endl;
  }else{
    if(K-A <= B){
      cout << 0 << " " << B - K + A << endl;
    }else{
      cout << 0 << " " << 0 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static			BufferedReader	br = null;
	private	static	final	int[]			AI = { 0, 90, 180, 270 };

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		char[][]	bd = parseBoard();

		showBoard(bd, 1);
		showBoard(bd, 2);
		showBoard(bd, 3);
	}
 
	private static void showBoard(char[][] bd, int ai) {
		System.out.println(AI[ai]);
		for (int i = 0; i < 8; i++) {
			String	out = "";
			for (int j = 0; j < 8; j++) {
				switch (ai) {
				case	1:
					out += bd[7-j][i];
					break;
				case	2:
					out += bd[7-i][7-j];
					break;
				case	3:
					out += bd[j][7-i];
					break;
				default:
					out += bd[i][j];
					break;
				}
			}
			System.out.println(out);
		}
	}

	private static char[][] parseBoard() {
		char[][]	bd = new char[8][];

		for (int i = 0; i < bd.length; i++) {
			bd[i] = parseStdin().toCharArray();
		}

		return bd;
	}

	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (!tmp.isEmpty()) stdin = tmp;
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

Measured memory_bytes: 16892
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

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

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int k, t;
  cin >> k >> t;
  int a[t];
  for(int i = 0; i < t; i++) cin >> a[i];

  int count = 0;
  int b = -1;
  for(int i = 0; i < k; i++){
    int m = -1;
    for(int j = 0; j < t; j++){
      if(j == b || a[j] <= 0) continue;
      if(m == -1 || a[m] <= a[j]) m = j;
    }
    if(m == -1){
      m = b;
      ++count;
    }
    a[m]--;
    b = m;
  }

  cout << count << endl;

  return 0;
}


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

using namespace std;

const int ms = 5e2 + 17;
char arr[ms][ms];
int x[] = {0, 0, 1, -1};
int y[] = {1, -1, 0, 0};

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

    int h, w;
    cin >> h >> w;

    for(int i = 0; i < h; ++i)
        for(int j = 0; j < w; ++j)
            cin >> arr[i][j];

    for(int i = 0; i < h; ++i)
    {
        for(int j = 0; j < w; ++j)
        {
            if(arr[i][j] == '#')
            {
                bool OK = false;

                for(int k = 0; k < 4; ++k)
                {
                    int xx = i + x[k], yy = j + y[k];

                    if(xx >= 0 && xx < h && yy < w && yy >= 0)
                    {
                        if(arr[xx][yy] == '#')
                            OK = true;
                    }
                }

                if(!OK)
                    return cout << "No\n", 0;

            }
        }
    }

    cout << "Yes\n";
}


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

int n,p[101],now,maxn;
bool c[101];
char s[101];

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>s[i];
	for(int i=1;i<=n;i++){
		if(c[i]) now--;
		if(s[i]=='0') continue;
		/*
		cout<<i-1<<": "<<now;
		for(int q=1;q<=n;q++) cout<<" "<<s[q];
		cout<<endl;
		*/
		for(int j=n;j>=i;j--){
			if(s[j]=='0') continue;
			if(i==j){
				s[i]='0';
				break;
			}
			if(s[i]==s[j]&&s[i]!='0'){
				now++;
				c[j]=1;
				s[j]='0';
				for(int r=j;r>i;r--){
					if(s[r]==s[i]) s[r]='0';
				}
				break;
			}
		}
		maxn=(maxn>now?maxn:now);
	}
	cout<<maxn<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

void solve(){
    int num,a,b;
    cin>>num>>a>>b;
    int ans=max(a,b)/num;
    ans-=((min(a,b)-1)/num);
    if(ans>0){
        out("OK");
        return;
    }else{
        out("NG");
    }

}

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

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

#define clr(arr,val) memset(arr,val ,sizeof arr)
//#define first f
//#define second s

typedef  long long ull;
typedef long long ll;
int const oo=(int)1e9 ;

int const SZ= (int)1e5+1;
//const ll mod=(ll)1e9+7;
int arr[SZ];
int dp[SZ];
int n,k;
//int mn=oo;
int solve(int i){
    
    if(i==n-1)
        return 0;
    if(i>=n)
        return oo;
    
    int &ret=dp[i];
    
    if(ret!=-1)
        return ret;
    ret=oo;
    for(int j=1 ;j<=k ;j++){
        int ch1=abs(arr[i]-arr[i+j])+solve(i+j);
        ret=min(ret,ch1);
        
    }
    return ret;
    
}
int main() {
//    int t ;
//    cin>>t;
//    while(t--){
        cin>>n>>k;
        for(int i=0 ;i<n ;i++)
                  cin>>arr[i];
        clr(dp,-1);
        cout<<solve(0)<<endl;
//    }
    return 0;
}

Measured memory_bytes: 12064
#include <unistd.h>
#include <stdlib.h>

char    *create_array(char *s, char *new_arr, char *t, int size)
{
	int i;
	int j;

	i = -1;
	while (s[++i])
		new_arr[i] = s[i];
	free(s);
	j = 0;
	while (j < size)
		new_arr[i++] = t[j++];   
	new_arr[i] = 0;
	return (new_arr);
}

char    *get_data(char *s)
{
	int     size;
	int     sum_size;
	char    t[1000];
	char    *new_arr;

	sum_size = 0;
	while ((size = read(0, t, 1000)))
	{
		if (size == -1)
			return (NULL);
		sum_size += size;
		if (!(new_arr = (char*)malloc(sum_size + 1)))
			return (NULL);
		s = create_array(s, new_arr, t, size);
	}
	return (s);
}

void    write_num(int num)
{
	char c;

	if (num < 10)
	{
		c = num + '0';
		write(1, &c, 1);
	}
	else
	{
		write_num(num / 10);
		write_num(num % 10);
	}
}

int     get_num(char *s, int num, int pass_flag, int count)
{
	int i;

	i = 0;
	while (count++ < pass_flag)
		while (s[i++] != 10)
			;
	num = 0;
	while ('0' <= s[i] && s[i] <= '9')
		num = num * 10 + s[i++] - '0';
	return (num);
}

char    *get_string(char *tmp, int pass_flag, int count)
{
	int     i;
	int     j;
	int     k;
	char    *new_arr;

	i = 0;
	while (count++ < pass_flag)
		while (tmp[i++] != 10)
			;
	j = 0;
	while (31 < tmp[i + j] && tmp[i + j] < 127)
		j++;
	new_arr = (char*)malloc(j + 1);
	k = -1;
	while (++k < j)
		new_arr[k] = tmp[i + k];
	new_arr[k] = 0;
	return (new_arr);
}

char    **get_strings(char *tmp, int pass_flag, int size)
{
	int     i;
	int     j;
	int     count;
	char    **new_arr;

	new_arr = (char**)malloc(sizeof(char*) * (size + 1));
	count = 0;
	i = 0;
	while (count++ < pass_flag)
		while (tmp[i++] != 10)
			;
	j = -1;
	while (++j < size)
		new_arr[j] = get_string(&tmp[i], j, 0);
	new_arr[j] = 0;
	return (new_arr);
}

void    all_free(int blue_num, char **blue, int red_num, char **red)
{
	int i;

	i = -1;
	while (++i < blue_num)
		free(blue[i]);
	i = -1;
	while (++i < red_num)
		free(red[i]);
	free(blue);
	free(red);
}

int     ft_strcmp(char *s1, char *s2)
{
        while (*s1++ == *s2++)
                if (!*s1 && !*s2)
                        return (0);
        return (*(s1 - 1) - *(s2 - 1));
}

void    get_ans(int blue_num, char **blue, int red_num, char **red)
{
	int i;
	int j;
	int max;
	int count;

	max = 0;
	i = -1;
	while (++i < blue_num)
	{
		count = 1;
		j = i;
		while (++j < blue_num)
			if (!(ft_strcmp(blue[i], blue[j])))
				count++;
		j = -1;
		while (++j < red_num)
			if (!(ft_strcmp(blue[i], red[j])))
				count--;
		if (max < count)
			max = count;
	}
	write_num(max);
}

int     main(void)
{
	char    *s;
	int     blue_num;
	char    **blue;
	int     red_num;
	char    **red;

	s = malloc(1);
	s = get_data(s);
	blue_num = get_num(s, blue_num, 0, 0);
	blue = get_strings(s, 1, blue_num);
	red_num = get_num(s, red_num, blue_num + 1, 0);
	red = get_strings(s, blue_num + 2, red_num);
	get_ans(blue_num, blue, red_num, red);
	free(s);
	all_free(blue_num, blue, red_num, red);
	return (0);
}


Measured memory_bytes: 128
package main
 
import (
	"fmt"
)
 
func main() {
	var h, a uint64
	fmt.Scanf("%d %d", &h, &a)
	type magicType struct {
		damage uint64
		mp uint64
	}
	magics := make([]magicType,a)
	var dp [1e4+1][1e4+1]uint64
    for i := uint64(0); i < a; i++ {
		_, err := fmt.Scanf("%d %d", &magics[i].damage, &magics[i].mp)
		if err != nil {
			break
		}
      for hp := uint64(1); hp <= h; hp++ {
			var cost uint64
			if hp < magics[i].damage {
				cost = magics[i].mp
			} else {
				cost = dp[i][hp - magics[i].damage] + magics[i].mp
			}
			if i == 0 || cost < dp[i - 1][hp] {
				dp[i][hp] = cost
			} else {
				dp[i][hp] = dp[i - 1][hp]
			}
		}
	}


	fmt.Printf("%v", dp[a - 1][h])
}

Measured memory_bytes: 107264
// A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
#include<string>
#include<math.h>
using namespace std;
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b))<EPS)

class Point {
public:
	double x, y;


	Point(double x = 0, double y = 0) :x(x), y(y) {}

	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double a) { return Point(a * x, a * y); }
	Point operator / (double a) { return Point(x / a, y / a); }

	double abs() { return sqrt(norm()); }
	double norm() { return x * x + y * y; };

	bool operator < (const Point& p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator ==(const Point& p)const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}

};

typedef Point Vector;

int main()
{
	const double pi = acos(-1);

	int a, b, h, m;

	cin >> a >> b >> h >> m;

	double longrad = 2 * pi * m / 60;
	double alpha = pi / 6 * m / 60;
	double shortrad = 2 * pi * h / 12;
	double rad;
	Vector v1 = Vector(b * cos(pi/2-longrad), b * sin(pi / 2-longrad));
	Vector v2 = Vector(a * cos(pi / 2-shortrad-alpha), a * sin(pi / 2-shortrad-alpha));

	Vector ansv = v2 - v1;
	
	double ans = ansv.abs();


	printf("%.12f", ans);

	return 0;

}


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

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

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

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

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

  string s;
  cin >> s;

  ll ans = 0;
  REP(i, s.size()){
    if(s[i] == '+')
      ans++;
    else
      ans--;
  }

  cout << ans << endl;
  
}


Measured memory_bytes: 256