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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;

    cin >> n >> k;

    V<ll> table;
    ll cumSum[n];
    ll a;
    ll bits = 0;
    ll mask;
    int counter;

    cin >> a;

    table.pb(a);
    cumSum[0] = a;

    int i, j, len;

    repi(i, n, 1) {
        cin >> a;

        cumSum[i] = cumSum[i - 1] + a;
        table.pb(cumSum[i]);
    }

    repi(i, n, 1) repi(j, n, i) table.pb(cumSum[j] - cumSum[i - 1]);

    len = table.size();
    nep(i, 41) {
        mask = 1LL << i;
        bits += mask;
        counter = 0;

        rep(j, len) if ((table[j] & bits) == bits) counter++;

        if (counter < k) bits -= mask;
    }

    Out(bits);

    return 0;
}


Measured memory_bytes: 6384
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String s = sc.next();
			
			boolean flag = true;
			int max = 1;
			int i = 3;
			int count = 0;
			String ans = "egg";
			
			if(s.charAt(0)=='c'){
				ans = "chicken";
				flag = false;
				i=7;
			}
			
			while(i<s.length()){
				count++;
				if(s.charAt(i)=='e' && flag==false){
					flag = true;
					i+=3;
				}else if(s.charAt(i)=='c' && flag==true){
					flag = false;
					i+=7;
				}else if(s.charAt(i)=='e' && flag==true){
					if(max<count){
						max = count;
						ans = "egg";
					}
					i+=3;
					count=0;
				}else if(s.charAt(i)=='c' && flag==false){
					if(max<count){
						max = count;
						ans = "chicken";
					}
					i+=7;
					count=0;
				}	
			}
			count++;
			
			if(flag==true) i-=3;
			else if(flag==false) i-=7;
			
			if(s.charAt(i)=='e' && max<count) ans = "egg";
			else if(s.charAt(i)=='c' && max<count) ans = "chicken";

			System.out.println(ans);
		}
	}	
}

Measured memory_bytes: 20308
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<x86intrin.h>
#include<math.h>

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nBuf,int N){
    char *buf,*ptr;

    buf=(char*)malloc(nBuf*sizeof(char));
    my_gets(buf,nBuf,stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}
#define MAX(a,b) ( ((a)>(b)) ? (a):(b) )

int64_t div_fl(int64_t B, int64_t r){
    return B/r;
}

int64_t div_ce(int64_t A, int64_t r){
    return (A%r == 0)?(A/r): ((A/r)+1);
}

int64_t my_gcd(int64_t A, int64_t B){
    return (B==0)?(A):(my_gcd(B,A%B));
}

int64_t my_lcm(int64_t A, int64_t B){
    return A*(B/my_gcd(A,B));
}

int64_t my_cnt(int64_t A, int64_t B, int64_t r){
    return div_fl(B,r) - div_ce(A,r) + (1ll);
}

int main(){
    int64_t A,B,C,D,E;

    scanf("%lld %lld %lld %lld%*c",&A,&B,&C,&D);

    E=my_lcm(C,D);

    printf("%lld\n", my_cnt(A,B,1)-my_cnt(A,B,C)-my_cnt(A,B,D)+my_cnt(A,B,E));
    
    return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
from sys import stdin

ns = lambda: stdin.readline()[:-1] # s = ns()
ni = lambda: int(stdin.readline()) # N = ni()
na = lambda: list(map(int, stdin.readline().split())) # Arr = na()

H, W = na()
Grid = []
for _ in range(H):
    s = ns()
    if '#' in s:
        Grid.append(list(s))

h = len(Grid)
res = []
for i in range(W):
    s = ''
    for j in range(h):
        s += Grid[j][i]
    if '#' in s:
        res.append(s)

for i in range(len(res[0])):
    s = ''
    for j in range(len(res)):
        s += res[j][i]
    print(s)



Measured memory_bytes: 3188
X,N = map(int,input().split())
P = list(map(int,input().split()))
move = 0
discover = True
while discover:
    nowdis = True
    for i in range(0,N):
        if P[i] == X + move:
            nowdis = False
    if nowdis == True:
        discover = False
        print(X + move)
    if move >= 0:
        move = (-1) * move - 1
    else:
        move = (-1) * move
     

Measured memory_bytes: 9188
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.IOException;

public class Main {

    public static void main(String args[]) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        String input;
        while (!(input = br.readLine()).equals("0 0")) {
            String[] st = input.split(" ");
            int y = Integer.parseInt(st[0]);
            int x = Integer.parseInt(st[1]);
            for (int i = 0; i < y; i++) {
                for (int j = 0; j < x; j++) {
                    bw.append("#");
                }
                bw.newLine();
            }
            bw.newLine();
        }
        bw.flush();
    }


}


Measured memory_bytes: 26132
n = int(input())
A = list(map(int,input().split()))

cnt = 0
A_ = []
for i in A:
    if i < 0:
        cnt += 1
        A_.append(-i)
    else:
        A_.append(i)

if cnt%2 == 0:
    print(sum(A_))
else:
    print(sum(A_) - 2*min(A_))
    

Measured memory_bytes: 20136
n,m = map(int,raw_input().split())
gyoretu = []
bekutoru = []
for i in range(n):
    gyoretu.append(map(int,raw_input().split()))
for i in range(m):
    bekutoru.append(input())

for a in gyoretu:
    i = 0
    for b in range(len(bekutoru)):
        i = i + (a[b] * bekutoru[b])
    print i

Measured memory_bytes: 4564
#include <iostream>
#include <cmath>
#include <map>
using namespace std;

int main() {
    int N, M, s, c, ans = 0;
    map<int, int> m;
    cin >> N >> M;
    
    while (M--) {
        cin >> s >> c;
        
        if (m.count(s)) {
            if (m[s] != c) {
                cout << "-1" << endl;
                return 0;
            } else {
                continue;
            }
        }
        
        m.insert(make_pair(s, c));
        ans += c * (int) (pow(10, N - s));
    }

    if (N > 1 && m.count(1) && m[1] == 0) {
        cout << "-1" << endl;
        return 0;
    }
    if (N > 1 && !m.count(1)) {
        ans += 1 * (int) (pow(10, N - 1));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main(void){
    // Your code here!
    int s, w;
    cin >> s >> w;
    if(w >= s){cout << "unsafe";}
    else {cout << "safe";}
    return 0;
}


Measured memory_bytes: 3616
n,m = map(int,input().split())

p = [True for _ in range(n+1)]

p[0] = 1
p[1] = 1

for _ in range(m):
    a = int(input())
    p[a] = False

for i in range(2,n+1):
    if p[i] == False:
        p[i] = 0
    else:
        p[i] = p[i-1] + p[i-2]

print(p[n]%(10**9+7))

Measured memory_bytes: 460056
a=list(input())
b=list(input())
a=a+a

if len(a)/2!=len(b):
  print("No")
else:
    for i in range(len(b)):
        if b==a[i:i+len(b)]:
            print("Yes")
            break
        if i==len(b)-1:
            print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>

#define INPUT_FROM_FILE (0)
#if INPUT_FROM_FILE
#include <fstream>
#endif

#define ROOT (0)
#define INTERNAL_NODE (1)
#define LEAF (2)

class Node{
public:
	int parent;
	int left;
	int right;

	Node() : parent(-1), left(-1), right(-1){
		return;
	}

	~Node(){
		return;
	}

	int get_type(){
		if(parent == -1){
			return ROOT;
		}
		else if(left != -1 || right != -1){
			return INTERNAL_NODE;
		}
		else{
			return LEAF;
		}
	}

};

int calc_depth(const std::vector<Node> &nodes, int i){
	int d = 0;
	int n = nodes[i].parent;

	while(n != -1){
		n = nodes[n].parent;
		d++;
	}
	return d;
}

int calc_height(const std::vector<Node> &nodes, int i){
	int lh = 0;
	int rh = 0;
	int lid = nodes[i].left;
	int rid = nodes[i].right;

	if(lid == -1 && rid == -1){
		return 0;
	}
	if(lid >= 0){
		lh += calc_height(nodes, lid) + 1;
	}
	if(rid >= 0){
		rh += calc_height(nodes, rid) + 1;
	}

	return lh > rh ? lh : rh;
}

int get_siling(const std::vector<Node> &nodes, int i){
	int pid = nodes[i].parent;
	int lid = -1;
	int rid = -1;

	if(pid == -1){
		return -1;
	}
	lid = nodes[pid].left;
	rid = nodes[pid].right;

	if(lid != i){
		return lid;
	}
	else{
		return rid;
	}
}

int get_degree(const std::vector<Node> &nodes, int i){
	int d = 0;
	if(nodes[i].left >= 0){
		d++;
	}
	if(nodes[i].right >= 0){
		d++;
	}
	return d;
}

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	int n = 0;
	std::vector<Node> node_vec;
	int height = 0;

#if INPUT_FROM_FILE
	ifs >> n;
#else
	std::cin >> n;
#endif

	node_vec.resize(n);

	for(int i = 0; i < n; i++){
		int id = -1;
		int left = -1;
		int right = -1;

#if INPUT_FROM_FILE
		ifs >> id >> left >> right;
#else
		std::cin >> id >> left >> right;
#endif
		node_vec[id].left = left;
		node_vec[id].right = right;
		
		if(left >= 0){
			node_vec[left].parent = id;
		}
		if(right >= 0){
			node_vec[right].parent = id;
		}
	}

	
	for(unsigned int i = 0; i < node_vec.size(); i++){
		std::cout << "node " << i << ": ";
		
		std::cout << "parent = " << node_vec[i].parent << ", ";

		std::cout << "sibling = " << get_siling(node_vec, i) << ", ";

		std::cout << "degree = " << get_degree(node_vec, i) << ", ";

		std::cout << "depth = " << calc_depth(node_vec, i) << ", ";

		std::cout << "height = " << calc_height(node_vec, i) << ", ";

		if(node_vec[i].get_type() == ROOT){
			std::cout << "root";
		}
		else if(node_vec[i].get_type() == INTERNAL_NODE){
			std::cout << "internal node";
		}
		else{
			std::cout << "leaf";
		}
		std::cout << std::endl;

	}

	return 0;
}


Measured memory_bytes: 3108
using System;

namespace ALDS1_4_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            int N = int.Parse(input);
            int[] reference = new int[N + 1];

            input = Console.ReadLine();
            string[] ref_st = input.Split(' ');
            for (int i = 0; i < N; i++)
            {
                reference[i] = int.Parse(ref_st[i]);
            }

            input = Console.ReadLine();
            int q = int.Parse(input);
            int[] analyte = new int[q];

            input = Console.ReadLine();
            string[] ana_st = input.Split(' ');
            for (int i = 0; i < q; i++)
            {
                analyte[i] = int.Parse(ana_st[i]);
            }
            int count = 0;
            int p = 0;
            for (int i = 0; i < q; i++)
            {
                reference[N] = analyte[i];
                p = 0;
                while (reference[p] != analyte[i])
                {
                    p++;
                }
                if (p != N) count++;
            }

            Console.WriteLine(count);
        }
    }
}

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

int main(){

  int S, i=1, ans=0;
  cin >> S;
  int A[1000000];
  A[0] = S;
  bool uuu = true;

  while(uuu){
    A[i] = A[i-1]%2==0 ? A[i-1]/2 : A[i-1]*3 + 1;

    for(int j=0; j<i; j++){
      if(A[i] == A[j]) ans = i;
    }
    i++;
    if(ans!=0) break;
  }

  cout << ans+1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>

using namespace std;
#define long long int
int32_t main()
{
	int i,j,k,l,x,y,z;
	string s;
	int N;
	int S[1<<18];
	cin>>N;
	for(int i=0;i<(1<<N);i++)
		cin>>S[i];
	sort(S,S+(1<<N));
	multiset<int> T;
	for(int i=0;i<(1<<N)-1;i++)
		T.insert(S[i]);

	vector<int> V;
	V.push_back(S[(1<<N)-1]);
	for(int i=0;i<N;i++)
	{
		vector<int> W=V;
		for(int i=0;i<V.size();i++)
		{
			auto it=T.lower_bound(V[i]);
			if(it==T.begin())
			{
				cout<<"No"<<endl;
				return 0;
			}
			it--;

			W.push_back(*it);
			T.erase(it);
		}
		sort(W.begin(),W.end());
		reverse(W.begin(),W.end());
		swap(W,V);
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 13568
//Radhe Radhe
#include<bits/stdc++.h>
#define godspeed  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define ll long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define rep1(i,a,b)    for(ll i=a; i<=b; i++)
#define repVect(i,n)    for(ll i=0; i<sum.size(); i++)
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n';
#define no cout<<"No"<<'\n';
using namespace std;

int main()
{
    godspeed
    ll  t,i,x,j,k,n,ans=0,cnt=0;
    string s;
    cin>>s;
    for(i=0; s[i]; i++)
    {
        if(s[i]=='B')
        {
            cnt++;
        }
        else
        {
            ans+=cnt;
        }
    }

    cout<<ans<<endl;

    return 0;
}





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

using namespace std;

class Node {
  bool is_root = false;

 public:
  Node* left = nullptr;
  Node* right = nullptr;
  int value;

  Node(int value, bool is_root)
    :is_root{is_root}, value{value} {}

  bool find(int target) {
    if (target == value) return true;
    else if (target < value and left)
      return left->find(target);
    else if (target > value and right)
      return right->find(target);
    return false;
  }

  void add(int new_value) {
    if (new_value > value) {
      if (!right) {
        right = new Node(new_value, false);
      } else {
        right->add(new_value);
      }
    } else {
      if (!left) {
        left = new Node(new_value, false);
      } else {
        left->add(new_value);
      }
    }
  }

  void remove(int target, Node *parent) {
    if ((target > value and !right) || (target < value and !left)) {
      return;
    } else if (target > value) {
      right->remove(target, this);
    } else if (target < value) {
      left->remove(target, this);
    } else {
      if (!right and !left) {
        ((this == parent->right) ? (parent->right) : (parent->left)) = nullptr;
        delete this;
      } else if ((right and not left) or (left and not right)) {
        ((this == parent->right) ? (parent->right) : (parent->left)) = (right ? right : left);
        delete this;
      } else {
        Node *successor = right;
        Node *successor_parent = right;
        if (!right->left) {
          value = right->value;
          auto tmp = right->right;
          delete right;
          right = tmp;
        } else {
          while (successor->left) {
            successor_parent = successor;
            successor = successor->left;
          }
          value = successor->value;
          successor_parent->left = successor->right;
          delete successor;
        }
      }
    }
  }

  void print_preorder() {
    if (!is_root) cout << ' ' << value;
    if (left) left->print_preorder();
    if (right) right->print_preorder();
  }

  void print_inorder() {
    if (left) left->print_inorder();
    if (!is_root) cout << ' ' << value;
    if (right) right->print_inorder();
  }
};

int main() {
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  string line;
  Node *root = new Node(-2000000001, true);
  while (getline(cin, line)) {
    if (line.substr(0, 4) == "find") {
      cout << (root->find(stoi(line.substr(5))) ? "yes\n" : "no\n");
    } else if (line.substr(0, 6) == "insert") {
      root->add(stoi(line.substr(7)));
    } else if (line.substr(0, 6) == "delete") {
      root->remove(stoi(line.substr(7)), root);
    } else { // print
      root->print_inorder();
      cout << endl;
      root->print_preorder();
      cout << endl;
    }
  }
}


Measured memory_bytes: 21924
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dat[1000000];
ll u;
ll inf=1000000000000000001;
ll mod=1000000007;
void add(ll n,ll x){
  ll i=n+u-1;
  dat[i]=x;
  while(i>0){
    i=(i-1)/2;
    dat[i]=min(dat[2*i+1],dat[2*i+2]);
  }
}
ll que(ll a,ll b,ll k,ll l,ll r){
  if(a>=r||b<=l)return inf;
  if(a<=l&&b>=r)return dat[k];
  ll m1=que(a,b,2*k+1,l,(l+r)/2);
  ll m2=que(a,b,2*k+2,(l+r)/2,r);
  return min(m1,m2);
}
int main(){
  fill(dat,dat+1000000,inf);
  ll n,a,b;cin>>n>>a>>b;
  vector<ll> s(n);
  for(ll i=0;i<n;i++)cin>>s[i];
  for(ll i=0;;i++){
    ll e=pow(2,i);
    if(e>=n-1){
      u=e;
      break;
    }
  }
  for(ll i=0;i<n-1;i++){
    add(i,s[i+1]-s[i]);
  }
  ll dp1[n],dp2[n];
  fill(dp1,dp1+n,0);
  fill(dp2,dp2+n,0);
  dp1[0]=1;
  dp2[0]=1;
  for(ll i=1;i<n;i++){
    ll t=upper_bound(s.begin(),s.end(),s[i]-a)-s.begin();
    if(t==0){
      if(i==1){
        dp1[i]=1;
      }
      else{
        ll r=que(0,i-1,0,0,u);
        if(r>=b)dp1[i]=1;
      }
    }
    else{
      if(t==i){
        dp1[i]+=dp1[t-1];
        dp1[i]%=mod;
        dp1[i]+=dp2[t-1];
        dp1[i]%=mod;
      }
      else if(t==i-1){
        dp1[i]+=dp2[t];
        dp1[i]%=mod;
        //if(s[i-1]-s[i-2]>=b)dp1[i]+=dp2[t-1];
        //dp1[i]%=mod;
      }
      else{
        //ll f=que(t-1,i-1,0,0,u);
        ll g=que(t,i-1,0,0,u);
        //if(f>=b)dp1[i]+=dp2[t-1];
        //dp1[i]%=mod;
        if(g>=b)dp1[i]+=dp2[t];
        dp1[i]%=mod;
      }
    }
    ll tt=upper_bound(s.begin(),s.end(),s[i]-b)-s.begin();
    //if(i==3)cout<<tt<<endl;
    if(tt==0){
      if(i==1){
        dp2[i]=1;
      }
      else{
        ll r=que(0,i-1,0,0,u);
        if(r>=a)dp2[i]=1;
      }
    }
    else{
      if(tt==i){
        dp2[i]+=dp1[tt-1];
        dp2[i]%=mod;
        dp2[i]+=dp2[tt-1];
        dp2[i]%=mod;
      }
      else if(tt==i-1){
        dp2[i]+=dp1[tt];
        dp2[i]%=mod;
        //if(s[i-1]-s[i-2]>=a)dp2[i]+=dp1[tt-1];
        //dp2[i]%=mod;
      }
      else{
        //ll f=que(tt-1,i-1,0,0,u);
        ll g=que(tt,i-1,0,0,u);
        //if(f>=a)dp2[i]+=dp1[tt-1];
        //dp2[i]%=mod;
        if(g>=a)dp2[i]+=dp1[tt];
        dp2[i]%=mod;
      }
    }
  }
  
  ll ans=dp1[n-1]+dp2[n-1];
  cout<<ans%mod<<endl;
}

Measured memory_bytes: 10368
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////
vector< vector<pair<int, int>>> G;
vector<int> C;

void dfs(int u,int L) {
	if (C[u] != -1) return;
	if (L % 2 == 0) {
		C[u] = 0;
	}
	else {
		C[u] = 1;
	}
	for (auto v : G[u]) {
		dfs(v.first, L + v.second);
	}
}
void solve() {
	int N;
	cin >> N;
	G = vector< vector<pair<int, int>>>(N);
	C = vector<int>(N, -1);
	for (int i = 0; i < N - 1; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		--u; --v;
		G[u].emplace_back(pair<int, int>(v, w));
		G[v].emplace_back(pair<int, int>(u, w));
	}
	dfs(0,0);
	for (int i = 0; i < N; ++i) {
		cout << C[i] << endl;
	}
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 7424
#include<iostream>
#include<cmath>
using namespace std;
int main(){
 int a,b,c,d;
   cin >>a>>b>>c>>d;
   if(abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d)){
       cout<<"Yes";
   }
   else cout<<"No";
 return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 3e5;
const ll bits = 20;
const ld pi = 3.14159265358979323846;
const ll mod = 1e9+7;
const ll p = 29;


int main(){

    FASTIO;
    PRECISION; 

    ll n,p;
    cin>>n>>p;
    string s;
    cin>>s;
    ll ans = 0;
    if(p==2||p==5){
        for(ll i=0;i<n;i++){
            ll dig = s[i]-'0';
            if(dig%p==0){
                ans+=i+1LL;
            }
        }
    }else{
        map<ll,ll>dp;
        dp[0] = 1;
        ll sum = 0;
        ll ft = 1;
        for(ll i=n-1;i>=0;i--){
            ll dig = s[i]-'0';
            sum = (dig*ft + sum)%p;
            ans+=dp[sum];
            dp[sum]++;
            ft = (ft*10LL)%p;
        }
    }

    cout<<ans<<"\n";

}


Measured memory_bytes: 1044
#include<stdio.h>
#include<stdlib.h>

 int main(void)
 {
     char s[10];
     int num[10];
     int n,count = 0;

    scanf("%s",s);

    for(int i=0; s[i] != '\0' ;i++)
    {
        num[i] = s[i] - '0';
        count++;
    }

    n = abs((num[0]*100 + num[1]*10 + num[2])-753);

    for(int i=1; i < count-2 ;i++)
    {
        if(abs((num[i]*100+num[i+1]*10+num[i+2])-753) < n)
            n= abs((num[i]*100+num[i+1]*10+num[i+2])-753);
    }

    printf("%d",n);

     return 0;
 }

Measured memory_bytes: 128
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]


s,t=input(),input()
q=int(input())
abcd=[list(map(int,input().split())) for i in range(q)]

scnt=[(0,0)]*(len(s)+1)
tcnt=[(0,0)]*(len(t)+1)
for i in range(len(s)):
    a,b=scnt[i]
    if s[i]=="A":
        a+=1
    else:
        b+=1
    scnt[i+1]=(a,b)
for i in range(len(t)):
    a,b=tcnt[i]
    if t[i]=="A":
        a+=1
    else:
        b+=1
    tcnt[i+1]=(a,b)
# print(scnt)
# print(tcnt)

for i in range(q):
    a,b,c,d=abcd[i]
    sa,sb=scnt[b],scnt[a-1]
    sa,sb=sa[0]-sb[0],sa[1]-sb[1]
    ta,tb=tcnt[d],tcnt[c-1]
    ta,tb=ta[0]-tb[0],ta[1]-tb[1]
    # print(sa,sb,ta,tb)

    if abs((sa-sb)-(ta-tb))%3==0:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 98692
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int x[101];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, i;
    cin >> n;
    rep(i, n) {
        cin >> x[i];
    }
    int j;
    int ans = INF;
    xrep(i, 1, 101) {
        int tmp = 0;
        rep(j, n) {
            tmp += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map>       // pair
#include <string>
#include <stdio.h>
#include <numeric>
using namespace std;

int main(int argc, const char *argv[])
{   
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i ++)
    {
        cin>>A[i];
    }

   for(int i = 0; i < N-1 ; i ++)
   {
       if((A[i] < 0) && (A[i+1<0]))
       {
           A[i] = -1 * A[i];
           A[i + 1] = -1 *A[i+1];
       }
   }

   int count = 0;

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

   sort(A.begin(), A.end(), std::greater<int>());

   long long sum = 0;
   for(int i = 0; i < N  ; i ++)
   {    
       if(i < N - count)
   {
       sum += (long long)(A[i]);
   }
   else
   {
       sum -= (long long)(A[i]);
   }
   
   }
    cout<<sum;

       return 0;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll dx[] = { 1, 0 , -1,  0 }, dy[] = { 0, 1, 0, -1 };
ll cb(ll a, ll b);
void dfs(ll x, ll y, ll z);
vector<vector<ll>> c(10, vector<ll>(10));
vector<ll> r(10, mod);

int main() {
	ll h, w;
	cin >> h >> w;
	vector<vector<ll>> a(h, vector<ll>(w));

	rep(i, 10) {
		rep(j, 10) {
			cin >> c[i][j];
		}
	}

	rep(i, 10) {
		dfs(i, i, 0);
	}

	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
		}
	}

	ll ans = 0;

	rep(i, h) {
		rep(j, w) {
			if (a[i][j] != -1) ans += r[a[i][j]];
		}
	}


	cout << ans;

	return 0;
}

void dfs(ll x, ll y, ll z) {
	rep(i, 10) {
		if (r[x] >= c[y][i] + z) {
			if (i == 1)	r[x] = min(r[x], c[y][1] + z);
			else if (i == y) continue;
			else dfs(x, i, c[y][i] + z);
		}
	}
	return;
}


ll cb(ll a, ll b) {
	ll ans = 1;
	rep(i, b) ans *= (a - i);
	rep(i, b) ans /= (b - i);

	return ans;
}

ll gcd(ll a, ll b) {
	if (a % b == 0)return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

Measured memory_bytes: 3896
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    long long n,a[200],i,j,k,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<=n-2;i++)
    {
        for(j=i+1;j<=n-1;j++)
        {
            for(k=j+1;k<=n;k++)
            {
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
                {
                    if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i])
                    {
                        s++;
                    }
                }
            }
        }
    }
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n;
  cin>>n;
  vector<vector<ll>> activity(n,
    vector<ll>(3,0));
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < 3; ++j)
    {
      cin>>activity[i][j];
    }
  }
  vector<vector<ll>> dp(n+1,
    vector<ll>(3,0));

  for (int i = 1; i < dp.size(); ++i)
  {
    for (int j = 0; j < 3; ++j)
    {
      for (int k = 0; k < 3; ++k)
      {
        if(j==k) continue;
        dp[i][j]=max(dp[i][j],
          dp[i-1][k]+activity[i-1][j]);
      }
    }
  }

  cout<<*max_element(dp[n].begin(), dp[n].end())<<endl;

}

Measured memory_bytes: 14056
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define loop(k) rep(author_is_masa,k)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/


signed main(){
	int h,w;
	cin>>h>>w;
	string s[303];
	rep(i,h)cin>>s[i];

	vi cnti(h,0),cntj(w,0);

	rep(i,h){
		rep(j,w){
			cnti[i]+=s[i][j]=='#';
			cntj[j]+=s[i][j]=='#';
		}
	}
	rep(i,h){
		if(cnti[i]==0) continue;
		rep(j,w){

			if(cntj[j]==0) continue;

			cout<<s[i][j];
		}
		cout<<endl;
	}




	return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>

int main()
{
  int a, b, c, x, y;
  std::cin >> a >>  b >> c >> x >> y;
  if(a+b < c*2)
  {
    std::cout << a*x+b*y << std::endl;
    return 0;
  }

  int cost = 0;
  int num_share = std::min(x, y);
  cost += num_share*c*2;
  if(x-y>0)
  {
    cost += std::min((x-y)*a, (x-y)*c*2);
  }
  else
  {
    cost += std::min((y-x)*b, (y-x)*c*2);
  }
  std::cout << cost << std::endl;
  // int num_para = std::abs(x-y);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
long long x[1100];
long long y[1100];
long long z[1100];

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	for(int i=0;i<a;i++)scanf("%lld",x+i);
	for(int i=0;i<b;i++)scanf("%lld",y+i);
	for(int i=0;i<c;i++)scanf("%lld",z+i);
	std::sort(x,x+a);
	std::sort(y,y+b);
	std::sort(z,z+c);
	priority_queue<pair<long long,int> > Q;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		Q.push(make_pair(x[i]+y[j]+z[c-1],c-1));
	}
	for(int i=0;i<d;i++){
		pair<long long,int> at=Q.top();
		Q.pop();
		printf("%lld\n",at.first);
		if(at.second){
			at.first-=z[at.second];
			at.first+=z[at.second-1];
			at.second--;
			Q.push(at);
		}
	}
}


Measured memory_bytes: 18664
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define pii pair<ll,ll>
#define piii pair<pii, int>
#define pb push_back
#define fs first
#define sc second
#define ppb pop_back
//#define LOCAL
//#define endl "\n"
#define d0(x) cout<<x<<" "
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define d5(x,y,z,w,s) cout<<x<<" "<<y<<" "<<z<<" "<<w<<" "<<s<<endl
#define fifo ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll mod = 998244353;



int a[501][501],n;bool b[501][501];


void dfs(int i,int j,int y);

void dfs1(int i,int j,int x)
{
	if(i<0||j<0||i==n||j==n)
		return;
	if(a[i][j]<=x)
		return;
	a[i][j]=x;
	dfs(i,j,x+b[i][j]);
}

void dfs(int i,int j,int y)
{
	//cout<<i<<" "<<j<<endl;
	//int y=a[i][j]+1;
	dfs1(i+1,j,y);
	dfs1(i-1,j,y);
	dfs1(i,j+1,y);
	dfs1(i,j-1,y);
}

void solve()
{
	cin>>n;

	int ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			a[i][j] = min(min(i,j),min(n-1-i,n-1-j));
			b[i][j] = 1;
		}

	for(int i=0;i<n*n;i++)
	{
		int x;cin>>x;x--;
		//cout<<i<<endl;
		int i1=x/n;int j1=x%n;
		b[i1][j1]=0;
		ans+=a[i1][j1];
		dfs(i1,j1,a[i1][j1]);
	}

	cout<<ans<<endl;
}

int main()
{
	fifo
	int t=1;
	//cin>>t;
	for(int test_case=1;test_case<=t;++test_case)
	{
		solve();
	}
}


Measured memory_bytes: 12348
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);
#define rad2deg(a) ((a)/M_PI * 180.0)
#define deg2rad(a) ((a)/180.0 * M_PI)
const std::string yes = "Yes";
const std::string no  = "No";


int main(){
    int x;
    std::cin >> x;
    if(x>=30) std::cout << yes << "\n";
    else std::cout << no << "\n";
    return 0;
}

Measured memory_bytes: 3620
S=input()
ans=0
cnt=0
for i in range(len(S)):
    if(S[i]=='A' or S[i]=='C' or S[i]=='G' or S[i]=='T'):
        cnt+=1
    else:
        ans=max(cnt,ans)
        cnt=0
    ans=max(cnt,ans)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n, m; cin >> n >> m;
      vector<string> a(n), b(n);
      for (int i = 0; i < n; ++i) cin >> a[i];
      for (int i = 0; i < m; ++i) cin >> b[i];
      
      for (int i = 0; i <= n - m; ++i)
        for (int j = 0; j <= n - m; ++j)
        {
          bool f = true;
          for (int s = 0; s < m && f; ++s)
            for (int t = 0; t < m && f; ++t)
              if (a[i + s][j + t] != b[s][t])
                f = false;
          
          if (f) {
            cout << "Yes" << endl;
            return 0;
          }
        }
      
      cout << "No" << endl;
    }

Measured memory_bytes: 256
#include<iostream>  
#include<queue>  
#include<vector>  
#include<cmath>  
#include<algorithm>  
#include<cstring>
using namespace std;  
const int N=150;  
int line[N][N];
int girl[N],used[N],a[N][3],b[N][3];  
int n;  
bool found(int x)  
{  
    for(int i=1; i<=n; i++)  
    {  
        if(line[x][i]&&!used[i])  
        {  
            used[i]=1;  
            if(!girl[i]||found(girl[i]))  
            {  
                girl[i]=x;  
                return 1;  
            }  
        }  
    }  
    return 0;  
}  
int main()  
{  
        scanf("%d",&n);  
        memset(line,0,sizeof(line));  
        memset(girl,0,sizeof(girl));
		for(int i=1;i<=n;i++){
			scanf("%d %d",&a[i][0],&a[i][1]);
		} 
        for(int i=1; i<=n; i++)  
        {  scanf("%d %d",&b[i][0],&b[i][1]);
            for(int j=1;j<=n;j++){
            	if(a[j][0]<b[i][0]&&a[j][1]<b[i][1])line[i][j]=1;
			}
        }
        int sum=0;  
        for(int i=1; i<=n; i++)  
        {
            memset(used,0,sizeof(used));  
            if(found(i))sum++;  
        }  
        printf("%d\n",sum);  
    return 0;  
}  

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

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

    int ans = 0;
    for(char c = '0'; c <= '9'; c++) {
        size_t posc = s.find(c);
        if(posc == string::npos || n-2 < posc) continue;
        for(char d = '0'; d <= '9'; d++) {
            size_t posd = s.find(d, posc + 1);
            if(posd == string::npos || n-1 < posd) continue;
            for(char e = '0'; e <= '9'; e++) {
                size_t pose = s.find(e, posd + 1);
                if(pose == string::npos) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3684
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////

ll a,b;

int main(){

    cin >> a >> b;

    ll x = a,y = b;
    ll z = lcm(a,b);
    while(x <= z){
        x += a;
        if(x%b != 0){
            P(x);
            ret 0;
        }
    }
    P(-1);
	
	return  0;
}

Measured memory_bytes: 256
// 無向グラフにしてある.
#include <bits/stdc++.h>
using namespace std;

/* define const */
const int Nmax = 100;
const int M = 10000;
/* finish defineing const */

int graph[Nmax+10][Nmax+10];
int g_tmp[Nmax+10][Nmax+10];
int a[1110];
int b[1110];
int c[1110];
int n,m;

int main()
{
  for (int i = 0; i < Nmax+10; i++) {
    for (int j = 0; j < Nmax+10; j++) {
      if (i != j) {
	graph[i][j] = M;
	g_tmp[i][j] = M;
      }
      else {
	graph[i][j] = 0;
	g_tmp[i][j] = 0;
      }
    }
  }
  // finish initialization   
  
  cin >> n >> m;
  for (int i = 1; i <= m; i++) cin >> a[i] >> b[i] >> c[i];
  for (int i = 1; i <= m; i++) {
    graph[a[i]][b[i]] = c[i];
    g_tmp[a[i]][b[i]] = c[i];
    graph[b[i]][a[i]] = c[i]; // 有効グラフならこの行はコメントアウト
    g_tmp[b[i]][a[i]] = c[i]; // 有効グラフならこの行はコメントアウト
  }
  // finish inputting

  for (int k = 1; k <= n; k++) {
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
	if (g_tmp[i][j] > g_tmp[i][k]+g_tmp[k][j])
	  g_tmp[i][j] = g_tmp[i][k]+g_tmp[k][j];
      }
    }
  }

  long cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      if (graph[i][j] < M && graph[i][j] > g_tmp[i][j]) {
	++cnt;

      }
      //      cout << g_tmp[i][j] << " ";

    }
    //          cout << endl;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NQ = ReadLine().Split(" ").Select(s => int.Parse(s)).ToArray();
        var (N, Q) = (NQ[0], NQ[1]);
        var S = ReadLine();

        var count = new int[N];

        for (int i = 1; i < N; i++)
        {
            if (S[i - 1] == 'A' && S[i] == 'C')
                count[i] = count[i - 1] + 1;
            else
                count[i] = count[i - 1];
        }

        for (int i = 0; i < Q; i++)
        {
            var lr = ReadLine().Split(" ").Select(s => int.Parse(s)).ToArray();
            var (l, r) = (lr[0] - 1, lr[1] - 1);

            var ans = count[r] - count[l];

            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 47260
#include <iostream>
#include <iterator>
#include <algorithm>
#include <map>
using namespace std;

int main(void){
    // Your code here!
    int a,b;
    cin >> a >> b;
    if(b%a){
        cout <<  b - a << endl;
    }else{
        cout << b + a << endl;
    }
}


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

using namespace std;

bool compare(pair<int, int> a, pair<int, int> b){
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}
int main(){
    int n;
    cin >> n;
    int v[n];
    for(int i = 0; i < n; i++)cin >> v[i];

    vector<pair<int, int>> data1(100000, pair<int, int>(0,n/2));
    vector<pair<int, int>> data2(100000, pair<int, int>(0,n/2));
    for(int i = 0; i < n; i+=2){
        data1[v[i]].first = v[i];
        data1[v[i]].second--;
        data2[v[i+1]].first = v[i+1];
        data2[v[i+1]].second--;
    }
    sort(data1.begin(), data1.end(), compare);
    sort(data2.begin(), data2.end(), compare);

    if(data1[0].first != data2[0].first){
        //cout << data1[0].second << " + " << data2[0].second << " = ";
        cout << data1[0].second + data2[0].second << endl;
        return 0;
    }
    if(data1[0].second + data2[1].second <= data1[1].second + data2[0].second){
        cout << data1[0].second + data2[1].second << endl;
        return 0;
    }

    cout << data1[1].second + data2[0].second << endl;
}

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

ll N,X[MAX],Y[MAX],H[MAX];
vector<tuple<ll,ll,ll>> vec;

int main(){
    cin >> N;
    tuple<ll,ll,ll> G = make_tuple(-1,-1,-1);
    for(int i=0;i<N;i++){
        cin >> X[i] >> Y[i] >> H[i];
        if(H[i] >= 1){
            G = make_tuple(X[i],Y[i],H[i]);
        }
    }

    for(int i=0;i<=100;i++){
        for(int j=0;j<=100;j++){
            int height = get<2>(G)+abs(get<0>(G)-i)+abs(get<1>(G)-j);
            height = max(height,0);
            bool match = true;
            for(int k=0;k<N;k++){
                int diff = height-abs(X[k]-i)-abs(Y[k]-j);
                diff = max(diff,0);
                if(H[k] != diff){
                    match = false;
                }
            }
            if(match){
                vec.push_back(make_tuple(i,j,height));
            }
        }
    }
    if(vec.size() == 1){
		cout << get<0>(vec[0]) << " " << get<1>(vec[0]) << " " << get<2>(vec[0]) << endl;     
    }
}


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

using namespace std;

int main() {
    int H, W, N;
    cin >> H >> W >> N;
    vector<vector<int> > C(H, vector<int>(W));

    vector<int> as;

    for (int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++) {
            as.push_back(i);
        }
    }

    sort(as.begin(), as.end());

    for (int i = 0; i < H; i++) {
        for (int j = W * i; j < W * (i + 1); j++) {
            C[i][j - W * i] = as[j];
            // cout << "(i, j) = ( " << i << ", " << j << " )  == " << C[i][j]
            //     << endl;
        }
        if (i % 2 == 1) reverse(C[i].begin(), C[i].end());
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << C[i][j] << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
int main()
{
    int n,k,x;
    scanf("%d%d",&n,&k);
    int i,j,ci=0;
    for(i=1;i<=n;i++)
    {
        scanf("%d",&x);
        if(x>=k)
            ci++;
    }
    printf("%d\n",ci);
    return 0;
}


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

typedef long long ll;
int F(ll a, ll b){
  ll k =(a>b)?a:b;
  int x=0;
  while(k!=0){
    k/=10; x++;
  }
  return x;
}
int main(){
  ll n;  cin>>n;
  int ans=9999999;
  int temp;
  for(int i=1;i<=sqrt(n);i++){
    if(n%i==0){
      if(ans<F(i,n/i)){temp=i;}
      ans = min(F(i,n/i),ans);
    }
  }
  cout<<ans<<"\n";
}


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

void dfs(vector<ll> &isVisited, vector<vector<ll> > &vec, vector<vector<pair<ll,ll> > > &length, vector<ll> &color, ll i){
    isVisited[i] = 1;
    for (ll j = 0; j < vec[i].size(); j++){
        if (isVisited[vec[i][j]] == 1){
            continue;
        }
        color[vec[i][j]] = color[i] + length[i][j].second;
        dfs(isVisited, vec, length, color, vec[i][j]);
    }
}

int main(){
    ll N;
    cin >> N;
    vector<ll> color(N,0);
    vector<ll> isVisited(N,0);
    vector<vector<pair<ll,ll> > > length(N, vector<pair<ll,ll> > (0));
    vector<vector<ll> > connection(N,vector<ll> (0));
    rep(i,N - 1){
        ll u,v,w;
        cin >> u >> v >> w;
        connection[u - 1].push_back(v - 1);
        connection[v - 1].push_back(u - 1);
        length[u - 1].push_back(pair<ll,ll> (v - 1, w));
        length[v - 1].push_back(pair<ll,ll> (u - 1, w));
    }
    dfs(isVisited, connection, length, color, 0);
    rep(i,N){
        if (color[i] % 2 == 0) cout << 0 << endl;
        else cout << 1 << endl;
    }
}


Measured memory_bytes: 19992