akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    int n, m, k, tmp, ans;
    ans = 0;
    cin >> n >> m >> k;
    vector<ll> sum_a(n+1,0), sum_b(m+1, 0);
    rep(i,n){
        cin >> tmp;
        sum_a[i+1] = sum_a[i] + tmp;
    }
    rep(i,m){
        cin >> tmp;
        sum_b[i+1] = sum_b[i] + tmp;
    }
    auto lim_a = upper_bound(sum_a.begin(), sum_a.end(), k);
    for(auto itr_a = sum_a.begin(); itr_a != lim_a; itr_a++){
        int dist = int(--upper_bound(sum_b.begin(), sum_b.end(), k - *itr_a) - sum_b.begin() + itr_a - sum_a.begin());
        ans = max(dist, ans);
    }

    cout << ans << endl;

}

Measured memory_bytes: 6424
#include<stdio.h>
int main(void){
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(x>=r && y>=r && w-r>=x && h-r>=y){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int count = stdIn.nextInt();
		for(int i = 0;i < count;i++){
			int[] ball = new int[10];
			for(int j = 0;j < 10;j++){
				ball[j] = stdIn.nextInt();
			}
			int b = ball[0];
			int c = 0;
			String answer = null;
			for(int j = 1;j < ball.length;j++){
				if(ball[j] < b & ball[j] < c){
					answer = "NO";
					break;
				}
				if(b > c & ball[j] > b){
					b = ball[j];
				}else{
					c = ball[j];
				}
				if(j == ball.length - 1){
					answer = "YES";
				}
			}
			System.out.println(answer);
		}
	}
}

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


using namespace std;


int main(void){
    int n;
    cin>>n;
    
    int c[n+1],s[n+1],f[n+1];
    for(int i=0;i<n;i++){
        cin>>c[i]>>s[i]>>f[i];
    }
    c[n]=0;
    s[n]=0;
    f[n]=0;
    
    for(int i=0;i<n;i++){
        int sum=0;
        for(int j=i;j<n-1;j++){
            if(j==i){
                sum+=s[i]+c[i];
                //cout<<j<<sum<<endl;
            }else{
                if(sum<s[j]){
                    sum=s[j]+c[j];
                    //cout<<j<<sum<<endl;
                    continue;
                }
                if(sum%f[j]==0){
                    sum+=0+c[j];
                    //cout<<j<<sum<<endl;
                }else{
                    sum=((sum/f[j])+1)*f[j]+c[j];
                    //cout<<j<<sum<<endl;
                }
            }
        }
        if(i==n-1)cout<<"0"<<endl;
        else cout<<sum<<endl;
    }
}


Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int n,m;
  cin >> n >> m;
  if(n == m) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
int number(int const &n,int const &x)
{
	std::vector<std::vector<std::vector<int>>>v(n+1,std::vector<std::vector<int>>(3+1,std::vector<int>(x+1,0)));
	//v[p][q][r] means choose q numbers from {1,,,p} to make the sum equal to r;
	v[0][0][0] = 1;
	for(int q = 1 ; q <= 3 ; q ++){
		for(int r = 1 ; r <= x ; r ++){
			v[0][q][r] = 0;
		}
	}
	for(int p = 0 ; p <= n ; p ++){
		v[p][0][0] = 1;
		for(int q = 1 ; q <= 3 ; q ++){
			v[p][q][0] = 0;
		}
		for(int r = 1 ; r <= x ; r ++){
			v[p][0][r] = 0;
		}
	}

	for(int p = 1 ; p <= n ; p ++){
		for(int q = 1; q <= 3 ; q ++){
			for(int r = 1; r <= x ; r ++){
				v[p][q][r] += v[p-1][q][r];
				if(r - p >= 0) v[p][q][r] += v[p-1][q-1][r-p];
			}
		}
	}
	return v[n][3][x];
}



int main(int argc, char const *argv[])
{
	int n,x;
	while(std::cin>> n >> x){
		if(n == 0 && x == 0) break;
		std::cout << number(n,x) << std::endl;;
	}
	return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main()
{
	char s[4];
	scanf("%s",s);
	if(s[0]==s[1]&&s[0]==s[2]&&s[0]==s[3]){
		printf("No\n");
	}
	else if(s[0]==s[1]&&s[2]==s[3]||s[0]==s[2]&&s[1]==s[3]||s[0]==s[3]&&s[1]==s[2]){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1632
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}

int r,c;
string s[1003];
bool vis[1003][1003];
int dis[1003][1003];
inline bool chk(int x,int y)
{
    if(x>=0 && x<r && y>=0 && y<c)return true;
    else return false;
}
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};

 main()

{
    fast
    cin>>r>>c;
    queue<pi>q;
    int ses=1;
    f(i,0,r-1)
    {
        cin>>s[i];
        f(j,0,c-1)
        {
            if(s[i][j]=='#')
            {
                q.push(mp(i,j));
                vis[i][j]=1;
                dis[i][j]=1;
            }
        }
    }
    while(!q.empty())
    {
        int x=q.front().fi;
        int y=q.front().si;
        q.pop();
        f(k,0,3)
        {
            int nx=x+dx[k];
            int ny=y+dy[k];
            if(!chk(nx,ny))continue;
            if(vis[nx][ny])continue;
            vis[nx][ny]=1;
            q.push(mp(nx,ny));
            dis[nx][ny]=dis[x][y]+1;
            ses=max(ses,dis[nx][ny]);
        }
    }
    cout<<ses-1<<endl;
    return 0;

}





































Measured memory_bytes: 29624
public class Main {
	public static void main(String[] args) {
		    java.util.Scanner scanner = new java.util.Scanner(System.in);
		    int x = scanner.nextInt();
		    int y = scanner.nextInt();
		    int z = scanner.nextInt();
		    int n = (x - z) / (y + z);
		    System.out.println(n);
		 }

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a=0,n;
    bool s=true;
    string str;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> str;
        if(str=="A"){
            s=true;
            if(s){
                
            }
            else{
                if(a!=0){
                    cout << "NO"<< endl;
                    return 0;
                }
            }
            s=true;
            a++;
        }
        else{
            s=false;
            a--;
            if(a<0){
                cout << "NO"<< endl;
                return 0;
            }
        }
    }
    if(a==0){
        cout << "YES"<<endl;
    }
    else{
        cout << "NO"<<endl;
    }
    return 0;
    
    
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define fast_io ios::sync_with_stdio(false);cin.tie(NULL);
#define input freopen("Test.txt","r",stdin)
#define output freopen("Output.txt","w",stdout);
#define what_is(x) cout<<#x<<" is "<<x<<endl;
#define F(i,a,b) for(int i = a; i < b; i++)
#define MAX(a,b,c) max(a,max(b,c))
#define MIN(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define inf 1000000000
const double pi = 3.141592653589793238460;
#define debug false
#define MAXN 100010
#define mod 1000000007

void solve()
{
	ll a,b;
	cin>>a>>b;
	int g = __gcd(a,b);
	ll ans = 0;
	for(int i=1;i<=b;i++)
	{
		if((a*i)%b==0)
		{
			ans = a*i;
			break;
		}
	}
	cout<<ans<<"\n";
	
}

int main()
{
     // input; // output; // if(debug){watch_is();}
    fast_io;
    solve();   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
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;}

int main(){
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    string ans = "NG";
    for(int i = a; i <= b; i++){
        if(i%k == 0) ans = "OK";
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;
typedef pair<ll, ld> pld;
typedef pair<pii, int> ppiii;
typedef pair<pii, ll> ppiil;
typedef pair<pll, ll> pplll;
typedef pair<pli, int> pplii;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<pll>> vvpll;
#define rep(i, a, b) for (ll i=(a); i<(b); i++)
#define rrep(i, a, b) for (ll i=(a); i>(b); i--)
#define btoe(obj) (obj).begin(), (obj).end()
#define pb push_back
#define str to_string
#define mkp make_pair
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

void print(ld out) { cout << fixed << setprecision(12) << out << '\n'; }
template<typename T> void print(T out) { cout << out << '\n'; }
template<typename T1, typename T2> void print(pair<T1, T2> out) { cout << out.first << ' ' << out.second << '\n'; }
template<typename T> void print(vector<T> A) { rep(i, 0, A.size()) { cout << A[i]; cout << (i == A.size()-1 ? '\n' : ' '); } }
template<typename T> void print(set<T> S) { vector<T> A(S.begin(), S.end()); print(A); }

template<typename T> inline bool chmax(T &x, T y) { return (y > x) ? x = y, true : false; }
template<typename T> inline bool chmin(T &x, T y) { return (y < x) ? x = y, true : false; }

ll sum(vector<ll> A) { ll res = 0; for (ll a: A) res += a; return res; }
ll max(vector<ll> A) { ll res = -INF; for (ll a: A) chmax(res, a); return res; }
ll min(vector<ll> A) { ll res = INF; for (ll a: A) chmin(res, a); return res; }

ll toint(string s) { ll res = 0; for (char c : s) { res *= 10; res += (c - '0'); } return res; }
int toint(char c) { return c - '0'; }

inline ll pow(int x, ll n) { ll res = 1; rep(_, 0, n) res *= x; return res; }
inline ll pow(ll x, ll n, int mod) { ll res = 1; while (n > 0) { if (n & 1) { res = (res * x) % mod; } x = (x * x) % mod; n >>= 1; } return res; }

inline ll floor(ll a, ll b) { if (a < 0) { return (a-b+1) / b; } else { return a / b; } }
inline ll ceil(ll a, ll b) { if (a >= 0) { return (a+b-1) / b; } else { return a / b; } }

int popcount(ll S) { return __builtin_popcountll(S); }

ll N;
ll G[16][16];
ll dp[1<<16];

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

    cin >> N;
    rep(i, 0, N) rep(j, 0, N) cin >> G[i][j];
    
    // dp[S] := 集合Sのグループ分けを決めた時の最大値
    rep(S, 1, 1<<N) {
        // 集合S全てを同じグループとした場合を計算
        rep(i, 0, N) {
            rep(j, i+1, N) {
                if (S & (1<<i) && S & (1<<j)) {
                    dp[S] += G[i][j];
                }
            }
        }
        // 集合Sの部分集合の区切り方から、一番いいものを取る
        ll T = S;
        while (T > 0) {
            T = (T-1) & S;
            chmax(dp[S], dp[T] + dp[S^T]);
        }
    }
    ll ans = dp[(1<<N)-1];
    print(ans);
    return 0;
}


Measured memory_bytes: 896
import java.util.*
fun main(args:Array<String>) {
    val (D,N) = readLine()!!.split(" ").map(String::toInt)
    print(if(N==100) {N+1} else {N})
    
    0.until(D).map{it -> "00"}.forEach(::print)
    println()
}
 

Measured memory_bytes: 37872
from collections import defaultdict, deque
def main():
  N, M, *L = map(int, open(0).read().split())
  dic = defaultdict(list)
  par =  [0]*N
  cnt = [0]*N
  for a,b in zip(*[iter(L)]*2):
    dic[a-1] += [b-1]
    cnt[b-1] += 1

  for i in range(N):
    if cnt[i]==0:
      q = deque([i])
      par[i] = '0'
      break
  
  while q:
    m = q.popleft()
    for c in dic[m]:
      cnt[c] -= 1
      if cnt[c]==0:
        par[c] = str(m+1)
        q += [c]

  ans = '\n'.join(par)
  print(ans)
  
if __name__== '__main__':
  main()


Measured memory_bytes: 43508
#include<bits/stdc++.h>
using namespace std;
long long x[1000005],look[100005];
long long gcd(long long a,long long b)
{
	long long t=b;
	if(a%b==0)
	{
		return t;
	}
	else
	{
		return gcd(t,a%b);		
	}
}
int main()
{
	long long n,m;
	cin>>n>>m;
	long long a=gcd(n,m);
	long long ans=0;
	long long s=0;
	for(int i=2;i<=1000005;i++)
	{
		if(x[i]==0)
		{
			long long j=i*2;
			while(j<=1000000)
			{
				x[j]=1;
				j+=i;
			}
			s++;
			look[s]=i;
		}
	}
	for(int i=1;i<=s;i++)
	{
		if(a%look[i]==0)
		{
			ans++;
		}
		while(a%look[i]==0)
		{
			a=a/look[i];
		}
	}
	if(a!=1)
	{
		ans++;
	}
	cout<<ans+1;
	return 0;
}

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,sum;
  cin >> N;
  sum = 0;
  for (int i=0; i < N; i++){
    int l,r;
    cin >> l >> r;
    sum = sum + (r-l) + 1;
  }
  cout << sum << endl;
}

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

using namespace std;

constexpr long long INF64 = 1e18;

class Graph {

  struct Edge {
    int src, dst;
    long long weight;
    Edge(int src, int dst, long long weight)
        : src(src), dst(dst), weight(weight) {}
  };

  std::vector<std::vector<Edge>> g;
  std::vector<long long> dist, prev;

  bool negative_cycle = false;

  int flag = -1;

  void BellmanFord(int s) {
    const int n = g.size();
    dist[s] = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < n; ++j) {
        for (auto e : g[j]) {
          if (dist[e.src] != INF64 && dist[e.dst] > dist[e.src] + e.weight) {
            dist[e.dst] = dist[e.src] + e.weight;
            prev[e.dst] = e.src;
            if (i == n - 1) {
              dist[e.dst] = -INF64;
              negative_cycle = true;
            }
          }
        }
      }
    }
    flag = s;
  }

public:
  Graph(int n) : g(n), dist(n, INF64), prev(n, -1) {}

  void addEdge(int s, int t, long long cost) { g[s].emplace_back(s, t, cost); }

  long long getCost(int s, int t) {
    if (flag != s) {
      BellmanFord(s);
    }
    return dist[t];
  }

  std::vector<int> getPath(int s, int t) {
    if (flag != s) {
      BellmanFord(s);
    }
    assert(dist[t] != -INF64);
    std::vector<int> path;
    for (; t != -2; t = prev[t]) {
      path.push_back(t);
    }
    std::reverse(path.begin(), path.end());
    return path;
  }

  bool getNegativeCycle(){return negative_cycle;}
};

int main(){
    int n,m,s;
    cin>>n>>m>>s;
    Graph g(n);
    for(int i=0;i<m;++i){
        int from,to;
        long long weight;
        cin>>from>>to;
        cin>>weight;
        g.addEdge(from,to,weight);
    }
    for(int i=0;i<n;++i){
        long long ans=g.getCost(s,i);
        if(g.getNegativeCycle()){
            cout<<"NEGATIVE CYCLE"<<endl;
            return 0;
        }
        if(ans==INF64)cout<<"INF"<<endl;
        else cout<<ans<<endl;
    }
}
        


Measured memory_bytes: 3180
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

int n;
//int data[1e5 + 5];
map<int,int> first;
map<int,int> cnt;
set<int> numbers;
long long res[100005];

int main(){
    scanf("%d", &n);
    for(int i=1;i<=n;++i){
        int tmp;
        scanf("%d", &tmp);
        if(first[tmp]==0){
            first[tmp]=i;
        }
        cnt[tmp]++;
        numbers.insert(tmp);
    }
    for(auto it=numbers.rbegin();;){
        int a = *(it++);
        if(it==numbers.rend()){
            res[first[a]]+=((long long)cnt[a])*a;
            break;
        }
        int b = *it;
        res[first[a]]+=((long long)cnt[a])*(a-b);
        first[b]=min(first[b], first[a]);
        cnt[b]+=cnt[a];
    }
    for(int i=1;i<=n;++i){
        printf("%lld\n", res[i]);
    }
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10; 
int R[N],L[N];
int cnt[N];
char s[N];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1),pos=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='R')pos=i;
		R[i]=pos;
	}
	pos=n;
	for(int i=n;i>=1;i--){
		if(s[i]=='L')pos=i;
		L[i]=pos;
	}
	for(int i=1,step;i<=n;i++){
		if(s[i]=='L'){
			step=i-R[i];
			cnt[R[i]+step%2]++;
		}
		else{
			step=L[i]-i;
			cnt[L[i]-step%2]++;
		}
	}
	for(int i=1;i<=n;i++)printf("%d ",cnt[i]);
}

Measured memory_bytes: 1664
from collections import defaultdict
N=int(input())
S=input()
A=S[:N]
B=S[N:]
B=B[::-1]
def f(A):
    dd=defaultdict(int)
    for i in range(1<<N):
        a=''
        b=''
        for j in range(N):
            if i&(1<<j):
                a+=A[j]
            else:
                b+=A[j]
        dd[(a,b)]+=1
    return dd
dd1=f(A)
dd2=f(B)
ans=0
for t,c in dd1.items():
    ans+=dd2[t]*c
print(ans)

Measured memory_bytes: 150488
#include<iostream>
#include<vector>
#define ll long long

using namespace std;

vector<vector<ll>> A(100,vector<ll>(100,0));
vector<vector<ll>> B(100,vector<ll>(100,0));
vector<vector<ll>> C(100,vector<ll>(100,0));

int main(){
  int n,m,l;
  cin >> n >> m >> l;
  for(int i=0;i < n;i++){
    for(int j=0;j < m;j++){
      cin >> A.at(i).at(j);
    }
  }
  for(int i=0;i < m;i++){
    for(int j=0;j < l;j++){
      cin >> B.at(i).at(j);
    }
  }

  for(int i=0;i < n;i++){
    for(int j=0;j < l;j++){
      for(int k=0;k < m;k++){
        C.at(i).at(j) += A.at(i).at(k)*B.at(k).at(j);
      }
    }
  }

  for(int i=0;i < n;i++){
    for(int j=0;j < l;j++){
      cout << C.at(i).at(j);
      if(j == l-1) cout << endl;
      else cout << " ";
    }
  }

  return 0;
}


Measured memory_bytes: 3296
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

using namespace std;

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

    int aa = a * 2 - 1;
    int ab = a + b;
    int bb = b * 2 - 1;

    cout << max(aa, max(ab, bb)) << endl;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(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) long long(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>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n;
ll dist[305][305];
bool flg[305][305];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n;
  rep(i,n) rep(j,n) cin>>dist[i][j];
  
  rep(k,n){
    rep(i,n){
      rep(j,n){
        if(dist[i][j]>dist[i][k]+dist[k][j]){
          cout<<-1<<endl;
          return 0;
        }
        // dist[i][k] && dist[k][j] この条件がないと全ての辺のflgがtrueとなってしまう
        // 例えばi==0,k==0の場合を考えると、dist[0][0]+dist[0][j]のとき全てのi,jの組について成り立ってしまう
        // つまり、dist[x][x]となる場合を除外するために、この条件は必要である
        if(dist[i][j]==dist[i][k]+dist[k][j] && dist[i][k] && dist[k][j]) flg[i][j]=true;
      }
    }
  }
  
  ll ans=0;
  rep(i,n){
    rep(j,n){
      if(!flg[i][j]) ans+=dist[i][j];
    }
  }
  cout<<ans/2<<endl;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

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


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

  vector<int> a(N+1);
  vector<bool> v(N+1,false);
  REP(i,N)cin>>a[i+1];

  int t=1;
  int ans=0;
  while(t!=2 && v[t] == false){
    v[t] = true;
    t=a[t];
    ans++;
  }

  if(t==2){
    cout << ans << endl;
  }else{
    cout << -1 << endl;
  }

}



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

using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define lp(i, a, b) for (int i=a;i<=(int)b;++i)
#define lp2(i, a, b) for (ll i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vs vector<string>
#define vii vector<pii>
#define vll vector<pll>
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define clr(c, x) memset(c,x,sizeof(c));
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int N = (int) 1e5 + 5, INF = 0x3f3f3f3f, ALPHA = 26;
const ll mod = 998244353;
deque<int> v, ans;
ll fans = 0;

inline void solve(bool q) {
    while ((q ? v : ans).size() > 1) {
        int a1 = (q ? v : ans).front();
        (q ? v : ans).pop_front();
        int a2 = (q ? v : ans).front();
        (q ? v : ans).pop_front();
        int d = a1 + a2;
        if (d >= 10) {
            (q ? v : ans).pf(d % 10);
            (q ? v : ans).pf(d / 10);
        } else
            (q ? v : ans).pf(d);
        ++fans;
    }
    if (q && !v.empty()) ans.pb(v.front());
    v.clear();
}

int main() {
#ifdef ONLINE_JUDGE
    FAST;
#endif
    int n;
    cin >> n;
    while (n--) {
        int d;
        ll c;
        cin >> d >> c;
        while (c) {
            if (c % 2) v.pf(d);
            c /= 2;
            d *= 2;
            ll steps = 1;
            if (d >= 10) {
                steps++;
                int a1 = d % 10;
                int a2 = d / 10;
                d = a1 + a2;
            }
            fans += (c * steps);
        }
        solve(1);
    }
    solve(0);
    cout << fans << "\n";
    return 0;
}

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

using namespace std;
typedef long long ll;
char p[100005];

int main()
{
ll a,b,c,d,e,f,g=0,h;
cin>>a>>b>>c;
g=min(a,c);
c=c-g;
h=min(c,b);
g+=h*2;
if(c-h>0)
    g++;
else
    g+=b-h;
cout<<g;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll A[100][100];
ll B[100][100];
ll C[100][100];
bool DP[100][100][26200];
#define M 13100
#define Low -13000
#define High 13000

int main(){
    ll H, W;
    cin >> H >> W;
    REP(i,H){
        REP(j,W){
            cin >> A[i][j];
        }
    }
    REP(i,H){
        REP(j,W){
            cin >> B[i][j];
            C[i][j] = abs(A[i][j] - B[i][j]);
        }
    }

    DP[0][0][M-C[0][0]] = true;
    DP[0][0][M+C[0][0]] = true;
    REPi(x,1,W){
        ll c = C[0][x];
        for(int k = Low; k <= High; k++){
            chmax(DP[0][x][M+k+c], DP[0][x-1][M+k]);
            chmax(DP[0][x][M+k-c], DP[0][x-1][M+k]);
        }
    }

    REPi(y,1,H){
        REP(x,W){
            ll c = C[y][x];
            if(x == 0){
                for(int k = Low; k <= High; k++){
                    chmax(DP[y][x][M+k+c], DP[y-1][x][M+k]);
                    chmax(DP[y][x][M+k-c], DP[y-1][x][M+k]);
                }
            }
            else{
                for(int k = Low; k <= High; k++){
                    chmax(DP[y][x][M+k+c], DP[y-1][x][M+k]);
                    chmax(DP[y][x][M+k-c], DP[y-1][x][M+k]);
                    chmax(DP[y][x][M+k+c], DP[y][x-1][M+k]);
                    chmax(DP[y][x][M+k-c], DP[y][x-1][M+k]);
                }
            }
        }
    }

    ll ans = 1e10;
    for(int k = Low; k <= High; k++){
        if(DP[H-1][W-1][M+k])
            chmin(ans, (ll)abs(k));
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 205952
from collections import deque
import bisect
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
ans = int(0)

N = I()
color = []
a = I()
maxcolor =deque()
maxcolor.append(a)
lena = 1
for i in range(N-1):
    minmaxcolor = maxcolor[0]
    a = I()
    if a<=minmaxcolor:
        maxcolor.appendleft(a)
#        maxcolor.append(a)
        lena += 1
    else:
        acandi = bisect.bisect_left(maxcolor, a)
        maxcolor[acandi-1] = a
        """
        aupper = lena-1
        alower = int(0)
        acandi = aupper//2
        
        for _ in range(aupper+1):
            if maxcolor[acandi]>=a:
                alower = acandi
                acandi = (aupper+acandi+1)//2
            else:
                if aupper - alower <= 1:
                    maxcolor[acandi] = a
                    break
                else:
                    aupper = acandi
                    acandi = (acandi + alower) // 2
        """

#print(maxcolor)
ans = len(maxcolor)
print(ans)



Measured memory_bytes: 43484
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
lst = [0]*(n+1)
for x in range(1, 10**2+1):
    for y in range(1, 10**2+1):
        for z in range(1, 10**2+1):
            if 1 <= x**2 + y**2 + z**2 + x*y + y*z + z*x <= n:
                lst[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1
for i in range(1, n+1):
    print(lst[i])

Measured memory_bytes: 69072
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > a[100005],adj;
int n,m;
int f[100005],con[100005];
bool vis[100005];
void dfs(int v){
	vis[v]=true;
	con[v]+=f[v];
	for(int i=0;i<a[v].size();i++){
		int q=a[v][i].first;
		if(!vis[q]){
			dfs(q);
			con[v]+=con[q];
			if(con[q]%2!=0)
				swap(adj[a[v][i].second].first,adj[a[v][i].second].second);
		}
	}
}
int main (){
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
			f[u]++; 	
		a[u].push_back(make_pair(v,i));
		a[v].push_back(make_pair(u,i));	
		adj.push_back(make_pair(u,v));
	}
	if(m%2!=0){
		cout<<"-1";
		return 0;
	}
	dfs(1);
	for(int i=0;i<adj.size();i++){
		cout<<adj[i].first<<" "<<adj[i].second<<endl;
	}
}

Measured memory_bytes: 14708
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//s[i]-'0'で文字→数に;


int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  
  int sum = 0;
  rep(i,n) {
  sum+=s[i]-'0';
  }
  
  int x = stoi(s);
  
  cout << (x%sum==0?"Yes":"No") << endl;

}

Measured memory_bytes: 256
def main():
    N = int(input())
    word = []
    cnt = 0
    cnt_h = 0
    cnt_t = 0
    cnt_ht = 0
    total = 0
    for i in range(N):
        search = input()
        cnt += search.count('AB')
        if search[0] != 'B' and search[-1] !='A':
            continue
        elif search[0] =='B' and search[-1] =='A':
            cnt_ht +=1
        elif search[0] =='B':
            cnt_h +=1
        else:
            cnt_t +=1
    if cnt_ht ==0:
        print(cnt + min(cnt_h,cnt_t))
    elif cnt_t + cnt_h ==0:
        print(cnt + cnt_ht -1)
    else:
        print(cnt + min(cnt_h,cnt_t)+ cnt_ht)
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define eps 1e-7
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
#define int ll
const bool debug = 0;
using pii = pair<int, int>;
typedef long double D;

int32_t main()
{
    usecppio
    int n, m; cin >> n >> m;
    if (n%2==1)
    {
        for (int i = 1; i<=m; i++)
            cout << i << ' ' << n-i << '\n';
    }
    else
    {
        int odd = (m+1)/2;
        for (int i = 1; i<=odd; i++)
            cout << i << ' ' << n-i+1 << '\n';
        for (int i = odd+1; i<=m; i++)
            cout << i << ' ' << n-i << '\n';
    }
}

Measured memory_bytes: 3636
class Tree:
    def __init__(self):
        self.root = None
    
    def insert(self,x):
        z = Node(x)
        y = None
        x = self.root
        while x:
            y = x
            if z.data < x.data:
                x = x.left
            else:
                x = x.right
        z.parent = y
        if y == None:
            self.root = z
        elif z.data < y.data:
            y.left = z
        else:
            y.right = z

    def print(self):
        print('',' '.join(map(str,self.root.inwalk())))
        print('',' '.join(map(str,self.root.prewalk())))


class Node:
    def __init__(self,data):
        self.data = data
        self.parent = None
        self.left = None
        self.right = None

    def prewalk(self):
        ret = [self.data]
        if self.left:
            ret += self.left.prewalk()
        if self.right:
            ret += self.right.prewalk()
        return ret
    
    def inwalk(self):
        ret = []
        if self.left:
            ret += self.left.inwalk()
        ret += [self.data]
        if self.right:
            ret += self.right.inwalk()
        return ret

    
tree = Tree()
n = int(input())
for _ in range(n):
    input_line = input()
    if input_line[0] == 'i':
        tree.insert(int(input_line.split()[1]))
    else:
        tree.print()



Measured memory_bytes: 141448
N,M=map(int,input().split())

def primes(n):
    d=[]
    for i in range(1, int(n**0.5) + 1):
        if n%i==0:
            d.append(i)
            if n//i!=i:
                d.append(n//i)
    d.sort()
    return d

d=primes(M)

for i in d[::-1]:
    if M//i>=N:
        ans=i
        break

print(ans)


Measured memory_bytes: 9356
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string T;
  cin>>T;
  int N=T.size();
  int Q;
  cin>>Q;
  string S(N+2*Q,' ');
  for(int i=Q;i<=N+Q-1;++i) S[i]=T[i-Q];
  int cnt=0;
  int res=0;
 
  for(int i=0;i<Q;++i){
    int T;
    cin>>T;
    if(T==1) ++cnt;
    else{
      int F;
      cin>>F;
      char c;
      cin>>c;
      if(cnt%2==0 && F==1){
        S[Q-1-res]=c;
        ++res;
      }
      if(cnt%2==0 && F==2){
        S[N+Q+res]=c;
        ++res;
      }
      if(cnt%2!=0 && F==1){
        S[N+Q+res]=c;
        ++res;
      }
      if(cnt%2!=0 && F==2){
        S[Q-1-res]=c;
        ++res;
      }
    }
  }
 
  if(cnt%2==0){
    for(int i=0;i<N+2*Q;++i){
      if(S[i]!=' ') cout<<S[i];
    }
    cout<<endl;
  }
  else{
    for(int i=1;i<N+2*Q;++i){
      if(S[N+2*Q-i]!=' ') cout<<S[N+2*Q-i];
    }
    cout<<endl;
  }
 
}

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

map<long long, int> factorize(long long n) {
    map<long long, int> ret;
    for(long long i=2; i * i <= n; ++i) {
        while(n % i == 0) {
            ++ret[i];
            n /= i;
        }
    }
    if(n != 1) ret[n] = 1;
    return ret;
}

int main() {
    int n; cin >> n;
    auto tmp = factorize(n);
    vector<int> fac;
    for(auto p : tmp) fac.push_back(p.first);

    int res = 0;
    for(int i=0; i<(1 << fac.size()); ++i) {
        int div = 1, cnt = 0;
        for(int j=0; j<fac.size(); ++j) {
            if((i >> j) & 1) div *= fac[j], ++cnt;
        }
        res += (n / div) * (cnt & 1 ? -1 : 1);
    }
    cout << res << endl;
}


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


void solve(long long R){

    
    cout << 2*M_PI*R << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long R;
    scanf("%lld",&R);
    solve(R);
    return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int N;

void dfs(string s, char mx){
	if(s.length() == N){
		printf("%s\n", s.c_str());
	}
	else{
		for(char c = 'a'; c <= mx; c++){
			if(c == mx){
				dfs(s+c, char(mx + 1));
			}
			else{
				dfs(s+c, mx);
			}
		}
	}
}

int main(void){
	cin >> N;

	dfs("",'a');

	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 17;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}


mt19937 rnd(time(0));

struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};

/*
const int N = 1200000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    if (n<k) return 0;
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}
*/

/*

pair<int, int> solve1(ll l, ll r)
{
    int answer = 0;
    while (l>= answer+1 || r>=answer+1)
    {
        answer++;
        if (l>=r) l-=answer; else r-=answer;
    }
    //cout<<"Case #:"<<answer<<' '<<l<<' '<<r<<endl;
    return mp(l, r);
}*/

ll a, b, c, d;

map<ll, ll> ans;

ll solve(ll n)
{
    if (ans.find(n)!=ans.end()) return ans[n];
    if (n==0)
    {
        return 0;
    }
    if (n==1)
    {
        return d;
    }
    ll minn = 1e18;
    if (d<=minn/n) minn = min(minn, d*n);
    if (n%2==0) minn = min(minn, solve(n/2) + a);
    else
    {
        minn = min(minn, d*(n%2) + a + solve(n/2));
        minn = min(minn, d*(2 - n%2) + a + solve(1 + n/2));
    }

    if (n%3==0) minn = min(minn, solve(n/3) + b);
    else
    {
        minn = min(minn, d*(n%3) + b + solve(n/3));
        minn = min(minn, d*(3 - n%3) + b + solve(1 + n/3));
    }

    if (n%5==0) minn = min(minn, solve(n/5) + c);
    else
    {
        minn = min(minn, d*(n%5) + c + solve(n/5));
        minn = min(minn, d*(5 - n%5) + c + solve(1 + n/5));
    }

    ans[n] = minn;
    return minn;

}

void solve()
{
    ans.clear();
    ll n;
    cin>>n>>a>>b>>c>>d;
    cout<<solve(n)<<endl;
}

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

    int t;
    cin>>t;
    while(t--) solve();





}

/*
3821859835
9307855861

 */

Measured memory_bytes: 4432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
#define bit(k) (1LL<<(k))

int main(void){
    ll n;
    cin >> n;
    int m = 60;
    vector<ll> cnt(m);
    rep(i,n){
        ll a;
        cin >> a;
        rep(j,m){
            if (bit(j) & a) cnt[j]++;
        }
    }
    ll res = 0;
    ll MOD = 1e9+7;
    rep(i,m){
        res += ((cnt[i]*(n-cnt[i]))%MOD * (bit(i)%MOD))%MOD;
    }
    cout << res%MOD << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    ll x, y;
    while(cin>>x>>y){
        if(y==0){
            if(abs(x)==1) cout<<1<<endl;
            else cout<<abs(x)+abs(x)%2<<endl;
        }else if(abs(y)%2==0){
            cout<<abs(x)+abs(y)<<endl;
        }else{
            if(x==0 && y==1) cout<<1<<endl;
            else if(x==0) cout<<abs(y)+1<<endl;
            else if(abs(x)%2==0) cout<<abs(x)+abs(y)<<endl;
            else cout<<abs(x)+abs(y)-1<<endl;
        }
    }
    return 0;
}


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

int main(){
  int n, ans=0;
  cin >> n;
  vector<int> a(n), b(n), c(n-1);
  rep(i,n) cin >> a.at(i);
  rep(i,n) cin >> b.at(i);
  rep(i,n-1) cin >> c.at(i);
  ans += accumulate(b.begin(), b.end(), 0);
  rep(i,n-1){
   if(a.at(i)==a.at(i+1)-1) ans += c.at(a.at(i)-1); 
  }
  cout << ans;
}

Measured memory_bytes: 3524
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
using namespace std;
typedef long long li;
const li MAX = 100001;
li n, k, dp[MAX],a, take[MAX];

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> take[i];
	}
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (i >= take[j] && dp[i - take[j]] == 0) {
				dp[i] = 1;
			}
		}
	}
	if (dp[k])
	cout << "First";
	else cout << "Second";
//	system("pause");
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#define INF 1000000
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	while (cin >> n >> m, n | m)
	{
		string master[15], str[15];
		int num[15] = {};
		for (int i = 0; i < n; i++)
		{
			cin >> master[i];
			int pos = 0;
			while (master[i][pos] == '.')
			{
				num[i]++;
				pos++;
			}
		}
		for (int i = 0; i < m; i++)
			cin >> str[i];
		int R1[15] = {}, C1[15] = {}, S1[15] = {};
		int R2[15] = {}, C2[15] = {}, S2[15] = {};
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < master[i].size(); j++)
			{
				if (master[i][j] == '(')
					R1[i]++;
				if (master[i][j] == '{')
					C1[i]++;
				if (master[i][j] == '[')
					S1[i]++;
				if (master[i][j] == ')')
					R1[i]--;
				if (master[i][j] == '}')
					C1[i]--;
				if (master[i][j] == ']')
					S1[i]--;
			}
			R1[i + 1] = R1[i];
			C1[i + 1] = C1[i];
			S1[i + 1] = S1[i];
		}
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < str[i].size(); j++)
			{
				if (str[i][j] == '(')
					R2[i]++;
				if (str[i][j] == '{')
					C2[i]++;
				if (str[i][j] == '[')
					S2[i]++;
				if (str[i][j] == ')')
					R2[i]--;
				if (str[i][j] == '}')
					C2[i]--;
				if (str[i][j] == ']')
					S2[i]--;
			}
			R2[i + 1] = R2[i];
			C2[i + 1] = C2[i];
			S2[i + 1] = S2[i];
		}
		vector<int> vec(15, INF);
		vec[0] = 0;
		for (int r = 1; r <= 20; r++)
		{
			for (int c = 1; c <= 20; c++)
			{
				for (int s = 1; s <= 20; s++)
				{
					bool flag = true;
					for(int i = 0; i < n - 1; i++)
					{
						if (R1[i] * r + C1[i] * c + S1[i] * s != num[i + 1])
							flag = false;
					}
					if(flag)
					{
						for(int i = 0; i < m - 1; i++)
						{
							int tmp = R2[i] * r + C2[i] * c + S2[i] * s ;
							if(vec[i + 1] == -1 || vec[i + 1] == tmp)
								continue;
							if(vec[i + 1] != tmp && vec[i + 1] != INF)
								vec[i + 1] = -1;
							else
								vec[i + 1] = tmp;
						}
					}
				}	
			}
		}
		for(int i = 0; i < m; i++)
		{
			if(i == 0)
				cout << vec[i];
			else
				cout << " " << vec[i];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3188
using System;
using System.Linq;
 
class P{
  static void Main(){
    
    int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int W = n[0];
    int H = n[1];
    int N = n[2];
    int[] x = new int[N];
    int[] y = new int[N];
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      int[] m = Console.ReadLine().Split().Select(int.Parse).ToArray();
      x[i] = m[0];
      y[i] = m[1];
      a[i] = m[2];
    }
    
    int minX = 0, maxX = W, minY = 0, maxY = H;
    for(int i = 0; i < N; i++){
      if(a[i] == 1) minX = Math.Max(minX, x[i]);
      else if(a[i] == 2) maxX = Math.Min(maxX, x[i]);
      else if(a[i] == 3) minY = Math.Max(minY, y[i]);
      else maxY = Math.Min(maxY, y[i]);
    }
    
    int ans = maxX >= minX&&maxY >= minY ? (maxX - minX) * (maxY -minY) : 0;
    Console.WriteLine(ans);
    
  }
}

Measured memory_bytes: 13396
a,b,x=map(int,input().split())
import math
rec=a*a*b/2
if x==a*a*b:
    print(0)
    exit()
if x<=rec:
    c=x*2/a/b

    print(math.degrees(math.atan(b/c)))
else:
    x=a*a*b-x
    c=x*2/a/a
    print(90-math.degrees(math.atan(a/c)))


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

int main() {
	string odd, even;
	cin >> odd >> even;
	int len = odd.size() + even.size();
	for (int i = 0; i < len; i++) {
		if (i % 2 == 0) {
			cout << odd.at(i / 2);
		} else {
			cout << even.at(i / 2);
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int to, cost; };
int gcd(int a, int b) {
	if (!b)return a;
	return gcd(b, a%b);
}
signed main() {
	int t; cin >> t;
	rep(x, t) {
		int a, b, c, d; cin >> a >> b >> c >> d;
		if (b > a)cout << "No" << endl;
		else if (b > d)cout << "No" << endl;
		else if (b <= c)cout << "Yes" << endl;
		else {
			int G = gcd(b, d);
			a %= G;
			int l = b-(G-a)%G;
			if (l == b)l -= G;
			if (l > c)cout << "No" << endl;
			else cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n , W ,wt[102],v[102];
long long dp[102][100002];
int main()
{
    scanf("%d %d",&n,&W);
    for(int i=1;i<=n;i++){
        scanf("%d %d",&wt[i],&v[i]);
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=W;j++){
            if(i==0 || j==0){
                dp[i][j]=0;
            }
            else if(wt[i]<=j){
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wt[i]]+v[i]);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    printf("%lld",dp[n][W]);
    return 0;
}


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

int	main() {
	string s;
	cin >>s;
	vector<int> c(3, 0);
	for (int i=0; i<s.size(); i++) 
		c.at(s.at(i)-'a')++;
	sort(c.begin(), c.end());
	if (c.at(2)-c.at(0)<=1)
		cout <<"YES" <<endl;
	else
		cout <<"NO" <<endl;
	return 0;
};


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

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

    vector<vector<bool>> edge(N, vector<bool>(N, false));
    vector<int> P(N);

    for (int i = 0; i < M; i++) {
        int n, m;
        cin >> n >> m;
        edge[n-1][m-1] = true;
        edge[m-1][n-1] = true;
    }

    for (int i = 0; i < N; i++) {
        P[i] = i;
    }

    int count = 0;
    do {
        if (P[0] != 0) {
            break;
        }
        bool flag = true;
        for (int i = 0; i < N - 1; i++) {
            if (!edge[P[i]][P[i+1]]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            count++;
        }
    }while (next_permutation(P.begin(), P.end()));
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }
int clz(int x) { return 31 - __builtin_clz(x); }
int clz(ll x) { return 63 - __builtin_clzll(x); }
int ctz(int x) { return __builtin_ctz(x); }
int ctz(ll x) { return __builtin_ctzll(x); }

class compare {
public:
	bool operator()(tuple<ll, ll> a, tuple<ll, ll> b) {
		return (get<1>(a) > get<1>(b));
	}
};

ll dp[100002];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	rep(i,n+2)dp[i]=LINF;
	dp[0]=0;
	vl h(n);
	rep(i,n)cin>>h[i];
	range(i,1,n){
		if(i!=1)dp[i]=min(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
		dp[i]=min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792