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

//087D
public class Main {
	
	static int N, M, visited[];
	static long position[];
	static List<ArrayList<int[]>> to;
	static Queue<Integer> q;
	static long INF = Long.MAX_VALUE/2;
	static boolean out = false;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		N = sc.nextInt(); M = sc.nextInt();
		to = new ArrayList<ArrayList<int[]>>();
		for(int i=0;i<N;i++)to.add(new ArrayList<int[]>());
		for(int i=0;i<M;i++) {
			int L = sc.nextInt()-1, R = sc.nextInt()-1, D = sc.nextInt();
			int tmp[] = {R, D};
			int rtmp[] = {L, -D};
			to.get(L).add(tmp);
			to.get(R).add(rtmp);
		}
		sc.close();
		
		visited = new int[N];
		position = new long[N];
		Arrays.fill(position, INF);
		for(int i=0;i<N;i++) {
			if(visited[i]==1)continue;
			position[i]=0;
			dfs(i, -1);
			
		}
		if(!out) System.out.println("Yes");
	}
	
	
	static void dfs(int now, int parent) {
		if(out) return;
		visited[now]=1;
		List<int[]> nexts = (List<int[]>) to.get(now);
		for(int[] nextArr : nexts) {
			if(out) return;
			int next = nextArr[0];
			int nextDist = nextArr[1];
			if(next == parent)continue;
			if(position[next]==INF)position[next]=position[now]+nextDist;
			else if(position[next]!=position[now]+nextDist) {
				out = true;
				System.out.println("No");
				return;
			}
			if(visited[next]!=1) dfs(next, now);
		}
	}
	
	
}


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

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

a.sort() 

cnt2 = 0
cnt = 1
ans = 0
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        cnt += 1
    else:
        ans += cnt%2
        cnt = 1
        flg = False

ans += cnt%2
print(ans)

Measured memory_bytes: 7388
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  if (N % 2 != 0) {
    cout << "No" << endl;
    return 0;
  }
  for (int i=0; i<N/2; i++) {
    if (S[i] != S[N/2 + i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;
int n;
int a[55];
int main(void){
    cin>>n;
    int x=1;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        if(abs(a[x])<abs(a[i]))x=i;
    }
    cout<<2*n-2<<endl;
    for(int i=1;i<=n;i++)if(i!=x)cout<<x<<' '<<i<<endl;
    if(a[x]>0)for(int i=2;i<=n;i++)cout<<i-1<<' '<<i<<endl;
    else for(int i=n;i>1;i--)cout<<i<<' '<<i-1<<endl;
}


Measured memory_bytes: 256
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
    x = int(input())
    b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
    res = INF
    for S in [s[b - 1], s[b]]:
        for T in [t[d - 1], t[d]]:
            d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 13972
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

constexpr static int MAXN = 3e5;

int n, m;
string s;
vector <int> adj[MAXN];
int cnt[MAXN][2];
bool marked[MAXN];

void dfs(int i) {
    if (cnt[i][0] != 0 && cnt[i][1] != 0)
        return;
    marked[i] = true;
    for (int j : adj[i])
        if (j != i)
            cnt[j][s[i] - 'A']--;
    for (int j : adj[i])
        if (j != i && !marked[j])
            dfs(j);
}

int main() {
    cin >> n >> m;
    cin >> s;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        if (u == v) {
            adj[u].push_back(u);
            cnt[u][s[u] - 'A']++;
        }
        else {
            adj[u].push_back(v);
            adj[v].push_back(u);
            cnt[u][s[v] - 'A']++;
            cnt[v][s[u] - 'A']++;
        }
    }

    for (int i = 0; i < n; i++)
        if (!marked[i])
            dfs(i);

    bool found = false;
    for (int i = 0; i < n; i++)
        if (!marked[i])
            found = true;

    cout << (found ? "Yes" : "No") << endl;
}


Measured memory_bytes: 22788
package main
import (
  "fmt"
)
func max(a, b int)int {
  if a < b {
    return b
  }
  return a
}

func ceil(a, b int)int {
  if a%b == 0 {
    return a/b
  }
  return a/b + 1
}

func main() {
  var n int
  fmt.Scan(&n)
  ts := make([]int, n)
  as := make([]int, n)
  for i := 0; i < n; i++ {
    fmt.Scan(&ts[i], &as[i])
  }
  var totalT, totalA int
  for i := 0; i < n; i++ {
    t := ts[i]
    a := as[i]
    if totalA <= a && totalT <= t {
      totalT = t
      totalA = a
      continue
    }
    c := max(ceil(totalA, a), ceil(totalT, t))
    totalT = t*c
    totalA = a*c
  }
  result := totalT + totalA
  fmt.Println(result)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define f first
#define s second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector < vector <pii> > graph;

const int mod = 1e9;

signed main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   ll s;
   cin >> s;
   ll y = (3ll * mod - s % mod) % mod;
   ll x = (s + y) / mod;
   cout << 0 << ' ' << 0 << ' ' << 1 << ' ' << 1000000000 << ' ' << x << ' ' << y << '\n';
   return 0;
}


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

using namespace std;

int main(void)
{
  int N;
  cin >> N;
  string s;
  cin >> s;
  int red = 0;
  int blue = 0;
  for(int i = 0; i < N; i++){
    if(s[i] == 'R'){
      red++;
    }
    else{
      blue++;
    }
  }
  if(red > blue){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


n, k, s = LI()
a = []
for _ in range(k):
    a.append(s)
for _ in range(n - k):
    if s == 1:
        a.append(s + 1)
    else:
        a.append(s - 1)
print(*a)


Measured memory_bytes: 13924
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
int cnt[105];
int main()
{
     int n,k,i,j,c=0;
     cin>>n>>k;

     while(k--)
     {
         int di;
         cin>>di;
         for(i=0;i<di;i++)
         {
            int x;
            cin>>x;
            cnt[x]++;

         }
     }
     for(i=1;i<=n;i++)
     {
         if(cnt[i]==0)
         {
             c++;
         }
     }
     cout<<c;



}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)
using namespace std;

long long n, s;

long long f(long long x, long long b){
	if(b > x) return x;
	else return f(x / b, b) + x % b;
}

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> s;
	for(long long i = 2; i <= sqrt(n) + 1; i++)
		if(f(n, i) == s){
			cout << i << "\n";
			return 0;
		}
	for(long long i = sqrt(n) - 1; i > 0; i--){
		long long b = (n - s) / i + 1;
		if(b > 1 && f(n, b) == s){
			cout << b << "\n";
			return 0;
		}
	}
	if(n == s) cout << n + 1 << "\n";
	else cout << "-1\n";
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  ll k;
  cin >> k;

  map<int, int> a;
  rep(i, n) cin >> a[i + 1];

  vector<int> done(n + 1, -1);

  int i = 1;
  int cnt = 0;
  while (true) {
    if (cnt == k) {
      cout << i << endl;
      return 0;
    }
    if (done[i] >= 0) break;
    done[i] = cnt;
    cnt++;
    i = a[i];
  }

  int loop = cnt - done[i];

  k -= done[i];
  k %= loop;

  int ans = i;
  rep(j, k) ans = a[ans];

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 13520
#include <vector>
#include <set>
#include <map>
#include <string>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
#include <string.h>
#include <stdio.h>

typedef long long ll;
using namespace std;

typedef vector<vector<int>> graph_t;
const int INF = 1e9+1;

pair<int, int> solve(vector<tuple<int, int, int>> roads)
{
	graph_t g;
	const int N = 10;
	g.resize(N);
	for (int i = 0; i < N; i++) {
		g[i].resize(N, INF);
		g[i][i] = 0;
	}
	for (auto i = roads.begin(); i != roads.end(); ++i) {
		int s = get<0>(*i);
		int t = get<1>(*i);
		int d = get<2>(*i);
		g[s][t] = d;
		g[t][s] = d;
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++)
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		}
	}
	int ans = INF;
	int index = -1;
	for (int i = 0; i < N; i++) {
		int s = 0;
		for (int j = 0; j < N; j++) {
			if (i == j || g[i][j] >= INF)
				continue;
			s += g[i][j];
		}
		if (ans > s && s > 0) {
			ans = s;
			index = i;
		}
	}
	return make_pair(index, ans);
}

void solve_stdio()
{
	while (true) {
		int n;
		if (!(cin >> n))
			break;
		if (n == 0)
			break;
		vector<tuple<int, int, int>> roads;
		for (int i = 0; i < n; i++) {
			int s, t, d;
			cin >> s >> t >> d;
			roads.emplace_back(s, t, d);
		}
		int index;
		int ans;
		tie(index, ans) = solve(roads);
		cout << index << " " << ans << endl;
	}
}

int main()
{
	solve_stdio();
}


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

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

	for(int a=0; a<=N; a++)
		for(int b=0; b<=N-a; b++) {
			if (a * 10000 + b * 5000 + (N-a-b)*1000 == Y) {
				cout << a << " " << b << " " << (N-a-b) << '\n';
				goto Fin;
			}
		}
	cout << "-1 -1 -1 \n";
	Fin:
	return 0;
}

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


int main(){
	int label[7],check[7];
	cin >> label[1] >> label[2] >> label[3] >> label[4] >> label[5] >> label[6];
	cin >> check[1] >> check[2] >> check[3] >> check[4] >> check[5] >> check[6];

	bool o = false;
	for(int i = 0;i < 4;i++){
		if(check[1] == label[1]){
			for(int j = 0;j < 4;j++){
				if(label[2] == check[2] && label[3] == check[3] && label[4] == check[4] && label[5] == check[5]){
					cout << "Yes\n";
					o = true;
				}
				else{
					int tmp = check[4];
					check[4] = check[2];
					check[2] = check[3];
					check[3] = check[5];
					check[5] = tmp;
				}
				if(o)break;
			}
		}
		int tmp = check[1];
		check[1] = check[2];
		check[2] = check[6];
		check[6] = check[5];
		check[5] = tmp;
		if(o)break;
	}
	
	for(int i = 0;i < 4;i++){
		if(o)break;
		if(check[1] == label[1]){
			for(int j = 0;j < 4;j++){
				if(label[2] == check[2] && label[3] == check[3] && label[4] == check[4] && label[5] == check[5]){
					cout << "Yes\n";
					o = true;
				}
				else{
					int tmp = check[4];
					check[4] = check[2];
					check[2] = check[3];
					check[3] = check[5];
					check[5] = tmp;
				}
				if(o)break;
			}
		}
		int tmp = check[1];
		check[1] = check[3];
		check[3] = check[6];
		check[6] = check[4];
		check[4] = tmp;
		if(o)break;
	}
	if(!o) cout << "No\n";
	return 0;
}

Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define MAXM 1000
#define MAXN 12
#define INF 1000000000

int N, M, cost[MAXM + 3], dp[MAXM + 3][(1 << MAXN) + 3];
vector<int> adj[MAXM + 3];

/*
Min cost to unlock mask using keys idx..M-1
*/
int solve(int idx, int mask) {
    if (idx == M) {
        if (mask == 0)
            return 0;
        else
            return INF;
    }

    if (dp[idx][mask] != -1)
        return dp[idx][mask];

    int leave = solve(idx + 1, mask);

    int newMask = mask;
    for (auto id: adj[idx]) {
        if (newMask & (1 << id))
            newMask ^= (1 << id);
    }

    int take = cost[idx] + solve(idx + 1, newMask);

    return dp[idx][mask] = min(leave, take);
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int b;
        cin >> cost[i] >> b;
        for (int j = 0; j < b; j++) {
            int c;
            cin >> c;

            adj[i].push_back(c - 1);
        }
    }

    memset(dp, -1, sizeof(dp));

    int answer = solve(0, (1 << N) - 1);
    if (answer < INF)
        cout << answer << endl;
    else
        cout << -1 << endl;
}


Measured memory_bytes: 16512
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

int main() {
  ll n;
  cin>>n;
  n*=2;
  vector<ll> v;
  rep(i,0,n){
  	ll a;
  	cin>>a;
  	v.pb(a);
  }
  sort(all(v));
  ll ans = 0;
  rep(i,0,v.sz/2){
  	ans += v[i*2];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
typedef long long ll;
using namespace std;

int a[200010], cnt[200010]={};

int main() {
    int N;
    cin >> N;
    for(int i=0; i<N; ++i) cin >> a[i];
    ll ans=0;
    for(int i=N-1; i>=0; --i){
        if(i+a[i]<=N-2) ans += cnt[i+a[i]];
        if(i>a[i]) ++cnt[i-a[i]];
    }
    cout << ans << endl;
	return 0;
}


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

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

	const int inf = 1e9 + 5;

	int n;
	cin >> n;
	vector<int> h(n);

	for (int i = 0; i < n; i++)
		cin >> h[i];

	vector<int> dp(n, inf);
	dp[0] = 0;
	// dp[i] = min( dp[i - 1] + abs(h[i] - h[i-1]),  dp[i - 2] + abs(h[i] - h[i - 2]) )
	for (int i = 1; i < n; i++) {
		dp[i] = min( dp[i-1] + abs(h[i] - h[i - 1]), i > 1 ? dp[i - 2] + abs(h[i] - h[i - 2]) : inf);
	}

	cout << dp.back() << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#define ll long long
#define MOD 1000000007
using namespace std;

int main(){
    int n; cin >> n;
    vector<char> s(2*n); 
    vector<int> k(2*n);
    int j = 0;
    for(int i=0;i<2*n;i++){
        cin >> s[i];
        if((i % 2 == 1 && s[i] == 'B') || (i % 2 == 0 && s[i] == 'W')){
            k[j] = i - 2*j;
            j++;
        }
    }
  if( j != n ) cout  << 0;
  else{
    ll ans = 1;
    for(int i=0;i<j;i++){
        ans *= k[i];
        ans %= MOD;
    }
    for(int i=1;i<=n;i++){
      ans *= i;
      ans %= MOD;
    }
  cout << ans % MOD;
  }
    return 0;
}



Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
int inf = 1000000000;

int main(void) {
  int n;
  while(cin >> n){
    if( n == 0 ) break;
    vector< vector<int> > l(n+1, vector<int> (n+1, 0));
    for(int i=0; i<n; i++){
      int m;
      cin >> m;
      for(int j=0; j<m; j++){
        int tmp; cin >> tmp;
        l[i+1][tmp]++;
      }
    }
    int k; cin >> k;
    vector<int> d(k);
    for(int i=0; i<k; i++) cin >> d[i];
    vector<int> ans;
    for(int i=0; i<n; i++){
      bool f = true;
      for(int j=0; j<k; j++){
        if( l[i+1][d[j]] != 1 ) f = false;
      }
      if( f ) ans.push_back(i+1);
    }

    if( ans.size() != 1 ) cout << -1 << endl;
    else cout << ans[0] << endl;
  }

  return 0;
}

// EOF

Measured memory_bytes: 3200
#include<cstdio>
#include<list>
#define NMAX 10005
#define NUL -1
using namespace std;
short n;

struct Node{
    short parent;
    list<int> sub;
}nodes[NMAX];

void init(){//初始化父节点
    for(short i=0;i<n;i++)
        nodes[i].parent =NUL;
}

void unite(short a, short b){//合并
    short aParent = (nodes[a].parent==NUL)?a:nodes[a].parent;//a的父节点
    short bParent = (nodes[b].parent==NUL)?b:nodes[b].parent;//b的父节点
    if(aParent==bParent) return;//已属于同一集合
    nodes[bParent].parent = aParent;//b父节点指向a的父节点
    nodes[aParent].sub.push_front(bParent);//a父节点的子节点列表添加b父节点
    while(!nodes[bParent].sub.empty()){//将b父节点下的所有子节点移动到a父节点的子节点列表
        short firstNode = *(nodes[bParent].sub.begin());//a的父节点的子节点列表中的首节点
        nodes[aParent].sub.push_front(firstNode);//向b父节点的子节点列表添加该节点
        nodes[firstNode].parent = aParent;//更新该节点的父节点
        nodes[bParent].sub.pop_front();//清除已添加的节点
    }
}

bool same(short a, short b){//检验是否属于同一集合
    a = (nodes[a].parent==NUL)?a:nodes[a].parent;//a的父节点
    b = (nodes[b].parent==NUL)?b:nodes[b].parent;//b的父节点
    return a == b;//a的父节点不为空且a、b的父节点相同
}

int main(){
    int ope,t,a,b;
    scanf("%d%d", &n, &t);
    init();
    while(t--){
        scanf("%d%d%d", &ope, &a, &b);
        if(ope)
            printf("%d\n", same(a, b));
        else unite(a, b);
    }
    return 0;
}



Measured memory_bytes: 3344
//
//  main.cpp
//  Atcoder
//
//  Created by Keita on 2020/06/21.
//  Copyright © 2020 Keita. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;

void doProblemA(){
    char a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z;
    cin >> s;
    //>> a >> A >> b >> B >> c >> C >> d >> D >> e >> E >> f >> F >> g >> G >> h >> H >> i >> I >> j >> J >> k >> K >> l >> L >> m >> M >> n >> N >> o >> O >> p >> P >> q >> Q >> r >> R >> s >> S >> t >> T >> u >> U >> v >> V >> w >> W >> x >> X >> y >> Y >> z >> Z;
    if(s >= 'A' && s <= 'Z'){
  //if(isupper(s)){
       //α == a or α == b or α == c or α == d or α == e or α == f or α == g or α == h or α == i or α == j or α == k or α == l or α == m or α == n or α == o or α == p or α == q or α == r or α == s or α == t or α == u or α == v or α == w or α == x or α == y or α == z){
        cout << 'A' << endl;
    }else{
        cout << 'a' << endl;
    }
}

void doProblemB(){
    int N, K, i;
    cin >> N >> K;
    for(i=0; i < N; i++){
        
    }
}

int main(int argc, const char * argv[]) {
    // insert code here...
    doProblemA();
    return 0;
}

Measured memory_bytes: 3552
import itertools
from collections import Counter
n = int(input())
xy = [[int(x) for x in input().split()] for _ in range(n)]
vectors = []
for xy1, xy2 in itertools.combinations(xy,2):
    p = xy2[0] - xy1[0]
    q = xy2[1] - xy1[1]
    vectors.append((p, q))
    vectors.append((-p, -q))
c = Counter(vectors)
if n>=2:
    x = max(c.values())
    res = n - x
else:
    res = 1
print(res)

Measured memory_bytes: 39408
#include <iostream>

int main(){
    int n, k, h[200020], dp[200020];
    std::fill(h, h+200020, 0);
    std::fill(dp, dp+200020, 1e9);
    std::cin >> n >> k;
    for(int i = 0; i < n; i++){
        std::cin >> h[i];
    }
    dp[0] = 0;
    for(int i = 1; i < n; i++){
        for(int j = std::max(0, i-k); j < i; j++){
            dp[i] = std::min(dp[i], dp[j] + std::abs(h[i] - h[j]));
        }
    }
    std::cout << dp[n-1] << std::endl;
}


Measured memory_bytes: 1792
n = int(input())

frogs = list(map(int, input().split()))

dp = [0] * n

for i in range(n):
    if i == 0:
        dp[0] = 0
    elif i == 1:
        dp[1] = abs(frogs[0] - frogs[1])
    else:
        dp[i] = min(abs(frogs[i] - frogs[i-1]) + dp[i-1], abs(frogs[i] - frogs[i-2]) + dp[i-2])

# print(dp)
print(dp[-1])

Measured memory_bytes: 85068
while True:
    A = 0
    n, x = map(int, input().split())
    if n == x == 0:
        break
    for a in range(1,n+1):
        for b in range(a+1,n+1):
            for c in range(b+1, n+1):
                if a + b + c == x:
                    A += 1
    print(A)



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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

static const ll INF = 1e15;

const ll mod = 1000000007;


int main(void)
{
	int ids[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int k;
	cin >> k;
	k--;
	cout << ids[k] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using vi = vector<int64_t>;
using vvi = vector<vi>;
using ll = int64_t;
using P = pair<ll,ll>;
ll INF = 1000000007;
// ll INF = 9223372036854775807;
// ll INF = 998244353;

int main() {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    double a,b,h,m;
    double res = 0.0;
    cin >> a >> b >> h >> m;
    // a,bと角度から三角形の残りの辺の長さを出せばよい
    double htheta = 0.5*(h*60+m);
    double mtheta = 6.0*m;
    double theta = abs(htheta - mtheta);
    theta = min(theta, 360-theta);
    double pi = 2.0 * acos(0);
    res = sqrt(a*a + b*b - 2.0*a*b*cos(theta*pi/180.0));
    cout << setprecision(100) << res << endl;
}

Measured memory_bytes: 4244
N = int(input())
H = [int(x) for x in input().split()]
ans = 0
for i in range(N):
  mi = H[i]
  ans += mi
  for j in range(i+1,N):
    if mi<=H[j]:
      H[j] -=mi
    else:
      mi = min(mi,H[j])
      H[j]=0
print(ans)

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,M;
  cin >> N >> M;
  string S;
  cin >> S;

  bool flg1 = true;
  bool flg2 = true;
  bool flg3 = true;

  for(int i = 0; i < N; i++){
    if(S[i] >= '0' && S[i] <= '9'){

    } else { 
      flg1 = false;
      break;
    }
  }
  flg2 = (S[N] == '-' ? true : false);

  for(int i = N+1; i < N+M+1; i++){
    if(S[i] >= '0' && S[i] <= '9'){

    } else { 
      flg2 = false;
      break;
    }
  }

  cout << (flg1&&flg2&&flg3 ? "Yes" : "No") << endl; 

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fio ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int main(){
	fio;
	int s;
	cin>>s;
	int b=s%100,a=(s-b)/100;
	if(a<=12&&a>0&&b<=12&&b>0)cout<<"AMBIGUOUS";
	if(a<=12&&a>0&&(b>12||b==0))cout<<"MMYY";
	if((a>12||a==0)&&b<=12&&b>0)cout<<"YYMM";
	if((a>12||a==0)&&(b>12||b==0))cout<<"NA";
}

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

const int maxn = 2e5 + 10;
const ll inf = 1e18;
int h[maxn];
ll a[maxn];
ll DP[maxn];
int N;

struct maxtree{
    ll tree[maxn << 2];
    void build(int l , int r , int id){
        if(l == r){
            tree[id] = -inf;
        }
        else{
            int mid = (l + r) >> 1;
            build(l , mid , id << 1);
            build(mid + 1 , r , id << 1 | 1);
            tree[id] = max(tree[id << 1] , tree[id << 1 | 1]);
        }
    }
    void update(int l , int r , int pos , ll val , int id){
        if(l > r || pos < l || pos > r)return;
        if(l == r && l == pos){
            tree[id] = val;
            return;
        }
        int mid = (l + r) >> 1;
        if(pos <= mid){
            update(l , mid , pos , val , id << 1);
        }
        else{
            update(mid + 1 , r , pos , val , id << 1 | 1);
        }
        tree[id] = max(tree[id << 1] , tree[id << 1 | 1]);
    }
    ll query(int l , int r , int x , int y , int id){
        if(l <= x && y <= r){
            return tree[id];
        }
        int mid = (x + y) >> 1;
        if(mid < l){
            return query(l , r , mid + 1 , y , id << 1 | 1);
        }
        if(mid >= r){
            return query(l , r , x , mid , id << 1);
        }
        return max(
            query(l , r , x , mid , id << 1),
            query(l , r , mid + 1 , y , id << 1 | 1)
        );
    }

}T;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for(int i = 1; i <= N; ++i){
        cin >> h[i];
    }
    for(int i = 1; i <= N; ++i){
        cin >> a[i];
    }
    T.build(0 , N , 1);
    T.update(0 , N , 0 , DP[0] , 1);
    ll ret = 0;
    for(int i = 1; i <= N; ++i){
        DP[i] = T.query(0 , h[i] - 1 , 0 , N , 1) + a[i];
        ret = max(ret , DP[i]);
        T.update(0 , N , h[i] , DP[i] , 1);
    }
    cout << ret << endl;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double


ll modpower(ll a, ll r, ll mod){ //a^r
    ll x = 1;
    a %= mod;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

int main() {
    ll mod = 1e9+7;
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    
    multiset<pair<ll, ll>> mst;
    ll ans = 1;
    ll zero = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] == 0 && B[i] == 0) {
            zero++;
            continue;
        }
        ll g = gcd(abs(A[i]), abs(B[i]));
        A[i] /= g;
        B[i] /= g;
        if (A[i] < 0) {
            A[i] *= -1;
            B[i] *= -1;
        }
        mst.insert({A[i], B[i]});
    }
    
    while (!mst.empty()) {
        auto it = mst.begin();
        ll a = (*it).first, b = (*it).second;
        ll cnt_a = 1, cnt_b = 0;
        mst.erase(it);
        
        it = mst.lower_bound({a, b});
        while (it != mst.end() && (*it).first == a && (*it).second == b) {
            cnt_a++;
            it = mst.erase(it);
        }
        
        it = mst.lower_bound({-a, -b});
        while (it != mst.end() && (*it).first == -a && (*it).second == -b) {
            cnt_a++;
            it = mst.erase(it);
        }
        
        it = mst.lower_bound({b, -a});
        while (it != mst.end() && (*it).first == b && (*it).second == -a) {
            cnt_b++;
            it = mst.erase(it);
        }
        
        it = mst.lower_bound({-b, a});
        while (it != mst.end() && (*it).first == -b && (*it).second == a) {
            cnt_b++;
            it = mst.erase(it);
        }
        
        ans *= modpower(2, cnt_a, mod) + modpower(2, cnt_b, mod) - 1;
        ans %= mod;
    }
    cout << (ans+zero+mod-1) % mod << endl;
    return 0;
}


Measured memory_bytes: 18744
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

std::vector<size_t> make_vector(size_t n, size_t x) {
  return std::vector<size_t>(n, x);
}

template <class Tp>
std::vector<Tp> make_vector(size_t n, const Tp& x) {
  return std::vector<Tp>(n, x);
}

template <class... Ts>
auto make_vector(size_t n, size_t m, const Ts&... x) {
  return std::vector<decltype(make_vector(m, x...))>(n, make_vector(m, x...));
}

int main() {
  size_t N;
  scanf("%zu", &N);

  size_t x0 = 0;
  size_t y0 = 0;
  for (size_t i = 0; i < N; ++i) {
    int a;
    scanf("%d", &a);
    if (a <= 2) ++x0;
    if (a <= 1) ++y0;
  }

  auto dp = make_vector(N+1, N+1, N+1, 0.0);

  double n = N;
  for (size_t z = N+1; z-- > 0;) {
    for (size_t y = N+1; y-- > std::max(z, y0);) {
      for (size_t x = N+1; x-- > std::max(y, x0);) {
        if (x > 0)
          dp[x-1][y][z] += (dp[x][y][z] + (n / (n-z))) * (n-(x-1)) / (n-z);

        if (y > 0)
          dp[x][y-1][z] += (dp[x][y][z] + (n / (n-z))) * (x-(y-1)) / (n-z);

        if (z > 0)
          dp[x][y][z-1] += (dp[x][y][z] + (n / (n-(z-1)))) * (y-(z-1)) / (n-(z-1));
      }
    }
  }

  printf("%.12f\n", dp[x0][y0][0]);
}


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

#define int long long

typedef priority_queue<int, vector<int>, greater<int> > PQ;

signed main(){
    int w, h;
    cin >> w >> h;

    PQ yoko, tate;
    int a;
    for(int i = 0;i < w;i++){
        cin >> a;
        yoko.push(a);
    }

    for(int i = 0;i < h;i++){
        cin >> a;
        tate.push(a);
    }

    int ans = 0;
    h++;
    w++;
    while(!tate.empty() || !yoko.empty()){
        if(tate.empty()){
            ans += yoko.top() * h;
            w = max(w-1, 0ll);
            yoko.pop();
        }else if(yoko.empty()){
            ans += tate.top() * w;
            h = max(h-1, 0ll);
            tate.pop();
        }else{
            if(tate.top() < yoko.top()){
                ans += tate.top() * w;
                h = max(h-1, 0ll);
                tate.pop();
            }else{
                ans += yoko.top() * h;
                w = max(w-1, 0ll);
                yoko.pop();
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int n;
  cin >>n;
  vector<int> a(n);
  rep(i,n) cin>>a.at(i);
  int ma=0;
  int sum=0;
  rep(i,n) ma=max(ma,a.at(i));
  rep(i,n)sum+=a.at(i);
  sum -= ma;
  if(ma < sum) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

map<long long, bool> mp;
long long n;
long long p = 998244353;

void s(int y, int x, bool b) { mp[y * n + x] = b; }

int get(int y, int x) {
  if (mp.find(y * n + x) == mp.end())
    return -1;
  return mp[y * n + x];
}

struct N {
  int y, x, b;
};

long long pw(long long e, long long x) {
  if (x == 0)
    return 1;
  if (x == 1)
    return e % p;
  if (x % 2 == 0)
    return pw((e * e) % p, x / 2);
  return (e * pw(e, x - 1)) % p;
}

int main() {
  int m;
  cin >> n >> m;
  vector<N> ns(m);

  for (int i = 0; i < m; i++) {
    cin >> ns[i].y >> ns[i].x >> ns[i].b;
    ns[i].x--;
    ns[i].y--;
    s(ns[i].y, ns[i].x, ns[i].b);
  }
  long long ms = (n - 3) * (n - 2) / 2;
  if (ms < 0)
    ms = 0;
  for (int i = 0; i < m; i++) {
    if (abs(ns[i].y - ns[i].x) >= 3) {
      if (get(ns[i].x, ns[i].y) == -1) {
        // 1
        ms--;
      } else {
        if (get(ns[i].x, ns[i].y) != ns[i].b) {
          cout << 0 << endl;
          return 0;
        }
        if (ns[i].x > ns[i].y)
          ms--;
      }
    }
  }

  long long dp[n][1 << 5];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < (1 << 5); j++)
      dp[i][j] = 0;
  if (get(0, 0) == -1) {
    dp[0][0] = dp[0][1 << 2] = 1;
  } else if (get(0, 0)) {
    dp[0][1 << 2] = 1;
  } else {
    dp[0][0] = 1;
  }

  for (int i = 0; i < (1 << 5); i++) {
    if (((i >> 0) & 1) || ((i >> 4) & 1))
      continue;
    int x1 = (i >> 1) & 1;
    int x2 = (i >> 2) & 1;
    int x3 = (i >> 3) & 1;
    if (get(1, 0) == 1 - x1 || get(1, 1) == 1 - x2 || get(0, 1) == 1 - x3) {
      continue;
    }
    int y = (x1 + x2 + x3) % 2;
    dp[1][i] += dp[0][y << 2];
  }
  for (int i = 2; i < n; i++) {
    for (int j = 0; j < (1 << 5); j++) {
      int x1 = (j >> 0) & 1;
      int x2 = (j >> 1) & 1;
      int x3 = (j >> 2) & 1;
      int x4 = (j >> 3) & 1;
      int x5 = (j >> 4) & 1;
      if (get(i, i - 2) == 1 - x1 || get(i, i - 1) == 1 - x2 ||
          get(i, i) == 1 - x3 || get(i - 1, i) == 1 - x4 ||
          get(i - 2, i) == 1 - x5)
        continue;
      int y = (x1 + x5) % 2;
      if ((y + x3) % 2 != (x2 + x4) % 2)
        continue;
      for (int k = 0; k < (1 << 5); k++) {
        if (y != ((k >> 2) & 1)) {
          continue;
        }
        dp[i][j] += dp[i - 1][k];
        dp[i][j] %= p;
      }
    }
  }
  long long ans = 0;
  for (int i = 0; i < (1 << 5); i++) {
    ans += dp[n - 1][i];
    ans %= p;
  }
  ans *= pw(2, ms);
  ans %= p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 28928
N = int(input().rstrip())
b = list(map(int, input().rstrip().split()))
a = [0 for i in range(N)]

for i in range(N - 1):
	v = b[i]
	a[i + 1] = v
	if i == 0:
		a[i] = v
	else:
		if v <= a[i]:
			a[i] = v

r = sum(a)
print(r)


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
using namespace std;
const int MAX_N = 1e7;
int _par[MAX_N];//親
int _rank[MAX_N];//木の深さ

//n要素で初期化 parは親の要素の番号
void init(int n){
  for(int i=0; i<n; i++){
    _par[i] = i;
    _rank[i]=0;
  }
}

//木の根を求める
int find(int x){
  if(_par[x]==x){
    return x;
  }
  else{
    return _par[x] = find(_par[x]);
  }
}

//xとyの属する集合の併合
void unite(int x, int y){
  x=find(x);
  y=find(y);
  if(x==y) return;

  if (_rank[x] < _rank[y]){
    _par[x] = y;
  }else{
    _par[y]=x;
    if(_rank[x] == _rank[y])_rank[x]++;
  }
}

//xとyが同じ集合に属するか否か
bool same(int x, int y){
  return find(x) == find(y);
}


int main(){
  
  int N,M;

  cin >> N >> M;
  int p[N];
  for (int i=0; i<N; i++){
    cin >> p[i];
    p[i] -=1;
  }

  int x[M],y[M];
  for (int i=0; i<M; i++){
    cin >> x[i] >> y[i];
    x[i] -=1;
    y[i] -=1;
  }

  init(2*N);
  for (int i=0; i<N; i++){
    unite(i,p[i]+N);
  }

  for (int i=0; i<M; i++){
    unite(x[i],y[i]);
  }

  int count =0;
  for (int i=0; i<N; i++){
    if(same(i,N+i)) count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 4224
#include<cstdio>
using namespace std;
int n,a[105];
int main(){
	scanf ("%d",&n);
	for (register int i=1;i<=n;++i){
		scanf ("%d",&a[i]);
		if (a[i]%2==0){
			if (a[i]%3==0||a[i]%5==0) continue;
			else{
				printf ("DENIED\n");return 0;
			}
		}
	}
	printf ("APPROVED\n");
	return 0;
}

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

int main(){
    int n,count=1,ans=0; cin>>n;

    for(int i=1; i<=n; i++){

        if(i == pow(10,count) ){

            i *= 10;
            i--;
            count += 2;
            continue;
        }
        ans++;
    }
    cout<<ans<<endl;

    return  0;
}

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

typedef long long ll;

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int par[100001];
int ran[100001];

void init(int n)
{
	FOR(i,1,n+1){
		par[i] = i;
		ran[i] = 0;
	}
}

int root(int x)
{
	if(par[x] == x)return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y)
{
	x = root(x);
	y = root(y);
	if(x == y)return;
	if(ran[x] < ran[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(ran[x] == ran[y])ran[x]++;
	}
}

bool same(int x, int y)
{
	return root(x) == root(y);
}

int main()
{
	int n,m;
	cin >> n >> m;
	int p[n+1];
	FOR(i,1,n+1)cin >> p[i];
	init(n);
	FOR(i,0,m){
		int x,y;
		cin >> x >> y;
		unite(x, y);
	}
	int ans = 0;
	FOR(i,1,n+1){
		if(same(i, p[i]))ans++;
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 1408
N = int(input())
C0 = 0
C1 = 0
C2 = 0
C3 = 0


for i in range(N):
    C = input()
#    print(C)
    if C == 'AC':
        C0 += 1
    elif C == 'WA':
        C1 += 1
    elif C == 'TLE':
        C2 += 1
    elif C == 'RE':
        C3 += 1

print('AC x ' + str(C0))
print('WA x ' + str(C1))
print('TLE x ' + str(C2))
print('RE x ' + str(C3))

Measured memory_bytes: 9204
#include <iostream>
#include <set>
#include <cstring>
using namespace std;

int m;
int field[100][100];

void searchCube(const int key, int& nx, int& ny) {
    for (int x = 0; x < m; x++) {
        for (int y = 0; y < m; y++) {
            if (field[x][y] == 0) {
                break;
            } else if (field[x][y] == key) {
                nx = x;
                ny = y;
                return;
            }
        }
    }
    nx = ny = -1;
    return;
}

int searchFloor() {
    for (int x = 0; x < m; x++) {
        if (field[x][0] == 0) {
            return x;
        }
    }
    return -1;
}

void moveAllCubesAboveOntoFloor(const int cx, const int cy) {
    for (int i = 1; cy + i < m; i++) {
        if (field[cx][cy + i] > 0) {
            int nx = searchFloor();
            field[nx][0] = field[cx][cy + i];
            field[cx][cy + i] = 0;
        } else {
            break;
        }
    }
}

void moveCubeOnTop(const int cx, const int cy, const int toX) {
    for (int y = 0; y < m; y++) {
        if (field[toX][y] == 0) {
            field[toX][y] = field[cx][cy];
            field[cx][cy] = 0;
            break;
        }
    }
}

int main() {
    while (true) {
        cin >> m;
        if (m == 0) {
            break;
        }
        memset(field, 0, sizeof(field));
        for (int x = 0; x < m; x++) {
            field[x][0] = x + 1;
        }
        while (true) {
            int pick, put;
            cin >> pick >> put;
            if ((pick | put) == 0) {
                break;
            } else if (pick == put) {
                continue;
            }
            int pickX, pickY;
            searchCube(pick, pickX, pickY);
            int putX, putY;
            if (put != 0) {
                searchCube(put, putX, putY);
            } else {
                putX = searchFloor();
                putY = -1;
            }
            if ((pickX == putX && putY < pickY) || (putY == -1 && pickY == 0)) {
                continue;
            }
            moveAllCubesAboveOntoFloor(pickX, pickY);
            if (put != 0) {
                searchCube(put, putX, putY);
            } else {
                putX = searchFloor();
            }
            moveCubeOnTop(pickX, pickY, putX);
        }
        multiset<int> heights;
        for (int x = 0; x < m; x++) {
            int height = 0;
            for (int y = 0; y < m; y++) {
                if (field[x][y] > 0) {
                    height++;
                } else {
                    break;
                }
            }
            if (height > 0) {
                heights.insert(height);
            }
        }
        for (multiset<int>::iterator it = heights.begin(); it != heights.end(); it++) {
            cout << *it << endl;
        }
        cout << "end" << endl;
    }
}

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


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

    int cur = 0, pre = 0;
    for (auto&& c : s) {
        if (c == '(') cur++;
        else cur--;

        if (cur < 0) {
            pre++;
            cur++;
        }
    }

    cout << string(pre, '(') << s << string(cur, ')') << endl;

    return 0;
}

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

int main(){
	int n;
	cin>>n;
	vector<int> a(n,0);
	vector<int> dp(n,0);
	for(int i = 0; i < n; i ++)
		cin>>a[i];
	if(n == 2){
      	cout<<abs(a[1] - a[0]);
		return 0;
    }
	dp[1] = abs(a[1] - a[0]);
	for(int i = 2; i < n; i ++)
		dp[i] = min(abs(a[i] - a[i-1]) + dp[i-1] , abs(a[i] - a[i-2]) + dp[i-2]  );
	cout << dp[n-1];
}

Measured memory_bytes: 1024
//code_sm
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define si set<int>
#define ll long long
#define pb push_back
ll gcd(ll a,ll b)
{
	if(a==0)
	return b;
	else
	return gcd(b%a,a);
}
int main()
{
int n;
cin>>n;
cout<<"ABC"<<n;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,i,j,k,l,m,n,a[200005],b[200005];
    char s[200005],s1[200005];
    map<long long,long long>mp;
    pair<long long,long long>p[200005];
    int matrix[50][50];
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        matrix[i][j]=1;
    }
    cin>>k>>l;
    for(i=0;i<k;i++)
    {
        for(j=0;j<m;j++)
        matrix[i][j]=0;
    }
    for(i=0;i<l;i++)
    {
        for(j=0;j<n;j++)
        matrix[j][i]=0;
    }
    int count=0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            if(matrix[i][j]==1)
            count++;
        }
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
 
using namespace std;
 
int N, T;
 
//1-idx
int dp1[3000 + 10][3000 + 10];//dp1[i][j] := [1, i]品目まで食べるかを選んで、jの時間がかかったときのおいしさの最大値 
int dp2[3000 + 10][3000 + 10];//dp2[i][j] := [i, N]品目まで食べるかを選んで、jの時間がかかったときのおいしさの最大値
vector<int> A, B;
 
int main() {
	cin >> N >> T;
	for (int i = 0; i < N; i++) {
		int a, b;
		cin >> a >> b;
		A.push_back(a), B.push_back(b);
	}
	
	dp1[0][0] = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= T - 1; j++) {
			dp1[i][j] = dp1[i - 1][j];
			if (j - A[i - 1] >= 0)dp1[i][j] = max(dp1[i][j], dp1[i - 1][j - A[i - 1]] + B[i - 1]);
		}
	}
 
	dp2[N + 1][0] = 0;
	for (int i = N; i >= 1; i--) {
		for (int j = 0; j <= T - 1; j++) {
			dp2[i][j] = dp2[i + 1][j];
			if (j - A[i - 1] >= 0)dp2[i][j] = max(dp2[i][j], dp2[i + 1][j - A[i - 1]] + B[i - 1]);
		}
	}
 
	int ans = max(dp1[N][T - 1], dp2[1][T - 1]);
	for (int i = 0; i <= N - 1; i++) {
		for (int j = 0; j <= T - 1; j++) {
			ans = max(ans, dp1[i][j] + B[i] + dp2[i + 2][T - 1 - j]);
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 70912
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

static long gcd(long a, long b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

long long int facctorialMethod(int k){//階乗
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

long long int tousasum(long long int n){//等差数列
    return n*(n+1)/2;
}

unsigned GetDigit(unsigned num){//桁数
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

map< long long int, long long int > prime_factor(long long int n) {//素因数分解
    map< long long int, long long int > ret;
    for(long long int 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;
    double temp = 0.0;
    cin >> N;

    for(int i=0;i<N;i++){
        int tmp = 0;
        cin >> tmp;
        temp += 1.0/(double)tmp;
    }

    cout << 1.0/temp << endl;
}








Measured memory_bytes: 256
//安定なソート（例：バブルソート） //不安定なソート（例選択ソート）
#include <iostream>

using namespace std;

struct Card{char suit, value;};


void bubbleSort(struct Card a[], int n)
{
    for(int i = 1; i<n; i++){//1回ループするたびに一番右が最も大きい値になる
        for(int j = 0; j<n-i; j++){
        if(a[j].value > a[j+1].value){
          Card temp = a[j];
          a[j] = a[j+1];
          a[j+1] = temp;//この三行で右の方が大きくなる
        }
    }
  }
}

void selectionSort(struct Card a[], int n)//選択ソートはもっとも小さい値を見つけて１番右にもっていく
{
    for(int i = 0; i<n; i++){
        int min = i;//この時点での未ソートの部分のインデックス
        for(int j = i; j < n; j++){//最小の値を探すループ//jの初期値は未ソート部分の最も左のインデックス
          if(a[j].value < a[min].value)
              min = j;//最小の値のインデックスを探す
        }
          Card temp = a[i];
          a[i] = a[min];
          a[min] = temp;
    }
}

void print(struct Card a[], int n){
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << a[i].suit << a[i].value;
    }
    cout << endl;
}

//バブルソートと選択ソートの結果を比較
bool isStable(struct Card C1[], struct Card C2[], int n){
    for(int i = 0; i<n; i++){
        if(C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main(){
    Card C1[100], C2[100];
    int n;
    char ch;

    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> C1[i].suit >> C1[i].value;
    }

    for(int i = 0; i < n; i++)
        C2[i] = C1[i];

    bubbleSort(C1, n);
    selectionSort(C2, n);

    print(C1, n);
    cout << "Stable" << endl;

    print(C2, n);
    if(isStable(C1, C2, n)){
        cout << "Stable" << endl;
    }else{
        cout << "Not stable" << endl;
    }

    return 0;
}

















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

int main()
{
    int n,i,j,ans=0;
    cin>>n;

    string s;
    cin>>s;

    i=0;
    j=n-1;
    for( ;i<j;)
    {
        if(s[j]=='R'&&s[i]=='W')
        {
            j--;
            i++;
            ans++;
        }
        else if(s[i]=='R')
            i++;
        else if(s[j]=='W')
            j--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3732
use std::io::*;
use std::str::*;
#[allow(unused_imports)]
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() {
    input!{
        a: usize,
        b: usize,
    }
    if a % 2 == 1 && b % 2 == 1 {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

#define MAX_N 100000

int main(){
  int N,Q,i,S[MAX_N],T,l,mid,r,res = 0;
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&Q);
  for(i = 0 ; i < Q ; i++){
    scanf("%d",&T);
    l = -1, r = N;
    while(r - l > 0){
      mid = (l + r) / 2;
      if(S[mid] == T){
        ++res;
        break;
      }else if(S[mid] > T){
        r = mid;
      }else{
        l = mid+1;
      }
    }
  }
  printf("%d\n",res);
  return 0;
}

Measured memory_bytes: 988
use std::io;
use std::cmp;
use std::collections::binary_heap::BinaryHeap;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n);
    let n = n.trim().parse::<usize>().unwrap();
    let mut a = [0i64; 300_000];

    let mut numbers = String::new();
    io::stdin().read_line(&mut numbers);
    let mut numbers = numbers.split_whitespace();
    for i in 0..(3*n) {
        a[i] = numbers.next().unwrap().parse::<i64>().unwrap();
    }

    let mut rq = BinaryHeap::with_capacity(2*n);
    for i in 0..n {
        rq.push(-a[i]);
    }
    let mut rsum: i64 = rq.iter().fold(0i64, |acc, &x| acc - x );
    let mut rs = [0i64; 100_001];
    rs[0] = rsum;
    
    for i in 0..n {
        let k = i + n;
        rsum += a[k];
        rq.push(-a[k]);
        rsum -= -rq.pop().unwrap();

        rs[i+1] = rsum;
    }

    let mut lq = BinaryHeap::with_capacity(2*n);
    for i in (2*n)..(3*n) {
        lq.push(a[i]);
    }
    let mut lsum = lq.iter().fold(0i64, |acc, &x| acc + x );
    let mut ls = [0i64; 100_001];
    ls[n] = lsum;

    for i in 0..n {
        let k = 2*n - 1 - i;
        lsum += a[k];
        lq.push(a[k]);
        lsum -= lq.pop().unwrap();

        ls[k-n] = lsum;
    }

    let mut max = std::i64::MIN;
    for i in 0..(n+1) {
        max = cmp::max(max, rs[i] - ls[i]);
    }
    
    println!("{}", max);
}

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

int main(){
  ll N,K,M,sum = 0; cin >> N >> K >> M;
  if(K/N >= M){
    cout << M;
  }
  else{
    cout << K/N;
  }
}

Measured memory_bytes: 3604