akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  int n; std::cin >> n;
  ll sum = 0;
  vi a(n);
  rep(i, n) std::cin >> a[i], sum += a[i];
  vi x(n, -sum);
  for (int i = 0; i < n; i+=2) x[0] += 2*a[i];
  rep(i, n-1) x[i+1] = 2 * a[i] - x[i];
  rep(i, n) std::cout << x[i] << (i < n-1 ? ' ' : '\n');
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=1e5+5;
bool d[3][N];
int s,t,n,m,dist[3][N];
vi v[N],e1,e2;//可以制造余数1和余数2的 
queue<int>q;
int main()
{
	for(int i=0;i<N;i++)dist[0][i]=dist[1][i]=dist[2][i]=1e9;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].pb(b);
	}
	cin>>s>>t;
	s--,t--;
	q.push(s);
	q.push(0);
	while(!q.empty())
	{
		int now=q.front();q.pop();
		int move=q.front();q.pop();
		if(d[move%3][now])continue;
		dist[move%3][now]=move;
		d[move%3][now]=true;
		for(int i=0;i<v[now].size();i++)
		{
			int to=v[now][i];
			q.push(to);
			q.push(move+1);
		}
	}
	if(d[0][t])
	{
		cout<<dist[0][t]/3<<endl;
	}
	else
	{
		cout<<-1<<endl;
	}
	return 0;
}

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

int main(){
    long long int N,A,B;
    cin >> N >> A >> B;
    if(A%2!=B%2){
        cout << min(A,N-B+1)+(B-A)/2;
    }
    else{
        cout << (B-A)/2;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    char w;int num;int c[26] = {};
    while(cin >> w){
        num = w;
        if (97 <= num && num <= 122) c[num-97] += 1;
        else if (65 <= num && num <= 90) c[num-65] += 1;
    }
    for(int i=0;i<26;i++) cout << char(i+int('a')) << " : " << c[i] << endl;
}


Measured memory_bytes: 3100
package main

import "fmt"

func main() {
	var N, h, prevh, tmpout, out int
	fmt.Scanf("%d", &N)
	prevh = 0
	tmpout = 0
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &h)
		if prevh >= h {
			tmpout++
		}
		if tmpout > out {
			out = tmpout
		}
		if prevh < h {
			tmpout = 0
		}
		prevh = h
	}
	fmt.Println(out)
}

Measured memory_bytes: 5504
#include<stdio.h>
#define MAX 100000
typedef struct{
    char name[100];
    int time;
} queue;
  
void enqu(queue);
queue dequ(void);
  
int head=0,tail=0;
queue C[MAX];
  
    main(){
    int n,m,i,sum=0;
    queue D;
 
    scanf("%d%d",&n,&m);
        for(i=0;i<n;i++){
            scanf("%s%d",D.name,&D.time);
            enqu(D);
        }
        while(1){
            if(head == tail) break;
            if(C[head].time > m){
                D = dequ();
                D.time -= m;
                enqu(D);
                sum += m;
            }
            else{
                D = dequ();
                printf("%s %d\n",D.name,D.time+sum);
                sum += D.time;
            }
        }
return 0;
}
  
void enqu(queue p){
C[tail] = p;
if(tail+1 == MAX) tail = 0;
else tail++;
}
  
queue dequ(){
    queue x;
    x = C[head];
  
    if(head+1 == MAX) head = 0;
    else head++;
    return x;
}

Measured memory_bytes: 10756
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int s = Integer.parseInt(sc.next());
		
		int mod = 998244353;
		
		int []a = new int [n];
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = Integer.parseInt(sc.next());
		}
		
		int dp[][] = new int [n+1][3001];
		
		dp[0][0] = 1;
	
		
		for(int i = 0 ; i < n; i++) {
			for(int j = 3000; j >= 0 ;j--) {
				if(j - a[i] < 0) {
					dp[i+1][j] = (dp[i][j]*2)%mod;
				}
				else {
				dp[i+1][j] = (2*dp[i][j])%mod;
				dp[i+1][j] = (dp[i][j-a[i]] + dp[i+1][j])%mod;
				}
			}
		}
		
		System.out.println(dp[n][s]);

	}

}


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

int main(void) {
	while(true) {
		int x, y, s;
		cin >> x >> y >> s;
		if ( x == 0 ) { break; }
		x += 100;
		y += 100;

		int max = 0;
		
		for(int a=1; a<s; a++) {
			int at = a*x/100;
			int bt = s-at;
			
			for(int b = ((bt+1)*100/x); (b*x/100) >= bt && b>0; b--) {
				if ( (b*x/100) != bt ) { continue; }
				int newsum = a*y/100 + b*y/100;
				if ( newsum > max ) { max = newsum; }
			}
		}

		cout << max << std::endl;
	}
}

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

int main(void){
    int N; cin >> N;
    vector<ll> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    ll a=0,b=0;
    int cnt, i=0;
    while(cnt<2 and i<A.size()-1){
        if(A[i]==A[i+1]){
            if(cnt==0) a=A[i];
            else b=A[i];
            cnt++;
            i+=2;
        }
        else i++;
        
    }

    cout << a*b << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
	  FastReader sc = new FastReader();
	  int[] nums = new int[3];
	  
	  for (int i = 0; i < 3; i++) {
		  nums[i] = sc.nextInt();
	  }
	  Arrays.sort(nums);
	  
	  System.out.println((nums[1] - nums[0]) + (nums[2] - nums[1]));
  }
  
  static class FastReader {
    BufferedReader br;
    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }
  
    String next() { 
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        } catch (IOException  e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() { 
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
        try{
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
      }
  }
}


Measured memory_bytes: 21332
use std::str::FromStr;
use std::collections::VecDeque;



fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn bfs(maze : &Vec<Vec<bool>>, h : usize, w : usize, stt : (usize,usize), tar : (usize,usize)) -> i32 {
    let mut dst = Vec::new();
    for i in 0..h {
        let v = vec!(false; w);
        dst.push(v);
    }
    dst[stt.0][stt.1] = true;
    let mut que : VecDeque<((usize,usize),i32)> = VecDeque::new();
    que.push_back((stt,0));
    let mut d = 0;
    while !que.is_empty() {

        let x = que.pop_front();
        let x0 = (x.unwrap().0).0;
        let x1 = (x.unwrap().0).1;
        let ds = x.unwrap().1;
        //if (stt == (1,1) && tar == (3,3)){
        //    println!("{} {} {} ", d, x0, x1);
        //}
        dst[x0][x1] = true;
        if x.unwrap().0 == tar {
            return ds;
        }
        if maze[x0-1][x1] && !dst[x0-1][x1] {
            que.push_back(((x0-1, x1), ds+1));
            dst[x0-1][x1] = true;
        }
        if maze[x0+1][x1] && !dst[x0+1][x1] {
            que.push_back(((x0+1, x1), ds+1));
            dst[x0+1][x1] = true;
        }
        if maze[(x0)][(x1)-1] && !dst[x0][x1-1] {
            que.push_back(((x0, x1-1), ds+1));
            dst[x0][x1-1] = true;
        }
        if maze[(x0)][(x1)+1] && !dst[x0][x1+1] {
            que.push_back(((x0, x1+1), ds+1));
            dst[x0][x1+1] = true;
        }

    }
    return d;

}

fn main() {
    let hw : Vec<usize> = get_vec();
    let mut maze : Vec<Vec<bool>> = Vec::new();
    let dum1 = vec!(false; (hw[1]+2));
    maze.push(dum1);
    for i in 0..hw[0] {
        let v : String = get_one();
        let mut row : Vec<bool> = Vec::new();
        row.push(false);
        for c in v.chars() {
            if c == '.' {
                row.push(true);
            }
            else {
                row.push(false);
            }
        }
        row.push(false);
        maze.push(row);
    }
    let dum2= vec!(false; (hw[1]+2));
    maze.push(dum2);
    let mut ans = 0;
    for i1 in 0..hw[0]+2 {
        for i2 in 0..hw[1]+2 {
            for j1 in 0..hw[0]+2 {
                for j2 in 0..hw[1]+2 {
                    if maze[i1][i2] && maze[j1][j2] {
                        let a = bfs(&maze, hw[0]+2, hw[1]+2, (i1,i2), (j1,j2));
                        ans = std::cmp::max(ans, a);
                    }
                }
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
         int a=sc.nextInt();
         int b=sc.nextInt();
         int c=sc.nextInt();
         int d=sc.nextInt();
         


int area=a*b;
int area1=c*d;
 if(area>=area1)
System.out.println(area);
else if(area<area1)
System.out.println(area1);

}}

Measured memory_bytes: 20948
#include<bits/stdc++.h>
#define endl enjoy_codeforces
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    int n,k;std::cin>>n>>k;
    int ans=k;
    n--;while(n--)ans*=k-1;
    std::cout<<ans<<'\n';
}


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

int main(){
  int64_t n,a,b;
  cin >> n >> a >> b;
  int64_t count=0;
  if(a>b){
    swap(a,b);
  }
  for(int i=0;i<3;i++){
    if((b-a)%2==0){
      count+=(b-a)/2;
      break;
    }
    else{
      if(a==1){
        b-=1;
        count++;
      }
      else if(b==n){
        a+=1;
        count++;
      }
      else if((a-1)<(n-b)){
        int64_t c=a;
        b -= a-1;
        a -= a-1;
        count += c-1;
      }
      else{
        int64_t c=b;
        a += n-b;
        b += n-b;
        count += n-c;
      }
    }
  }
  cout << count << endl;
}

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

#define forn(i, a, b) for (int i = a; i <= b; ++i)

using namespace std;

const int N = (int)2e5 + 1;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;

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

int n, a[N];
int main (){
  scanf ("%d", &n);
  int sum = 0;
  forn (i, 1, n){
    scanf ("%d", a + i);
    sum += a[i] - 1;
  }
  printf ("%d\n", sum);
  return 0;
}


Measured memory_bytes: 256
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim a(N - 1) As Integer
        For i As Integer = 0 To N - 1
            a(i) = NextInt()
        Next

        Dim ans As Integer = Integer.MaxValue
        For k As Integer = Min(a) To Max(a)
            Dim cnt As Integer = 0
            For Each ai As Integer In a
                cnt += CInt((ai - k) ^ 2)
            Next
            ans = Min(New Integer() {ans, cnt})
        Next

        WriteLine(ans)
    End Sub

    Function Max(a() As Integer) As Integer
        Dim result As Integer
        For i As Integer = 0 To UBound(a)
            If i = 0 Or a(i) > result Then result = a(i)
        Next
        Return result
    End Function

    Function Min(a() As Integer) As Integer
        Dim result As Integer
        For i As Integer = 0 To UBound(a)
            If i = 0 Or a(i) < result Then result = a(i)
        Next
        Return result
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function
End Module


Measured memory_bytes: 19920
#include<bits/stdc++.h>
using namespace std;
int main(){
  string c,pr;
  int ans;
  cin>>ans;
  while(cin>>c&&c!="="){
    if(isdigit(c[0])){
      int a=0;
      for(int i=c.size()-1,k=1;i>=0;i--,k*=10)a+=(c[i]-'0')*k;
      if(pr=="+")ans+=a;
      if(pr=="-")ans-=a;
      if(pr=="/")ans/=a;
      if(pr=="*")ans*=a;
    }
    pr=c;
  }
  cout<<ans<<endl;
  return 0;
}

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

// @@ !! LIM(f:updMaxMin)
// --> f:updMaxMin
// ---- inserted function updMaxMin from util.cc
template<typename T>
bool updMax(T& tmax, const T& x) {
  if (x > tmax) { tmax = x; return true;  }
  else          {           return false; }
}
template<typename T>
bool updMin(T& tmin, const T& x) {
  if (x < tmin) { tmin = x; return true;  }
  else          {           return false; }
}
// ---- end updMaxMin
// @@ !! LIM  -- end mark --

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, M; cin >> N >> M;
  vector<bool> used(M);
  ll big = 1000 * 1000;
  vector<vector<ll>> dist(N, vector<ll>(N, big));
  vector<ll> A(M), B(M), C(M);
  for (ll i = 0; i < M; i++) {
    ll a, b, c; cin >> a >> b >> c; a--; b--;
    A.at(i) = a;
    B.at(i) = b;
    C.at(i) = c;
    dist.at(a).at(b) = c;
    dist.at(b).at(a) = c;
  }
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < N; j++) {
      for (ll k = 0; k < N; k++) {
	updMin(dist.at(j).at(k), dist.at(j).at(i) + dist.at(i).at(k));
      }
    }
  }
  ll cnt = 0;
  for (ll i = 0; i < M; i++) {
    if (C.at(i) > dist.at(A.at(i)).at(B.at(i))) cnt++;
  }
  cout << cnt << endl;

  return 0;
}



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

long long GCD(long long left, long long right) {
  if(left == 0 || right == 0) return 0;
  if(left < 0) left *= -1;
  if(right < 0) right *= -1;
  if(left < right) swap(left, right);
  long long nextnum, ansgcd = -1;
  while(ansgcd == -1) {
    nextnum = left % right;
    if(nextnum == 0) ansgcd = right;
    left = right;
    right = nextnum;
  }
  return ansgcd;
}

long long n, x, ans = 1;
vector<long long> lst;

int main() {
  int i;
  cin >> n >> x;
  lst.push_back(x);
  for(i = 0; i < n; ++i) {
    cin >> x;
    lst.push_back(x);
  }
  sort(lst.begin(), lst.end());
  ans = lst[1] - lst[0];
  for(i = 2; i < lst.size(); ++i) {
    ans = GCD(ans, lst[i] - lst[i - 1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
namespace lib
{
	#define ll long long
	#define ull unsigned long long
	#define rgi register int
	#define rgl register long long
	#define rgc register char
	const double pi=acos(-1); 
	using namespace std;
	class fastio
	{
		private:
			#define _NUMLEN 112
			char _num[_NUMLEN],_ch; int _f,_head; bool _useSTD;
		public:
			fastio() {_f=0,_head=0,_useSTD=0,SUF=_ch=' ';}
			char SUF;
			inline void ioSTD() {_useSTD=1; ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); }
			inline void gc(char & _c) {if(_useSTD)cin>>_c; else _c=getchar(); }
			inline void pc(char _c) {if(_useSTD)cout<<_c; else putchar(_c); }
			template<typename _T> inline fastio & operator - (_T & _x)
			{
				if(_useSTD)cin>>_x; else{
					_x=0; 
					while(!isdigit(_ch)) _f|=_ch=='-',gc(_ch); 
					while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),gc(_ch); 
					_f&&(_x=-_x,_f=0); 
				}return *this; 
			}
			template<typename _T> inline fastio & operator + (_T _x)
			{
				if(_useSTD)cout<<_x<<SUF; else{
					_T _k; 
					if(_x==0) {pc('0'),pc(SUF);return *this;} if(_x<0) pc('-'),_x=-_x;
					while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k; while(_head>0) pc(_num[_head]),--_head;
					pc(SUF);
				}return *this; 
			}
			template<typename _T> inline fastio & operator >> (_T & _x) {cin>>_x;return *this;}
			template<typename _T> inline fastio & operator << (_T _x) {cout<<_x;return *this;}
			#define edn pc('\n')
	}io;
	inline void fileio(string _r,string _w) {if(_r[0]!='-')freopen(_r.c_str(),"r",stdin); if(_w[0]!='-')freopen(_w.c_str(),"w",stdout); }
	#define mem(_x,_set) memset(_x,_set,sizeof(_x))
}
using namespace lib;
// ----------------------------

// #define int ll
const int maxn=100004;
const int mod=998244353,inf=1000000007;

signed main() {
	int n, k, t = 0, cur = 1;
	scanf("%d %d", &n, &k);
	while(cur < n) {
		cur = cur * k;
		t++;
	}
	if(cur == n) t++;
	printf("%d", t);
	return 0;
}

// ----------------------------
// by imzzy



Measured memory_bytes: 256
import numpy as np

n = int(input())
dam = list(map(int, input().split()))
yama = [-1] * n

min_dam = min(dam)
min_dam_arg = np.argmin(dam)

s = sum(dam)
yama[0] = s - 2 * sum(dam[1::2])
for i in range(1, n):
    yama[i] = 2 * (dam[i-1] - yama[i-1]/2)

yama = map(int, yama)
print(' '.join(map(str, yama)))

Measured memory_bytes: 26304
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;



int main() {

  int N;
  cin >> N;

  bool exist = false;
  int k = 1;
  while(k*(k-1) <= 2*N) {
    if(k*(k-1) == 2*N){
      exist = true;
      break;
    }

    k += 1;
  }

  if(exist) {
    cout << "Yes" << endl;

    vector< vector<int> > A;
    A.resize(k);
    for(int i = 0; i < k; ++i) A.resize(k-1);

    int n = 1;
    cout << k<< endl;
    for(int i = 1; i <= k; ++i) {
      cout << k-1 << " ";

      int size = A[i-1].size();
      for(int s = 0; s < size; ++s) {
        cout << A[i-1][s] << " ";
      }

      for(int s = i+1; s <= k; ++s) {
        cout << n << " ";
        A[s-1].push_back(n);
        n += 1;
      }

      cout << endl;
    }
  }
  else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 1920
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner seer = new Scanner(System.in);
		int n = seer.nextInt();
		int k = seer.nextInt();
		char[] s = seer.next().toCharArray();
		s[k-1] -= ('A'-'a');
		System.out.println(new String(s));
	}

}


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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.rbegin(),v.rend());
    int a=0,b=0;
    for(int i=0;i<n;i++){
        if(i%2==0){
            a+=v[i];
        }else{
            b+=v[i];
        }
    }
    cout<<a-b<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import math
S = input()
N = len(S)
flag = True

leftS = S[0:math.floor((N - 1)/2)]
rightS = S[math.floor((N + 3)/2) - 1:N]

def isPalindrome(str):
    N =len(str)
    flag = True
    for i in range(0,math.floor(N/2)):
        if str[i] != str[(N-1) - i]:
            flag = False
            break
    return flag

flag = isPalindrome(S)
if flag:
	flag = isPalindrome(leftS)
if flag:
	flag = isPalindrome(rightS)

if flag: print("Yes")
else: print("No")

Measured memory_bytes: 3064
def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N, M, C = reads()
B = reads()
ans = 0
for _ in range(N):
  A = reads()
  if sum(A[i] * B[i] for i in range(M)) + C > 0:
    ans += 1
print(ans)

Measured memory_bytes: 38256
#include <iostream>
#include <bits/stdc++.h>
#include <set>
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define ll long long
#define ull unsigned long long
#define MAXN 1000000007
#define INF 1e12
using namespace std;
typedef pair<int,int> pi;
typedef pair<pi,int> trip;
typedef pair<ll int,ll int> pli;
typedef vector<int> vi;
typedef vector<ll int> vli;
typedef vector<vi> vvi;
string getString(char x)
{
    string s(1, x);

    return s;
}
int highestPowerof2(ll int n)
{if(n==0)
    return 0;
   int p = (int)log2(n);
   //cout<<p<<"highest"<<endl;
   return p;
}

vector<int> vec;
vector<int> vecr;
int findset(int a)
{
    if(vec[a]==a)
        return a;
    else
        return vec[a]=findset(vec[a]);
}
void mergeset(int a, int b)
{
    int i=findset(a);
    int j=findset(b);
    if(i==j)
        return;
    if(vecr[i]>vecr[j])
    {
        vec[j]=i;
        vecr[i]+=vecr[j];
    }
    else
    {
        vec[i]=j;
        vecr[j]+=vecr[i];
    }
}
int main()
{ios::sync_with_stdio(0);
	cin.tie(0);
    int test=1;
    //int cas=
    //cin>>test;

    while(test--)
    {
       int n,m;cin>>n>>m;
       vec.assign(n+1,0);
       vecr.assign(n+1,1);
       for(int i=0;i<=n;i++)
        vec[i]=i;
       for(int i=0;i<m;i++)
       {
           int a,b;cin>>a>>b;
           mergeset(a,b);
       }
       int ans=0;
       for(int i=1;i<=n;i++)
       {
           if(vec[i]==i)
            ans=max(ans,vecr[i]);
       }
       cout<<ans<<endl;

    }

}


Measured memory_bytes: 4668
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <sstream>
#include <cstring>
#include <set>
#include <cctype>
#include <bitset>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cin.tie(0);                  \
    // cout.tie(0);
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1e6 + 100;
const int maxm = 1e6 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
bool vis[maxn];

int main()
{
#ifdef ONLINE_JUDGE
#else
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    IO;
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j *i <= n; j++)
        {
            if (i * j < n)
                cnt++;
        }
    }
    cout << cnt;
    return 0;
}


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

int main() {
  int w,a,b;cin>>w>>a>>b;
  if(abs(a-b)<=w)cout<<0<<endl;
  else cout<<abs(a-b)-w<<endl;
}

Measured memory_bytes: 3608
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
li = [0]*100001
for a in A:
    li[a] += 1
ans = sum(A)
# print(dict_A)
for i in range(Q):
    b, c = map(int, input().split())
    ans += (c-b)*li[b]
    li[c] += li[b]
    li[b] = 0
    print(ans)

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


int main(void) {
  string S;
  ll K;
  cin >> S >> K;

  rep(i, S.size()) {
    if (i == K - 1) {
      cout << S[i] << endl;
      return 0;
    }
    if (S[i] != '1') {
      cout << S[i] << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long N;
        public long MOD = 1000000007;

        public void Run()
        {
            N = Input.ReadLong();
            long X = long.MaxValue;
            for (int i = 0; i < 5; i++)
            {
                long x = Input.ReadLong();
                X = Math.Min(X, x);
            }

            Console.WriteLine(5 + ((N - 1)/ X));
        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

int main() {
  string st;
  cin >> st;
  bool s = false, w = false, e = false, n = false;
  for (int i = 0; i < st.size(); i++) {
    if (st.at(i) == 'S') s = true;
    if (st.at(i) == 'W') w = true;
    if (st.at(i) == 'E') e = true;
    if (st.at(i) == 'N') n = true;
  }

  if (s == n && e == w) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int h, w, i, j;
    char a[101][101];

    scanf("%d %d", &h, &w);
    
    for(i=0;i<h;i++){
        scanf("%s", a[i]);
    }

    for(i=0;i<h;i++){
        printf("%s", a[i]);
        printf("\n");
        printf("%s", a[i]);
        printf("\n");
    }
    
    return 0;
}
    
    


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define N 100005
using namespace std;
typedef pair<int,int> P;
int n,x[N],y[N],w[N];
map<P,int> fox;
int dy[6]={1,1,0,1,1,0};
int dx[6]={0,1,1,-1,0,-1};

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x[i]>>y[i]>>w[i];
    fox[P(y[i],x[i])]=w[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    int sum=w[i];
    for(int j=0;j<6;j++){
      int ny=y[i]+dy[j];
      int nx=x[i]+dx[j];
      if(fox.count(P(ny,nx)))
	sum+=fox[P(ny,nx)];
      if(j==2){
	ans=max(ans,sum);
	sum=w[i];
      }
    }
    ans=max(ans,sum);
  }
  cout<<ans<<" / "<<1<<endl;
  return 0;
}

Measured memory_bytes: 10516
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    vector<pair<int, int>> arr(n);

    for (int i = 0; i < n; i++)
    {
        cin >> arr[i].first;
        cin >> arr[i].second;
        arr[i].first -= arr[i].second;
        arr[i].second += arr[i].first + arr[i].second;
    }

    sort(arr.begin(), arr.end());
    int ans = 0;

    int end = arr[0].second;

    for (int i = 1; i < n; i++)
    {
        if (arr[i].first < end)
        {
            ans++;
            end = min(end, arr[i].second);
        }
        else
        {
            end = arr[i].second;
        }
    }
    cout << n - ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;


char dna[4]={'A', 'C', 'G', 'T'};
char x[1000002];
int coun[1000002];
int n, q;
int l, r;
int main(){   
    scanf("%d %d",&n, &q);
    scanf("%s",x);
	for (int i=0;i<n;i++){
		int temp = 0;
		for (int j=0;j<4 && !temp;j++){
			if ((x[i] == dna[0]) && (x[i+1] == dna[1])){
				temp = 1;
			}
		}
		coun[i+1] = coun[i] + temp;
		
	}
    while(q--){
    	scanf("%d %d",&l, &r);
    	printf("%d\n", coun[r-1]-coun[l-1]);	   	

    }
	return 0;
}

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

int findcycle(vector<int> &A, int N) {
    // うさぎとかめの閉路検出で、閉路の始点を求めたい、、
    //https://www.youtube.com/watch?v=pKO9UjSeLew
    int tortoise    = A[0];
    int hare        = A[0];
    while(true)
    {
        tortoise = A[tortoise];
        hare = A[A[hare]];  // うさぎは速いので、二つ飛びする
        if(tortoise == hare) break;
    }

    int ptr1 = A[0];
    int ptr2 = tortoise;
    while(ptr1 != ptr2) {
        ptr1 = A[ptr1];
        ptr2 = A[ptr2];
    }
    return ptr1;
}

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
        --A[i];
    }

    int cyclebegin = findcycle(A, N);

    int cur = 0;
    while(cur != cyclebegin && K > 0) {
        cur = A[cur];
        --K;
    }
    if(K == 0) { cout << cur + 1 << endl; return 0; }
    vector<int> Cycle;
    Cycle.push_back(cur);
    while(A[cur] != cyclebegin) {
        Cycle.push_back(A[cur]);
        cur = A[cur];
    }

    long long P = Cycle.size();
    cout << Cycle[K%P] + 1 << endl;
    return 0;
}

Measured memory_bytes: 4860
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
int W, H, N;
bool field[101][101];
int main() {
	cin >> W >> H >> N;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			field[i][j] = true;
		}
	}
	for (int i = 0; i < N; ++i) {
		int x, y, a;
		cin >> x >> y >> a;
		if (a == 1) {
			for (int j = 0; j < H; ++j) {
				for (int k = 0; k < x; ++k) {
					field[j][k] = false;
				}
			}
		}
		else if (a == 2) {
			for (int j = 0; j < H; ++j) {
				for (int k = x; k < W; ++k) {
					field[j][k] = false;
				}
			}
		}
		else if (a == 3) {
			for (int j = 0; j < y; ++j) {
				for (int k = 0; k < W; ++k) {
					field[j][k] = false;
				}
			}
		}
		else if (a == 4) {
			for (int j = y; j < H; ++j) {
				for (int k = 0; k < W; ++k) {
					field[j][k] = false;
				}
			}
		}
	}
	int cnt = 0;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (!field[i][j]) cnt++;
		}
	}
	cout << W * H - cnt << endl;
	return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(all(a), greater<int>());

  ll ans = 0;
  int cnt = 1;

  int i = 0;
  while(true){
    if(i==0){
      ans += a[i];
      cnt ++;
      if(cnt == n) break;
      i++;
    }else{
      ans += a[i];
      cnt++;
      if(cnt == n) break;
      ans += a[i];
      cnt++;
      if(cnt == n) break;
      i++;
    }
  }

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


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

struct edge {
    int to;
    int cost;
};

int prim(vector<vector<edge>>& edges, int V) {
    int res = 0;
    vector<bool> used(V, false);
    // P -> first : コスト, second : 行先
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0, 0);
    // コストが小さい順に出しいく
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        if(used[p.second]){
            continue;
        }
        used[p.second] = true;
        res += p.first;
        for(const auto e : edges[p.second]){
            if(!used[e.to]){
                que.emplace(e.cost, e.to);
            }
        }
    }
    return res;
}

signed main() {

    int n;
    cin >> n;
    vector<vector<edge>> edges(n);
    vector<pair<P, int>> point(n);
    rep(i, n){
        int x, y;
        cin >> x >> y;
        point[i] = {{x, y}, i};
    }
    
    // x sort
    sort(all(point));
    rep(i, n-1){
        int cost_x = abs(point[i].first.first - point[i+1].first.first);
        edges[point[i].second].emplace_back(edge{point[i+1].second, cost_x});
        edges[point[i+1].second].emplace_back(edge{point[i].second, cost_x});
    }
    
    // x と y を入れ替える
    for(auto &e : point){
        swap(e.first.first, e.first.second);
    }
    
    // y sort
    sort(all(point));
    rep(i, n-1){
        int cost_y = abs(point[i].first.first - point[i+1].first.first);
        edges[point[i].second].emplace_back(edge{point[i+1].second, cost_y});
        edges[point[i+1].second].emplace_back(edge{point[i].second, cost_y});
    }
    
    cout << prim(edges, n) << endl;

    return 0;
}


Measured memory_bytes: 16116
#include <iostream>

using namespace std;

int main()
{
  int i, x;
  for(i=1; i<=10000; i++)
  {
   cin >> x;

   if (x==0)
      break;
   else
      cout << "Case " << i << ": " << x << endl;
  } 
   return 0;
}


Measured memory_bytes: 2988
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>


using namespace std;

int main(){

	int a, b;

	cin >> a;
	cin >> b;

	cout << (a -1 ) * (b-1) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n,m;
  cin>>n>>m;
  LL x = 1900*m+100*(n-m);
  LL a=1;
  REP(i,0,m)a*=2;
  LL y = x*a;
  cout<<y<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		List<Integer> list = new ArrayList<>();
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();

		for(int i = 0; i < a; i++) {
			int x = sc.nextInt();
			if (x == 0) {
				list.add(sc.nextInt());
			} else if (x == 1) {
				System.out.println(list.get(sc.nextInt()));
			} else {
				list.remove(list.size()-1);
			}
		}

	}

}



Measured memory_bytes: 129872
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=924844033;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=2010;
int comb[N][N],p[N],q[N],c[N],u,n,k;
void mul(int x) {
	int v=x/2+1;
	rep(i,0,v) q[i]=comb[x-i][i];
	rep(i,0,u+v) c[i]=0;
	rep(i,0,u) rep(j,0,v) c[i+j]=(c[i+j]+(ll)p[i]*q[j])%mod;
	rep(i,0,u+v) p[i]=c[i]; u=u+v-1;
}
int main() {
	p[0]=1; u=1;
	scanf("%d%d",&n,&k);
	comb[0][0]=1;
	rep(i,1,n+1) {
		comb[i][0]=comb[i][i]=1;
		rep(j,1,i) comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
	}
	rep(i,0,k) {
		int c=i,cnt=0;
		while (c<n) c+=k,cnt++;
		mul(cnt);
		mul(cnt);
	}
	ll sg=1,ret=0;
	if (n%2==1) sg=-1;
	rep(i,0,n+1) {
		ret=(ret+sg*p[n-i])%mod;
		sg=-sg*(i+1)%mod;
	}
	if (ret<0) ret+=mod;
	printf("%lld\n",ret);
}


Measured memory_bytes: 13952
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int n, a[200010];
int r, sum;
int ans;

signed main() {
	cin >> n; 
	rep(i, n)cin >> a[i];
	for (int l = 0; l < n; l++) {
		sum -= a[l - 1];
		while (1) {
			if ((sum^a[r]) != sum + a[r])break;
			if (r == n)break;
			sum ^= a[r];
			r++;
			ans += (r - l);
		}
		if (r == l)r++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


int main(){FIN

    string s;cin>>s;
    map<char,ll> mp;
    bool ok = true;
    if (s[0]!='A') ok =false;
    if(count(s.cbegin()+2, s.cend()-1, 'C')!=1) ok = false;
    REP(i,s.size()){
        if (s[i]=='A' || s[i]=='C') {
            mp[s[i]]++;
            if (mp[s[i]]>1) ok = false;
        }
        if (s[i]!='A' && s[i]!='C' && isupper(s[i])) ok = false;
    }
    if (ok) cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100000];

int solve(int start,int n,int a[])
{

    if(dp[start]!=-1)
    {

     return dp[start];

    }


    if(start+1==n)
    {

    return abs(a[start]-a[start+1]);

    }
    else if (start+2==n)
        return abs(a[start]-a[start+2]);

    int x = solve(start+1,n,a)+abs(a[start]-a[start+1]);
    int y=solve(start+2,n,a)+abs(a[start]-a[start+2]);


     dp[start] =  min(x,y);

     return dp[start];

}

int main()
{
  int n;
  cin>>n;
int a[n];

memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++)
    cin>>a[i];
    cout<<solve(0,n-1,a)<<endl;
}


Measured memory_bytes: 8832
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n,m = li()
a = list(li_())

ans = [0]*m
# 1.前処理
# 1-1.a[1:]の中の x(0<= x < m)の個数
cnt_equal = [0]*m
for i in range(n-1):
    cnt_equal[a[i+1]] += (((a[i+1]+m-a[i])%m) - 1)

# 1-2.a[i]→a[i+1]の内側(両端除く)に x(0<= x < m)が入る回数
cnt_inner = [0]*(2*m+1)
for i in range(n-1):
    cnt_inner[a[i] + 1] += 1
    cnt_inner[a[i] + (a[i+1]+m-a[i])%m] -= 1
    
cnt_inner = list(accumulate(cnt_inner))
cnt_inner = [cnt_inner[i]+cnt_inner[i+m] for i in range(m)]


# 2.fav == 1 のときのシミュレーション
fav = 0
for i in range(n-1):
    ans[0] += min((a[i+1]+m-a[i])%m, 1+(a[i+1]+m-fav)%m)

# 3.favが[2,m]のとき、fav-1の情報をもとに更新
for fav in range(1,m):
    ans[fav] = ans[fav-1] + cnt_equal[fav-1] - cnt_inner[fav-1]
    
print(min(ans))

Measured memory_bytes: 24172
#include <cstdio>
using namespace std;

int n, x[8], y[8];

void dfs(int b){
	if(b != 128){ putchar('('); }
	printf("(%d&(0", b);
	int c = 2;
	
	for(int i = 0; i < n; ++i){
		if(y[i] & b){
			printf("|((255");
			++c;
			int d = 1;
			for(int t = 1; t <= b; t <<= 1){
				if(x[i] & t){
					printf("&((x");
				}
				else{
					printf("&(((~x)");
				}
				
				printf("*%d)", b / t);
				++d;
			}
			printf("+0");
			for(int j = 0; j < d; ++j){
				putchar(')');
			}
		}
	}
	
	printf("^0");

	for(int i = 0; i < c; ++i){
		putchar(')');
	}
	
	if(b != 128){
		printf("|");
		dfs(b << 1);
		printf(")");
	}
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		scanf("%d%d", &x[i], &y[i]);
	}

	dfs(1);
	puts("");
}

Measured memory_bytes: 1048
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String,
    }
    println!("{}",
        s.replace(",", " "));
}


Measured memory_bytes: 4352
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const ll mod = 1000000007;



int main()
{
    int n, MA, MB;
    cin >> n >> MA >> MB;
    vector<pair<int,int>> a(n);
    vector<int> cost(n);
    for(int i = 0; i < n; i++)cin >> a[i].first >> a[i].second >> cost[i];

    int m = n / 2;


    //半分全列挙
    vector<pair<int,int>> front(1 << m), back(1 << (n - m));
    vector<vector<int>> costfront(500, vector<int>(500, 1e8)); //{i,j}の組を作る最小値
    vector<vector<int>> costback(500,  vector<int>(500, 1e8));

    for(int bit = 0; bit < (1 << m); bit++){
        pair<int,int> cur;
        int curcost = 0;
        for(int i = 0; i < m; i++){
            if(bit & (1 << i)){
                cur.first += a[i].first;
                cur.second += a[i].second;
                curcost += cost[i];
            }
        }
        front[bit] = cur;
        costfront[cur.first][cur.second] = min(curcost, costfront[cur.first][cur.second]);
    }
    sort(front.begin(), front.end());

    int t = n - m;//半分全列挙の後側
    for(int bit = 0; bit < (1 << t); bit++){
        pair<int,int> cur;
        int curcost = 0;
        for(int i = 0; i < t; i++){
            if(bit & (1 << i)){
                cur.first += a[i + m].first;
                cur.second += a[i + m].second;
                curcost += cost[i + m];
            }
        }
        back[bit] = cur;
        costback[cur.first][cur.second] = min(curcost, costback[cur.first][cur.second]);
    }
    sort(back.begin(), back.end());


    int ans = 1000000000;

    for(int cef = 1; cef <= (n >= 20 ? 20 : 500); cef++){
        int ma = MA * cef;
        int mb = MB * cef;

        for(auto i : front){
            if(costfront[i.first][i.second] > ans)continue;
            pair<int,int> cur = {ma - i.first, mb - i.second};
            auto itr = lower_bound(back.begin(), back.end(), cur);
            if(itr == back.end())continue;
            if(*itr != cur)continue;

            ans = min(ans, costfront[i.first][i.second] + costback[cur.first][cur.second]);
        }
    }

    cout << (ans == 1000000000 ? -1 : ans) << endl;
}

Measured memory_bytes: 18688
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i = x; i < n; i++)
#define MAX 100
#define INF 1000000001

#define ad(x) int i = 100;
typedef long long ll;
// enum {
//   AST_INT,
//   AST_SYM,
//   AST_STR,
//   AST_FUNCALL,
// };



// double winProb(int Rp, int Rq) {
//     return 1/(1+pow(10, (Rq-Rp)/400.));
// }

// int R[1<<10];
// double dp[12][1<<10];
int h, w;
// int canvas[]
// int w[30010];
// int e[30010];

int main() {
    cin >> h >> w;
    vector<vector<char>> canvas(h + 2,vector<char>(w + 2,'b'));
    REP(i,1,h+1) REP(j,1,w+1) cin >> canvas[i][j];
    string ans = "Yes";
    REP(i,1,h+1) REP(j,1,w+1) {
        if (canvas[i][j] == '.') continue;
        if (canvas[i-1][j] != '#' && canvas[i+1][j] != '#' && canvas[i][j-1] != '#' && canvas[i][j+1] != '#') {
            ans = "No";
            break;
        }
    }
    
    
    cout << ans << endl;
    // REP(i,0,h+2) {
    //     REP(j,0,w+2) cout << canvas[i][j];
    //     cout << endl;
    // }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,nn) for(int i=0;i<nn;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



vector<pair<int,int>> v[100010];
ll saitan[100010];

void dfs(ll d,ll cost){
  saitan[d]=cost;
  FOR(i,v[d].size()){
    if(cost+v[d][i].second>=saitan[v[d][i].first]){
      continue;
    }
    dfs(v[d][i].first,cost+v[d][i].second);
  }
}

int main(){
  
  ll n;
  cin>> n;
  ll a,b,c;
  fill(saitan,saitan+n+1,100000000000000);
  FOR(i,n-1){
    cin >> a >> b >> c;
    v[a].push_back(make_pair(b,c));
    v[b].push_back(make_pair(a,c));
  }
  int q,k;
  cin >> q >> k;
  
  ll x,y;
  dfs(k,0);
  FOR(i,q){
    cin >> x >> y;
    cout << saitan[x]+saitan[y] << endl;
  }

  
}


Measured memory_bytes: 12800