akhauriyash/Code-Regression huggingface dataset:
module mod_three_colors
  implicit none
  integer(8), parameter :: md = 998244353_8
contains
  recursive function pow(a,b) result(r)
    implicit none
    integer(8), intent(in) :: a
    integer, intent(in) :: b
    integer(8) :: r
    r = 1_8
    if (b.eq.0) return
    if (mod(b,2).eq.0) then
      r = pow(a,b/2)
      r = mod(r*r,md)
      return
    end if
    r = mod(a*pow(a,b-1),md)
    return
  end function pow
end module mod_three_colors
program three_colors
  use mod_three_colors
  implicit none
  integer :: n, a, s, i, j
  integer(8) :: x, dp1(0:90000), dp2(0:90000)
  dp1 = 0_8
  dp2 = 0_8
  read(*,*) n
  s = 0
  dp1(0) = 1_8
  dp2(0) = 1_8
  do i = 1, n
    read(*,*) a
    do j = s, 0, -1
      dp1(j+a) = mod(dp1(j+a)+dp1(j),md)
      dp1(j) = mod(2_8*dp1(j),md)
      dp2(j+a) = mod(dp2(j+a)+dp2(j),md)
    end do
    s = s+a
  end do
  x = pow(3_8,n)+md-mod(3_8*sum(dp1((s+1)/2:s)),md)
  if (mod(s,2).eq.0) x = x+3_8*dp2(s/2)
  x = mod(x,md)
  write(*,'(i0)') x
  stop
end program three_colors

Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

//char arr[57][57];
int main(){
	Lancer();
	ll x,i=2,a,k,b,res=1;
	cin >> x;
	while (i<=x)
	{
		a = 1;
		k = 2;
		while (1)
		{
			a = 1;
			for (int j = 0; j < k; j++)
				a *= i;
			if (a <= x)
				res = max(a, res);
			else
				break;
			k++;
		}
		i++;
	}
	cout << res;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3668
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <cmath>
using namespace std;

int H, score;
int board[10][5];

void printBoard(){
  cout << endl;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < 5; j++) cout << board[i][j] << " ";
    cout << endl;
  }
}

bool checkBoard(){
  bool flag = false;
  for(int i = 0; i < H; i++){
    int prev = board[i][0], head = 0, tail = 1;
    int ans_head = 0, ans_tail = 1;
    for(int j = 1; j < 5; j++){
      if(board[i][j] == prev && prev != 0) tail++;
      else{
        prev = board[i][j];
        head = j;
        tail = head + 1;
      }
      if(tail - head > ans_tail - ans_head){
        ans_head = head;
        ans_tail = tail;
      }
    }

    if(ans_tail - ans_head < 3) continue;
    score += board[i][ans_head] * (ans_tail - ans_head);
    flag = true;

    for(int j = i; j >= 1; j--){
      for(int s = ans_head; s < ans_tail; s++) board[j][s] = board[j-1][s];
    }

    for(int j = ans_head; j < ans_tail; j++) board[0][j] = 0;
  }

  return flag;
}

int main(void)
{
  while(cin >> H && H != 0){
    score = 0;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < 5; j++) cin >> board[i][j];
    }
    while(checkBoard());
    cout << score << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int h,w;
    cin >> h >> w;
    string str;
    int cnt = 0;
    rep(i,h){
        cin >> str;
        rep(j,w){
            if(str[j] == '#'){
                cnt++;
            }
        }
    }

    if(cnt == h+w-1){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

    return 0;
}


Measured memory_bytes: 3624
from collections import defaultdict

N, K, *A = map(int, open(0).read().split())

S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + A[i]

d = defaultdict(int)
ans = 0
for j in range(N + 1):
    v = (S[j] - j) % K
    ans += d[v]
    d[v] += 1
    if j >= K - 1:
        d[(S[j - K + 1] - (j - K + 1)) % K] -= 1
        
print(ans)


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

using ll = long long;
// #define int long long

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  string s;
  cin >> s;
  REP(i,s.length()) {
    cout << "x";
  }
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T1, typename T2>
inline bool cmn (T1& a, T2 b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<typename T1, typename T2>
inline bool cmx (T1& a, T2 b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  long long n;
  cin >> n;
  constexpr int sz = 3;
  vector<int> a(sz), b(sz);
  for (int i = 0; i < sz; i++) cin >> a[i];
  for (int i = 0; i < sz; i++) cin >> b[i];
  auto cal = [] (int W, vector<int>&w, vector<int>&v) {
    int tz = w.size();
    if (tz == 0) return 0LL;
    if (tz == 1) return (long long)(W / w[0]) * v[0];
    if (tz == 2) {  
      long long ret = 0;
      for (int t = 0; t < 2; t++) {
        for (int i = 0; i <= min(W / w[0], w[1]); i++) {
          int j = (W - w[0] * i) / w[1];
          cmx(ret, (long long)i * v[0] + (long long)j * v[1]);
        }
        swap(w[0], w[1]);
        swap(v[0], v[1]);
      }
      return ret;
    }
    vector<long long> dp(W + 1, -1);
    dp[0] = 0;
    for (int i = 0; i < tz; i++) {
      if (v[i] < 0) continue;
      for (int j = 0; j + w[i] <= W; j++) {
        if (dp[j] == -1) continue;
        cmx(dp[j + w[i]], dp[j] + v[i]);
      }
    }
    return *max_element(dp.begin(), dp.end());
  };
  for (int t = 0; t < 2; t++) {
    vector<int> w, v;
    for (int i = 0; i < sz; i++) {
      if (a[i] < b[i]) {
        w.push_back(a[i]);
        v.push_back(b[i] - a[i]);
      }
    }
    n += cal(n, w, v);
    swap(a, b);
  }
  cout << n << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}

int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 2056
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		
		int n=in.nextInt();
		BT tree=new BT();
		PrintWriter out=new PrintWriter(System.out);
		
		for(int i=0;i<n;i++) {
			String odr=in.next();
			
			if(odr.equals("insert")) {
				int key=Integer.parseInt(in.next());
				tree.insert(key);
			}
			
			else if(odr.equals("find")) {
				int key=Integer.parseInt(in.next());
				if(tree.find(key))out.println("yes");
				else out.println("no");
			}
			
			else if(odr.equals("print")) {
				Queue<Integer> Q=new ArrayDeque<>(tree.walk('I'));
				while(!Q.isEmpty())out.print(" "+Q.remove());
				out.println();
				Q=tree.walk('F');
				while(!Q.isEmpty())out.print(" "+Q.remove());
				out.println();
				
			}
		}
		out.flush();
	}

}

class BTNode{
	int key;
	BTNode Parent,Left,Right;
	
	BTNode(int k){
		key=k;
	}
}

class BT{
	BTNode root,dummy;
	int NIL=-2000000001;
	int size=0;
	
	Queue<Integer> Q;
	
	BT(){
		root=new BTNode(NIL);
		dummy=new BTNode(NIL);
		root.Parent=dummy;
		root.Left=dummy;
		root.Right=dummy;
	}
	
	void insert(int k) {
		if(size==0) {
			root.key=k;
			size++;
			return;
		}
		
		BTNode node=new BTNode(k),s=root,p=root;
		node.Left=dummy;node.Right=dummy;
		
		while(s!=dummy) {
			p=s;
			if(k<s.key)s=s.Left;
			else s=s.Right;
		}
		
		node.Parent=p;
		size++;
		
		if(k<p.key)p.Left=node;
		else p.Right=node;
	}
	
	Queue<Integer> walk(char odr) {
		Q=new ArrayDeque<>();
		if(odr=='F')preWalk(root);
		else if(odr=='I')inWalk(root);
		return Q;
	}
	
	void preWalk(BTNode node) {
		Q.add(node.key);
		if(node.Left!=dummy)preWalk(node.Left);
		if(node.Right!=dummy)preWalk(node.Right);
	}
	
	void inWalk(BTNode node) {
		if(node.Left!=dummy)inWalk(node.Left);
		Q.add(node.key);
		if(node.Right!=dummy)inWalk(node.Right);
	}
	
	boolean find(int key) {
		if(isExist(key,root))return true;
		else return false;
	}
	
	boolean isExist(int key,BTNode node) {
		if(node==dummy)return false;
		if(node.key==key)return true;
		
		boolean b;
		if(key<node.key)b=isExist(key,node.Left);
		else b=isExist(key,node.Right);
		
		return b;
	}
}



Measured memory_bytes: 203904
#include <cstdio>
#define access(i) A[i / 3][i % 3]

using namespace std;
typedef long long llong;

#define MAX
const llong mod = 1000000000 + 7;

int main()
{
  int A[3][3];
  int N, b;
  int flag = 0;
  for (int i = 0; i < 9; i++)
  {
    scanf("%d", &access(i));
  }

  scanf("%d", &N);
  for (int i = 0; i < N; i++)
  {
    scanf("%d", &b);
    for (int j = 0; j < 9; j++)
    {
      if (access(j) == b)
        access(j) = 0;
    }
  }

  for (int i = 0; i < 3; i++)
  {
    if (A[i][0] == 0 && A[i][1] == 0 && A[i][2] == 0)
      flag = true;
    if (A[0][i] == 0 && A[1][i] == 0 && A[2][i] == 0)
      flag = true;
  }
  if (A[0][0] == 0 && A[1][1] == 0 && A[2][2] == 0)
    flag = true;
  if (A[0][2] == 0 && A[1][1] == 0 && A[2][0] == 0)
    flag = true;

  if (flag)
    printf("Yes");
  else
    printf("No");

  return 0;
}

Measured memory_bytes: 1732
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int max = 0;
    int cnt = 0;
    for (int i = 1; i < h.size(); i++)
    {
        if (h[i] <= h[i - 1])cnt++;
        else if (h[i] > h[i - 1])
        {
            if (max < cnt)
            {
                max = cnt;
            }
            cnt = 0;
        }
        if (i == h.size() - 1)
        {
            if (max < cnt)
            {
                max = cnt;
            }
            cnt = 0;
        }
    }
    cout << max << endl;

    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define int long long int
using namespace std;
 
int32_t main()
{
    int m,s,t;
    cin>>m>>s>>t;
    if(t>=s)
    {
      	t=s-1;
    	cout<<floor((m*t)/s);
    }
    else
    {
        int x=t;
        cout<<floor((m*x)/s)-m*floor(x/s);
        
    }
 
    
 
}

Measured memory_bytes: 3788
#include<iostream>
#include<string>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<climits>
#include<cmath>
#include<map>
#include<vector>
#define INF INT_MAX
using namespace std;

int N;
string S;
int ans;

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

	for (int i = 0; i < N; i++) {
		if (S[i] != S[i + 1]) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
import sys
import numpy as np
n, k, q = map(int, input().split())
a = [int(input())-1 for _ in range(q)]
lst = np.full(n, k)
for i in a:
    lst[:i]-=1
    lst[i+1:]-=1
for i in range(n):
    if lst[i] > 0:
        print('Yes')
    else:
        print('No')



Measured memory_bytes: 31836
N = int(input())
r_list = []
for i in range(N):
  item = input().split()
  item[1] = int(item[1])
  item.insert(0, i + 1)
  r_list.append(item)

r_list.sort(key = lambda x: x[2], reverse = True)
r_list.sort(key = lambda x: x[1])
for item in r_list:
  print(item[0])

Measured memory_bytes: 9084
from collections import deque, defaultdict


def read_input():
    n = int(input())
    edges = []

    for i in range(n - 1):
        u, v, w = map(int, input().split())
        edges.append((u, v, w))

    return n, edges


# グラフのノード間の距離の偶奇に応じてノードをグループ分けする
def search_graph(nodes, edges):
    edge_table = {n:[] for n in nodes}

    for e in edges:
        edge_table[e[0]].append((e[1], e[2]))
        edge_table[e[1]].append((e[0], e[2]))

    # 探索開始
    q = deque()
    # (node, これまでの距離), 初期ノードは(1, 0)とする
    q.appendleft((nodes[0], 0))

    even = []
    odd = []
    searched = defaultdict(int)

    while len(q) > 0:
        cnode, cdist = q.pop()
        searched[cnode] = 1

        if cdist % 2:
            odd.append(cnode)
        else:
            even.append(cnode)

        next_nodes = edge_table[cnode]
        for nn in next_nodes:
            if searched[nn[0]] == 0:
                q.appendleft((nn[0], cdist + nn[1]))

    return set(even), set(odd)


def submit():
    n, edges = read_input()
    nodes = [i for i in range(1, n + 1)]
    even, odd = search_graph(nodes, edges)

    for n in nodes:
        if n in even:
            print(0)
        else:
            print(1)



if __name__ == '__main__':
    submit()


Measured memory_bytes: 67084
// correcting previous top down approach
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
double pi = acos(-1.0);
const double EPS=1e-9;
#define MOD ll(1e9L+7)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define t() ll tt;cin>>tt;while(tt--) 
#define t2() ll tt2; cin>>tt2; for(ll tti=1;tti<=tt2;tti++)
#define printcj "Case #"<<tti<<": "
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cout << #x << " = " << x << "   " << #y << " = " << y << "\n";

const ll sz=3001,INF=-1e16L;
ll n,a[sz];
ll dp[sz][sz];


ll solve(ll i,ll j,bool xturn)
{
    if(i==j){
        if(xturn) return a[i];
        else return -a[i];
    }
    if(dp[i][j]!=INF) return dp[i][j];
    ll diff1 = solve(i+1,j,!xturn);
    ll diff2 = solve(i,j-1,!xturn);
    if(xturn) {
        if(diff1+a[i]>diff2+a[j]) return dp[i][j]=diff1+a[i];
        else return dp[i][j]=diff2+a[j];
    }
    else{
        if(diff1-a[i]<diff2-a[j]) return dp[i][j]=diff1-a[i];
        else return dp[i][j]=diff2-a[j];
    }

}

int main()
{
    fastio;
    ll i,j;
    cin>>n;
    for(i=0;i<n;i++)for(j=0;j<n;j++) dp[i][j] = INF;
    for(i=0;i<n;i++)cin>>a[i];
    
    ll diff = solve(0,n-1,1);
    cout<<diff;

    
}

Measured memory_bytes: 74212
def resolve():
    n = int(input())
    s = [[] for _ in range(n)]
    for i in range(n):
        a = int(input())
        for j in range(a):
            x, y = map(int, input().split())
            s[i].append((x, y))
    ans = 0
    for i in range(2**n):
        ho = [0]*n
        OK = True
        for j in range(n):
            ho[j] = (i>>j)&1
        for j in range(n):
            if ho[j] == 0:
                continue
            else:
                for k in range(len(s[j])):
                    if ho[s[j][k][0]-1] == s[j][k][1]:
                        continue
                    else:
                        OK = False
        if OK:
            ans = max(ans, sum(ho))
    print(ans)


resolve()

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
  char s[100000];
  scanf("%s", s);
  int size = 0;
  do {
    size++;
  } while(*(s+size) != '\0');
  char zero = '0', one = '1';
  int count = 0;
  for (int i = 0; i < size; i++) {
    if (((i%2 == 1) && (*(s+i) == zero)) || ((i%2 == 0) && (*(s+i) == one))) {
      count++;
    }
  }
  if (count > size - count) {
    count = size - count;
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(z) (z).begin(),(z).end() 
#define MOD 1000000007
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll isprime(ll n)
{
	for(int i=2;i<n;i++)
		if(n%i==0)
		return 0;
		
	return 1;	
}
int main()
{ 
    FAST;
	long double n,d;
	cin>>n>>d;
	ll cnt=0;
	while(n--)
	{
		long double x,y;
		cin>>x>>y;
		long double dist=sqrt((x*x)+(y*y));
		if(dist<=d)cnt++;
	}
	cout<<cnt;
}


Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

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

    x-=a;
    x%=b;

    cout << x << endl;
    return 0;
}



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

int vis[100005];
long long sum[100005];
int main(){
    long long n, x, m;
    scanf("%lld%lld%lld", &n, &x, &m);
    if(x == 0) printf("0\n");        
    else{

        long long y = x;
        int i = 1;
        long long temp = x;
        vis[y] = 1;
        sum[y] = x;

        long long ans = x;
        n--;
        while(n > 0){
            i++;
            y = y*y%m;
            temp += y;
            ans += y;
            n--;

            if(vis[y] && n >= i-vis[y]){
                int d = i-vis[y];
                ans += (temp - sum[y])*(n/d);
                n %= d;
            }

            vis[y] = i;
            sum[y] = temp;
        }

        printf("%lld\n", ans);


    }
}

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

int n;
vector<int> l;
vector<int> r;
int ans = 0;

void input(){
    cin >> n;
    l.resize(n);
    r.resize(n);
    for(int i = 0; i < n; i++){
        cin >> l[i] >> r[i];
        ans += r[i] - l[i] +1;
    }
    cout << ans << endl;
}

int main(){
    input();
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
  char b;
  cin>>b;
  if(b=='A'){cout<<'T'<<endl;}
  if(b=='T'){cout<<'A'<<endl;}
  if(b=='G'){cout<<'C'<<endl;}
  if(b=='C'){cout<<'G'<<endl;}
}


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;
using P = pair<int,int>;

int main() {
    int n,sum=0;
    cin>>n;
    vector<int> b(n-1),a(n);
    rep(i,n-1) cin>>b[i];
    a[0]=b[0];
    sum+=a[0];
    for (int i=1; i<n-1; i++) {
        a[i]=min(b[i-1],b[i]);
        sum+=a[i];
    }
    a[n-1]=b[n-2];
    sum+=a[n-1];
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

const int N=2e4+5;

int n,a[N],b[N];
char s[N],t[N];

int calc() {
	int t1=0,t2=0;
	fo(i,1,n-1) if (s[i]=='0'&&s[i+1]=='1') a[++t1]=i;
	fo(i,1,n) b[++t2]=0;
	fo(i,1,n-1) if (t[i]=='0'&&t[i+1]=='1') b[++t2]=i;
	fo(i,1,n) b[++t2]=n;
	int ret=n*n;
	fo(i,1,t2-t1+1) {
		int now=0;
		fo(j,1,i-1) now+=b[j];
		fo(j,1,t1) now+=abs(a[j]-b[i+j-1]);
		fo(j,i+t1,t2) now+=n-b[j];
		ret=min(ret,now);
	}
	return ret;
}

int main() {
	scanf("%d",&n);scanf("%s",s+1);scanf("%s",t+1);
	if (n<=2) {
		int ans=0;
		fo(i,1,n) ans+=s[i]!=t[i];
		printf("%d\n",ans);
		return 0;
	}
	int tmp=calc();
	fo(i,1,n) s[i]='0'+'1'-s[i],t[i]='0'+'1'-t[i];
	printf("%d\n",tmp+calc());
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
#include <math.h> 
#include <set>
#include <map>
#include <deque>


using namespace std;

#define ll long long int
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define riverse(v) reverse((v).begin(), (v).end())
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<ll>;
using vvi = vector<vi>;
const ll MOD = 1e9 + 7;

int main() {
	int n;
	cin >> n;
	vll a(n);
	rep(i, n) {
		cin >> a[i];
	}
	deque<int> ans;
	repp(i, n) {
		if (i % 2 == n % 2) {
			ans.push_front(a[i - 1]);
		}
		else ans.push_back(a[i - 1]);
	}
	rep(i, n) {
		cout << ans[i] << " ";
	}
}

Measured memory_bytes: 4608
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 a, b, c;
int main() {
  cin >> a >> b >> c;
  c -= a - b;
  cout << max(i64(0), c) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
#define PII pair<int,int>
#define ls x<<1
#define rs x<<1|1
#define fi first
#define se second
#define pb push_back
#define cwk freopen("D:\\c++\\in.txt","r",stdin),freopen("D:\\c++\\out.txt","w",stdout)
using namespace std;
const int N=1e6+10;
ll sum[N];
int main()
{
	///cwk;
	for(int i=1;i<=1e6;i++) {
		if(i%3&&i%5) {
			sum[i]=i;
		}else {
			sum[i]=0;
		}
	}
	int n;
	cin>>n;
	ll ans=0;
	for(int i=1;i<=n;i++) {
		ans+=sum[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11388
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0; string s;
	cin >> n;
	int ac = 0, wa = 0, tle = 0, re = 0;
	for (int i = 0; i < n; ++i)
	{
		cin >> s;
		if (s == "AC")
			++ac;
		else if (s == "WA")
			++wa;
		else if (s == "TLE")
			++tle;
		else
			++re;
	}
	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;
}

Measured memory_bytes: 3668
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(map(int, list(input())))
mod = 2019
lens = len(S)
mods = [0]*lens
cum = 0
for i in range(lens):
    s = S[-i-1]
    cum += s*pow(10, i, mod)
    cum %= mod
    mods[i] = cum
mods += [0]
from collections import Counter
c = Counter(mods)

ans = 0
for num, cnt in c.most_common():
    if cnt<2:
        break
    ans += cnt*(cnt-1)//2
print(ans)

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

struct node {
    int s, e, m; ll v, lz;
    node *l, *r;
    node(int _s, int _e): s(_s), e(_e), m((_s+_e)/2), v(0), lz(0) {
        if (s != e) {
            l = new node(s, m);
            r = new node(m+1, e);
        }
    }
    
    void prop() {
        if (lz == 0) return;
        if (s != e) {
            l->lz += lz;
            r->lz += lz;
        }
        v += lz;
        lz = 0;
    }

    void update(int x, int y, ll z) {
        assert(x <= y);
        //cout << "UPDATE " << s << " " << e << " :: " << x << " " << y << endl;
        //if (x == 3 and y == 3) cout << "AHHHHHHHHHHHHHHHHHHHHHHHHHH" << endl;
        if (s == x && e == y) { lz += z; return; }
        else if (y <= m) l->update(x, y, z);
        else if (x >  m) r->update(x, y, z);
        else l->update(x, m, z), r->update(m+1, y, z);

        l->prop();
        r->prop();
        v = min(l->v, r->v);
    }

    ll qmin(int x, int y) {
        prop();
        if (s == x && e == y) return v;
        if (y <= m) return l->qmin(x, y);
        if (x >  m) return r->qmin(x, y);
        return min(l->qmin(x, m), r->qmin(m+1, y));
    }

    void dbg(string pre="|") {
        cout << pre << "> " << s << " " << e << " :: " << v << " " << lz << endl;
        if (s != e) l->dbg(pre+"--"), r->dbg(pre+"--");
    }
} *seg;

int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;
    vector<ii> event[n+1];
    ll total = 0;
    FOR(i,0,m-1) {
        int l, r, a; cin >> l >> r >> a;
        event[l].emplace_back(r, a);
        total += a;
    }

    seg = new node(1, n+2);
    ll dp[n+2]; dp[n+1] = 0;

    RFOR(x,n,1) {
        for (auto e : event[x]) {
            seg->update(e.fi+2, n+2, e.sc);
            //cout << "\t\tEVENT " << e.fi+2 << " to " << n+2 << " by " << e.sc << endl;
        }

        //cout << "TEST " << seg->qmin(x+1, n+1) << endl;
        //cout << "\t\tTEST ";
        //FOR(i,1,n+2) cout << seg->qmin(i,i) << ' ';
        //cout << endl;
        //seg->dbg();

        dp[x] = min(dp[x+1], seg->qmin(x+1, n+2));
        seg->update(x, x, dp[x]);
        //cout << "\t\tUPDATE " << x << " by " << dp[x] << endl;
        //cout << x << " :: " << dp[x] << endl;
    }

    cout << total - dp[1] << '\n';
}



Measured memory_bytes: 37760
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC160
{
    class Program
    {
        static void Main(string[] args)
        {
            b();
        }

        public static void b()
        {
            long x = long.Parse(Console.ReadLine());
            long a = x / 500;
            x %= 500;
            long b = x / 5;
            Console.WriteLine(a * 1000 + b * 5);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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;}
using namespace std;

int main(){
  ll N,cnt=0;
  string S;
  cin>>N>>S;
  
  ll A[N],cntr=0,cntg=0,cntb=0;
  REP(i,N){
    if(S.at(i)=='R'){
      A[i]=1;
      cntr++;
    }
    if(S.at(i)=='G'){
      A[i]=2;
      cntg++;
    }
    if(S.at(i)=='B'){
      A[i]=3;
      cntb++;
    }
  }
  
  for(int i=0; i<N-2; ++i){
    for(int j=i+1; j<N-1; ++j){
      int k=2*j-i;
      if(k>=N) continue;
      
      if(A[i]+A[j]==3){
        if(A[k]==3) cnt++;
      }
      if(A[i]+A[j]==5){
        if(A[k]==1) cnt++;
      }
      if(A[i]+A[j]==4 && A[i]!=2){
        if(A[k]==2) cnt++;
      }
    }
  }
  
  
  cout<<cntr*cntg*cntb-cnt<<endl;
  return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define int long long
#define mod 1e18+10
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main() {
	int s,i;
	cin>>s;
	map<int,int> mp;
	mp[s]=1;
	for(i=2;;i++)
	{
		if(s%2==0)
			s/=2;
		else s=3*s+1;
		if(mp[s])
		{	cout<<i;
			return 0;
		}
		mp[s]=1;	
	}
	
}


Measured memory_bytes: 256
class UnionFindTree():
    # Union find tree
    # 2つの効率化　経路圧縮、ランク
    # つなげることはできるか分離することはできないので、木をつなげる方向に利用する
    # 
    def __init__(self, node_size):
        # node_num: 全体のノード数
        # parent: ノードがrootなら-1、親がいれば親の番号を入れる
        # size:
        # rank:  
        # self.parent =[-1] * node_size
        self.parent =[x for x in range(node_size)]
        self.node_size = node_size
        self.size = [1] * node_size
        self.rank = [1] * node_size

        # self.node_list = np.array([x for x in range(node_size)])
        self.member_dict = {}
    
    def find_root(self,node):
        # node属する木のrootを探す
        # たどった経路に含まれるnodeの親をrootにつなぎ替える
        if self.parent[node] == node:             # 自身がrootの場合
            root = node
        else:                                   # 自身がrootでない場合
            root = self.find_root(self.parent[node]) # 再帰的にrootを探す
            self.parent[node] = root            # たどった経路に含まれるnodeの親をrootにつなぎ替える(経路圧縮)
        return root

    def unite(self,node0, node1):
        # node0とnode1が含まれる木を結合する
        
        #node0 node1のrootを求める
        root_node0 = self.find_root(node0) 
        root_node1 = self.find_root(node1)

        if root_node0 != root_node1:
            # rankを比較しrankが小さい方の木を大きい方の木のrootにつなげる
            # rank is sameのときのみrankが増える

            # node1のグループをnode0のグループに結合
            if self.rank[root_node0] == self.rank[root_node1]: # rank is same
                self.parent[root_node1] = root_node0
                self.rank[root_node0] += 1
                self.size[root_node0] += self.size[root_node1]

            # node1のグループをnode0のグループに結合
            elif self.rank[root_node0] > self.rank[root_node1]:
                self.parent[root_node1] = root_node0
                self.size[root_node0] += self.size[root_node1]

            # node0のグループをnode1のグループに結合
            else:
                self.parent[root_node0] = root_node1
                self.size[root_node1] += self.size[root_node0]

    def same(self,node0,node1):
        #同じグループか確かめる
        return self.find_root(node0)==self.find_root(node1)




N,K,L = map(int,input().split())

road_uft = UnionFindTree(N)
train_uft = UnionFindTree(N)

for _ in range(K):
    p,q = map(int,input().split())
    p -=1
    q -=1
    road_uft.unite(p,q)

for _ in range(L):
    r,s = map(int,input().split())
    r-=1
    s-=1
    train_uft.unite(r,s)


pair_dict = {}
pair_list = []
for i in range(N):
    road_root = road_uft.find_root(i)
    train_root = train_uft.find_root(i)
    pair = (road_root,train_root)
    pair_list.append(pair)
    if pair in pair_dict:
        pair_dict[pair] +=1
    else:
        pair_dict[pair] = 1

ans = ""
for i in range(N):
    pair = pair_list[i]
    ans += str(pair_dict[pair]) + " "
print(ans)

Measured memory_bytes: 60636
N,M=map(int,input().split())
S=list(map(int,input().split()))

tokuhyo=0
for i in range(N):
    tokuhyo+=S[i]

S.sort()
S.reverse()
for i in range(M):
    if S[i]<tokuhyo/(4*M):
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 9188
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int X, Y, Z;
	cin >> X >> Y >> Z;
	X -= Z;
	cout << X / (Y + Z) << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
#define ll 		 long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 	 1000000007
#define MOD      998244353
#define mp       make_pair
#define pb       push_back
#define F        first
#define S        second
#define t()      ll test;cin>>test;while(test--)
#define ii       pair<int,int>
#define endl     "\n"
#define que_max  priority_queue <int>
#define IOS      ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

typedef tree < int ,  null_type ,  greater <int> ,  rb_tree_tag ,  tree_order_statistics_node_update > pbds;

int pw(int b, int p) { int r = 1; while (p > 0) { if (p & 1) r = r * b;
        p = p >> 1; b = b * b; } return r; }


const int INF = 1e9+5;
int main()
{
	ll n , k;
	cin>>n>>k;
	vector <ll> v(n);
	for(auto &i : v)
		cin>>i;

	vector <ll> dp(n,INF);
	dp[0] = 0;

	for(int i=0;i<n;++i)
	{
		for(int j = i+1 ; j<=(i+k) ; ++j)
		{
			if(j<n)
			{
				dp[j] = min(dp[j] , dp[i]+abs(v[i]-v[j]));
			}
		}
	}
	cout<<dp[n-1]<<endl;
	return 0;

}

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

int main(){
  int N, M;
  int h[1500], w[1500];
  vector<int> k;
  //kの要素iについて、(X,Y)からy=xに下ろした垂線の足Hの座標を(i/2,i/2)とする。
  //つまりi=X+Yで、kは各iを集めた配列。
  int X[1501], Y[1501];
  int sum, temp;
  while(cin >> N >> M && N>0){
    for(int i=0;i<N;i++)
      cin >> h[i];
    for(int i=0;i<M;i++)
      cin >> w[i];

    X[0]=0; Y[0]=0;
    for(int i=0;i<M;i++)
      X[i+1] = X[i] + w[i];
    for(int i=0;i<N;i++)
      Y[i+1] = Y[i] + h[i];
    
    k.clear();
    for(int i=0;i<M+1;i++)
      for(int j=0;j<N+1;j++)
        k.push_back(X[i]+Y[j]);
    sort(k.begin(), k.end());
    
    sum=0;
    temp=1;
    for(int i=1;i<k.size();i++){
      if(k[i] == k[i-1])
        temp++;
      else{
	sum += temp*(temp-1)/2;
	temp = 1;
      }
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 19344
n = int(input())
l = [int(x) for x in input().split()]
D = set() #Duplication
S = set() #all
for x in l:
    if x in S:
        D.add(x)
    else:
        S.add(x)

M = max(S)
limit = M+1
mp = [0]*(limit)

cnt = 0
S = sorted(S)
for x in S:
    for y in range(x,limit,x):
        mp[y] += 1
    if(x in D):
        continue
    if(mp[x]==1):
        cnt += 1
        
print(cnt)





Measured memory_bytes: 36200
#include <stdio.h>
#include <math.h>

int main(int argc, const char * argv[]) {
    int d,a;
    double x=0,y=0,rada;
    scanf("%d,%d",&d,&a);
    if(d==0&&a==0){
        printf("%d\n",d);
        printf("%d\n",a);
        return 0;
    }
    
    rada=a*3.141592/180.0;
    y+=d;
    //printf("x:%lf y:%lf\n",x,y);
    
    while(1){
        scanf("%d,%d",&d,&a);
        if(d==0&&a==0)
            break;
        
        x+=d*sin(rada);
        y+=d*cos(rada);
        //printf("x:%lf y:%lf pre:%lf d:%lf\n",x,y,rada,cos(rada));
        rada=(rada+a*3.141592/180.0);
    }
    printf("%d\n",(int)x);
    printf("%d\n",(int)y);
    
    return 0;
}

Measured memory_bytes: 604
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<int, int> P;

int a[1001][1001];

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

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

  int ind[N+1];
  fill(ind, ind + N + 1, 0);
  set<P> st;
  queue<P> que;

  for(int i = 1; i <= N; i++){
    int mn = min(i, a[i][0]);
    int mx = max(i, a[i][0]);
    que.push(P(mn, mx));
  }

  int ans = 0;
  while(!st.empty() || !que.empty()){
    if(!st.empty() && que.empty()){
      cout << -1 << endl;
      return 0;
    }

    int sz = que.size();
    /*for(int i = 0; i < sz; i++){
      P p = que.front();
      cout << p.first <<  " " << p.second << endl;
      que.pop();
      que.push(p);
    }
    cout << endl;
    */

    ans++;
    for(int t = 0; t < sz; t++){
      P p = que.front(); que.pop();

      auto it = st.find(p);
      if(it != st.end()){
        st.erase(it);

        int mn = min(p.first, p.second);
        int mx = max(p.first, p.second);

        ind[mn]++;
        ind[mx]++;

        if(ind[mn] != N - 1){
          que.push(P(min(mn, a[mn][ind[mn]]), max(mn, a[mn][ind[mn]])));
        }
        if(ind[mx] != N - 1){
          que.push(P(min(mx, a[mx][ind[mx]]), max(mx, a[mx][ind[mx]])));
        }
      }
      else {
        st.insert(p);
      }
    }
  }

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

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;
typedef vector<int> vll;
ll gn;
void go(vll &v) {
	assert(v.size()==gn);
	ll sum=0;
	for (auto &w:v) sum+=w;
	assert(sum%6==0);
	for (auto &w:v) {
		assert(w%2==0||w%3==0);
	}
	bool has2=0,has3=0;
	for (auto &w:v) {
		if (w%6==0) continue;
		if (w%2==0) has2=true;
		else if (w%3==0) has3=true;
	}
	if (has2&&has3) {
		for (auto &w:v) printf("%lld ",w); printf("\n"); exit(0);
	}
}
void solve(long long N){
	if (N==3) {
		printf("2 5 63\n"); exit(0);
	}
	gn=N;
	vll v; vll pool;
	for (int x=1;x<=30000;x++) {
		if (x%2==0||x%3==0) {
			if (v.size()<N) v.PB(x);
			else pool.PB(x);
		}
	}
	ll sum=0; for (auto &w:v) sum+=w;
	sum%=6;
	if (sum==0) go(v);
	const int LIM=5;
	for (int a=0;a<min((int)v.size(),LIM);a++) {
			for (int c=0;c<min((int)pool.size(),LIM);c++) {
					ll ch=pool[c]-(v[a]);
					if ((sum+ch)%6==0) {
						vll newans;
						for (auto &w:v) {if (w!=v[a]) newans.PB(w);}
						newans.PB(pool[c]);
						go(newans);
					}
			}
	}
	for (int a=0;a<min((int)v.size(),LIM);a++) {
		for (int b=0;b<a;b++) {
			for (int c=0;c<min((int)pool.size(),LIM);c++) {
				for (int d=0;d<c;d++) {
					ll ch=pool[c]+pool[d]-(v[a]+v[b]);
					if ((sum+ch)%6==0) {
						vll newans;
						for (auto &w:v) {if (w!=v[a]&&w!=v[b]) newans.PB(w);}
						newans.PB(pool[c]); newans.PB(pool[d]);
						go(newans);
					}
				}
			}
		}
	}
	assert(0);
}

int main(){	
	ios_base::sync_with_stdio(false); cin.tie(0);
	long long N;
	scanf("%lld",&N);
	solve(N);
	return 0;
}



Measured memory_bytes: 640
import collections


def main():
    n = int(input())
    A = list(map(int, input().split()))

    A_count = collections.Counter(A)
    conv_all = sum([(A_c_i * (A_c_i-1))//2 for A_c_i in A_count.values()])

    for i in range(n):
        print(conv_all - A_count[A[i]] + 1)


if __name__ == "__main__":
    main()


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

using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    int N = S.size();
    int ans = 0;
    int a = 0, b = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] - '0' ^ i%2) {
            a++;
        }

        if(S[i] - '0' ^ (1 + i)%2) {
            b++;
        }
    }
    ans = min(a, b);
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main()
{
	string S;
	string first="",last="";

	cin >> S;

	int d1 = S[0] - '0';
	int d2 = S[1] - '0';
	int d3 = S[2] - '0';
	int d4 = S[3] - '0';

	int d12 = d1*10 + d2;
	int d34 = d3*10 + d4;




	if(d12 > 0 && d12 <= 12){
		first = "MM";
	}
	else
	{
		first = "YY";
	}

	if(d34 > 0 && d34 <= 12)
	{
		last = "MM";
	}
	else
	{
		last = "YY";
	}

	if(first == "MM" && last == "MM")
	{
		cout << "AMBIGUOUS" << endl;
	}
	else if(first == "YY" && last == "YY")
	{
		cout <<"NA" << endl;
	}
	else
	{
		cout << first  << last << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int height=sc.nextInt();
		int wide=sc.nextInt();
		int[][] matrix=new int[height][wide];
		int[] vector=new int[wide];

		//入力
		for(int i=0;i<height;i++){
			for(int j=0;j<wide;j++){
				matrix[i][j]=sc.nextInt();
			}
		}
		for(int i=0;i<wide;i++){
			vector[i]=sc.nextInt();
		}

		//計算
		int[] ans_ary=new int[height];
		for(int i=0;i<height;i++){
			for(int j=0;j<wide;j++){
				ans_ary[i]+=matrix[i][j]*vector[j];
			}
		}

		//出力
		for(int i=0;i<height;i++){
			System.out.println(ans_ary[i]);
		}
	}

}



Measured memory_bytes: 40328
#include<iostream>
#include<algorithm>

using namespace std;

int n, m, q, a, b, come[1050], used[1050][1050], res, ok[1050][1050];

int dfs(int s, int g, int cp){
	if(s == g)return 1;
	come[s] = 1;
	for(int i = 0;i <= n;i++){
		if(come[i])continue;
		if(used[s][i] <= cp)continue;
		//if(ok[s][i] < cp)continue;
		if(dfs(i, g, cp)){
			used[i][s]++;
			used[s][i]--;
			ok[s][i] = 0;
			return 1;
		}
	}
	return 0;
}

int flow(int s, int g, int cp = 0){
	fill(come, come + 1000, 0);
	return dfs(s, g, cp);
}


int main(){
	cin >> n >> m >> q;
	while(m--){
		cin >> a >> b;
		used[a][b] = used[b][a] = 1;
	}
	for(int i = 0;i < q;i++){
		cin >> m >> a >> b;
		if(m == 1){
			used[a][b] = used[b][a] = 1;
		}
		else{
			if(used[a][b] == 2){
				if(!flow(b, a))
				{
					flow(n, 1);
					flow(b, a);
					res--;	
				}
			}
			else if(used[b][a] == 2){
				if(!flow(a, b)){
					flow(n, 1);
					flow(a, b);
					res--;
				}
			}		
			used[a][b] = used[b][a] = 0;
		}
		while(flow(1, n))res++;
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 9380
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <deque>

using namespace std;

#define FOR(i, start, end) for(ll i = (start); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ctoi(c) c - '0'
#define tos(s) to_string(s)

typedef long long ll;

int main() {
    int n,x,t;
    cin >> n >> x >> t;
    if (n%x ==0) {
        cout << n/x*t << endl;
    } else {
        cout << (n/x+1)*t << endl;
    }
    return 0;
}

/*
ACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACAC                                                                              
                                   ******,  .,, .,, ,,,    ****.**              
                                   ** . .,,,,,,,,,,,,,,,,,,,,,. .,*             
                                   **,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.            
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                    ****      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,      
              ***************,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,    
         ********************,,,,,,,,,,,,,,@@@,,,,,,,,,,,/@@@,,,,,,,,,,,,,,,    
        ******************,,,,,,,,,,,,,,,,,,(,,.         ,,,,,,,,,,,,,,,,,,,    
       ********************,,,,,,,,,,,*,,,,,.     %&&&     .,,,,*,,,,,,,,,,,,.  
       ***,,,,,,,,,,,,,,*,,,,,,,,,,,,,,,,,,,,               ,,,,,,,,,,,,,,,,,   
       ,,,,,,,,,,,,,,,,,,,**,,,,,,,,,,.......      ##(     ........,,,,,,,,,,.  
     .,,,,,,,,,,,,,,,,,,**,,,,,,,,,,..............    ..............,,,,,,,,    
    .,,,,,,,,,,,,,,,,,,,**,,,,,,,,,.................................,,,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,***,,,,,,,....................................,,,,,,,,,  
   ,,,,,,,,,,,,,,,,,,,,**,,,,,,,,.....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,**,,,,,,,,....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,,,     
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,.,,,,,     
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,        
     ,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................................,,,        
      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,          
       ..,,,,,,,,,,,,,,,,,,,,,,,,,,.................................,           
       .........**.....       ,,,,,..............................               
        .......*......                  ****,**,       ,..****                  
        .......*,....                   .......        ......                   
          .......*....                   .....          .....                   
                                         ......          .....                  
*/

Measured memory_bytes: 3160
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
const int INF = 1e10;
const long double PI = (acos(-1));


signed main() {
	int N;
	cin >> N;
	vector<P>v(N);
	rep(i, N) {
		int X, L;
		cin >> X >> L;
		v[i] = make_pair(X + L, X - L);
	}
	sort(v.begin(), v.end());
	int l, r;
	int ans = 1;
	for (int i = 0; i < N; i++) {
		if (!i)r = v[i].first;
		else {
			l = v[i].second;
			if (l < r)continue;
			else {
				r = v[i].first;
				ans++;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 1792
use std::io::*;
use std::str::FromStr;
use std::cmp::max;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u64> = (0..n).map(|_| 0).collect();
    let mut b: Vec<u64> = (0..n).map(|_| 0).collect();
    let mut c: Vec<u64> = (0..n).map(|_| 0).collect();
    let m = n + 1;
    let mut dp: Vec<Vec<u64>> = (0..m).map(|_| (0..3).map(|_| 0).collect()).collect();
    for i in 0..n {
        a[i] = read();
        b[i] = read();
        c[i] = read();
    }

    for i in 0..n {
        dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i];
        dp[i + 1][1] = max(dp[i][2], dp[i][0]) + b[i];
        dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c[i];
    }

    println!("{}", max(max(dp[n][0], dp[n][1]), dp[n][2]));
}


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

int c[50][50];
int w, h;

void dfs(int x, int y) {
  c[y][x] = 0;
  for (int i = -1; i <= 1; i++) {
    for (int j = -1; j <= 1; j++) {
      int nx = x + i;
      int ny = y + j;
      if (c[ny][nx] == 1 && 0 <= nx && nx < w && 0 <= ny && ny < h)
	dfs(nx, ny);
    }
  }
}

int search() {
  int count = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (c[i][j] == 1) {
	dfs(j, i);
	count++;
      }
    }
  }
  return count;
}

int main() {
  while (true) {
    cin >> w >> h;
    if (w == 0 && h == 0) return 0;

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

    int ans = search();
    cout << ans << endl;
  }
}

Measured memory_bytes: 3268