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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    string s,t;
    cin >> s >> t;

    multiset<char> S,T;
    set<char> SS,TT;
    rep(i,s.size())
    {
        S.insert(s[i]);
        SS.insert(s[i]);
    }
    rep(i,t.size())
    {
        T.insert(t[i]);
        TT.insert(t[i]);
    }

    vector<ll> useT;
    for(set<char>::iterator itr = TT.begin(); itr != TT.end(); ++itr) {
        useT.push_back( T.count(*itr) );
    }

    vector<ll> useS;
    for(set<char>::iterator itr = SS.begin(); itr != SS.end(); ++itr) {
        useS.push_back( S.count(*itr) );
    }

    sort(all(useT));
    sort(all(useS));
    if( useT.size() != useS.size() )
    {
        cout << "No" << endl;
    }
    else
    {
        rep(i,useT.size())
        {
            if(useT[i] != useS[i])
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
}


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

int main() {
  int n;
  cin >> n;
  int c=0,d=0;
  bool b[8]={};
  for ( int i=0; i<n; i++ ) {
    int a;
    cin >> a;
    if ( a>=3200 ) c++;
    else {
        b[a/400]=1;
    }
  }
  for ( int i=0; i<8; i++ ) {
    if ( b[i] ) d++;
  }
  cout << max(1,d) << ' ' << d+c << '\n';
  return 0; 
}


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

using namespace std;


int main(){

    //freopen("input.txt","r",stdin);

    long long int x,y,z;

    cin >> x >> y >> z;

    if ( x%z != 0){
       x = x + (z - x%z);
    }
    if(y % z != 0){
       y = y - y % z;
    }

    if(x>y) cout << 0 << endl;

    else cout << (y-x)/z + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

n = int(input())
s = input()
cnt = 0
for i in range(1000):
    c = str(i)
    one,two,three = -1,-1,-1
    if len(c)<3:
        while True:
            if len(c) == 3:
                break
            c = "0" + c
    for j in range(n):
        if s[j] == c[0]:
            one = j
            break
    if one != -1:
        for j in range(one+1,n):
            if s[j] == c[1]:
                two = j
                break
    if two != -1:
        for j in range(two+1,n):
            if s[j] == c[2]:
                three = j
                break
    if three != -1:
        cnt+=1
print(cnt)


Measured memory_bytes: 43740
#include<iostream>
int main()
{
  int n = 0;
  std::cin>>n;
  int count = 0;
  for(int a = 0; a < n; a++)
  {
    int nums[100][2];
    std::cin>>nums[a][0]>>nums[a][1];
    if(nums[a][0] == nums[a][1])
      count++;
    else
      count = 0;
    if(count == 3)
      break;
  }
  if(count == 3)
    std::cout<<"Yes";
  else
    std::cout<<"No";
}

Measured memory_bytes: 3100
while True:
    try:
        NA = True
        formula = raw_input()
        plus = formula.find('+')
        equal = formula.find('=')
        term1, term2, term3 = formula[:plus], formula[plus+1:equal], formula[equal+1:]
        for i in range(10):
            if len(term1) == 1 and len(term2) == 1 and len(term3) == 1:
                pass
            elif i == 0 and (term1[0] == 'X' or term2[0] == 'X' or term3[0] == 'X'):
                    continue
            if int(term1.replace('X', str(i))) + int(term2.replace('X', str(i))) == int(term3.replace('X', str(i))):
                NA = False
                print i
                break
        if NA: print "NA"
    except (EOFError):
        break

Measured memory_bytes: 4292
#include <iostream>

using namespace std;

int main()
{
    int x;
    int y;
    int z;
    int a;
    cin>>x>>y>>z;
    a=y*x;
    if(a>z)
    cout <<z<< endl;
    else if(a<z)
    cout <<a<< endl;
    else if(a==z)
    cout <<z<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1e9

int mp[1001][1001];
bool used[1001][1001];
int hw_count;
map<int, int> qmap;
int h, w;


int main()
{
	int first_count = 0;
	cin >> h >> w;
	queue<pair<int,int>> q;
	rep(i, h) {
		string s;
		cin >> s;
		rep(j, w) {
			if (s[j] == '#') {
				mp[i][j] = 1;
				first_count++;
				q.push(make_pair(i,j));
			} else {
				mp[i][j] = 0;
			}
		}
	}
	int count = first_count;
	int ans_count = 0;
	hw_count = h * w;
	if (first_count == hw_count) {
		cout << 0 << endl;
		exit(0);
	}
	while(1) {
		if (count == hw_count || q.empty()) {
			break;
		}
		ans_count++;
		queue<pair<int,int>> q2;
		while(!q.empty()) {
			pair<int,int> qq = q.front();
			int qi = qq.first;
			int qj = qq.second;
			q.pop();
			if (mp[qi][qj] == ans_count) {
				if (used[qi][qj] == true) {
					continue;
				}
				used[qi][qj] = true;
				if (qi + 1 < h) {
					if (mp[qi + 1][qj] == 0) {
						count++;
						mp[qi + 1][qj] = ans_count + 1;
						q2.push(make_pair(qi + 1,qj));
					}
				}
				if (qj + 1 < w) {
					if (mp[qi][qj + 1] == 0) {
						count++;
						mp[qi][qj + 1] = ans_count + 1;
						q2.push(make_pair(qi,qj + 1));
					}
				}
				if (qi - 1 >= 0) {
					if (mp[qi - 1][qj] == 0) {
						count++;
						mp[qi - 1][qj] = ans_count + 1;
						q2.push(make_pair(qi - 1, qj));
					}
				}
				if (qj - 1 >= 0) {
					if (mp[qi][qj - 1] == 0) {
						count++;
						mp[qi][qj - 1] = ans_count + 1;
						q2.push(make_pair(qi, qj - 1));
					}
				}	
			}
		}
		q = q2;
	}
	cout << ans_count << endl;
	return 0;
}

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

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 1000000007
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<int,int>


using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



string x;
int n;
bool check(int l, int r){
    while(l < r){
        if(x[l] != x[r])return 0;
        l++;
        r--;
    }
    return 1;
}
int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> x;
    n = x.length();
    int l = 0;
    int r = (n - 1) / 2 - 1;
    int l2 = (n + 3) / 2 - 1;
    int r2 = n -1;
    if(check(l,r) && check(l2,r2) && check(0,n-1)){
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
k, n = list(map(int, input().split()))
positions = list(map(int, input().split()))

diffs = [-1] * (n)
for i in range(n-1):
    diffs[i] = positions[i+1] - positions[i]
diffs[n-1] = positions[0] - positions[-1] + k

print(k - max(diffs))


Measured memory_bytes: 26436
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>

using namespace std;

const int MAX = 100000;

int main(){
    int n;
    int v[MAX];

    cin >> n;

    for(int i = 0;i < n;i++){
        cin >> v[i];
    }

    int table1[MAX+1] = {0};
    int table2[MAX+1] = {0};

    for(int i = 0;i < n;i+=2){
        table1[v[i]]++;
        table2[v[i+1]]++;
    }

    for(int i = 0;i <= MAX;i++){
        table1[i] = max(table1[i],table2[i]);
    }

    sort(table1,table1 + MAX + 1);

    cout << n - (table1[MAX - 1] + table1[MAX]) << endl;

    return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] T = new int[N];
    
    for (int i = 0; i < N; i++) {
      T[i] = sc.nextInt();
    }

    int M = sc.nextInt();
    int[] P = new int[M];
    int[] X = new int[M];

    for (int i = 0; i < M; i++) {
      P[i] = sc.nextInt() - 1;
      X[i] = sc.nextInt();
    }

    sc.close();

    for (int i = 0; i < M; i++) {
      int time = 0;
      for (int j = 0; j < N; j++) {
        if (P[i] == j) {
          time += X[i];
        } else {
          time += T[j];
        }
      }
      System.out.println(time);
    }

  }

}

Measured memory_bytes: 23636
#include<stdio.h>

#define N 36

char C[N],C_s[N];
int C2[N],C2_s[N];

void BubbleSort(int n){
  int i,j,flag;
  int x;
  char c;

  for(i=0;i<n-1;i++){
    flag = 1;
    while(flag){
      flag = 0;
      for(j=n-1;j>=i;j--){
	if(C2_s[j]<C2_s[j-1]){
	  x = C2_s[j];
	  c = C_s[j];
	  C2_s[j] = C2_s[j-1];
	  C_s[j] = C_s[j-1];
	  C2_s[j-1] = x;
	  C_s[j-1] = c;
	}
      }
    }
  }
}

void SelectionSort(int n){
  int i,j,minj;
  int x;
  char c;

  for(i=0;i<n-1;i++){
    minj = i;
    for(j=i;j<n;j++){
      if(C2[j]<C2[minj]){
	minj = j;
      }
    }
    if(minj!=i){
      c = C[i];
      x = C2[i];
      C[i] = C[minj];
      C2[i] = C2[minj];
      C[minj] = c;
      C2[minj] = x;
    }
  }
}

int main(){

  int n,flag;
  int i,j,minj;
  int x;
  char c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%c",&C[i]);
    if(C[i]!='D'&&C[i]!='C'&&C[i]!='H'&&C[i]!='S') scanf("%c",&C[i]);
    scanf("%d",&C2[i]);
  }


  for(i=0;i<n;i++){
    C_s[i] = C[i];
    C2_s[i] = C2[i];
  }

  BubbleSort(n);

  SelectionSort(n);
  

  for(i=0;i<n;i++){
    printf("%c%d",C_s[i],C2_s[i]);
    if(i<n-1) printf(" ");
  }
  printf("\nStable\n");
  
  for(i=0;i<n;i++){
    printf("%c%d",C[i],C2[i]);
    if(i<n-1) printf(" ");
  }

  flag = 0;
  for(i=0;i<n;i++){
    if(C2[i]!=C2_s[i] || C[i]!=C_s[i]){
      flag = 1;
      break;
    }
  }
  if(flag==0) printf("\nStable\n");
  else printf("\nNot stable\n");
  
  return 0;
}



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

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

typedef long long int ll;

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


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

  VI ans(N,0);
  FOR(i,1,N){
    ans[i] = N-i; 
  }

  FOR(i,1,N+1){
    FOR(j,i+1,N+1){
      if(abs(X-i) + abs(Y-j)+1 < j-i){
        ans[j-i]-=1;
        ans[abs(X-i) + abs(Y-j)+1]+=1;
      }
    }
  }
  FOR(i,1,N){
    cout << ans[i] << endl;
  }

}



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

typedef long long ll;
typedef unsigned long long ull;

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

    for(int x=M/N;x>=1;x--){
        if(M%x == 0){
            cout << x << endl;
            return 0;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:usize,
        k:i64,
        q:usize,
        ass:[usize1;q]
    }
    let mut ps = vec![0i64; n]; // 正解した回数
    for &a in ass.iter() {
        ps[a] += 1;
    }

    for i in 0..n {
        let point = k - (q as i64 - ps[i]);
        if point > 0 {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}


Measured memory_bytes: 6780
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;
#include <cstdio>
#include <tuple>
#include <string>
#include <vector> 
#include <set>
#include <string.h>
#include <map>
#include <cmath>
#include <deque>
using ll = long long;
using Graph = vector<vector<int>>;
#include <queue>
#include <stack>

int main(){

    int n;
    cin >> n;

    int p;
    if(n % 2 != 0) p = n/2 + 1;
    else p = n/2;
    cout << p << endl;
    

    return 0;
}

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

int main() {
    int n;
    std::string s, t;
    
    std::cin >> n;
    std::cin >> s >> t;
    
    for(int i = n; i >= 0; --i) {
        if(t.substr(0, i) == s.substr(s.size() - i, i)) {
            std::cout << n * 2 - i << std::endl;
            
            return 0;
        }
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String input = sc.next();

        while(!(input.equals("-"))){
            int time = sc.nextInt();
            for(int i = 0; i < time; i++){
                int place = sc.nextInt();
                input = input.substring(place) + input.substring(0, place);

            }
            System.out.println(input);
            input = sc.next();
        }
        sc.close();
    }
}


Measured memory_bytes: 26360
#include<iostream>
#include<climits>
#include<cstring>
using namespace std;

int helper(int arr[], int n) {
	int dp[100005];
	memset(dp,-1,sizeof dp);
	dp[n-1] = 0;
	
	for(int i=n-2;i>=0;i--){
		int option1  = abs(arr[i]-arr[i+1])+dp[i+1];
		int option2 = i==n-2?INT_MAX:abs(arr[i]-arr[i+2])+dp[i+2];
		dp[i] = min(option1,option2);
	}
	
	return dp[0];
}

int main() {
	int n;
	cin >> n;
	int arr[100005];
	for (int i = 0; i < n; i++)
		cin >> arr[i];
		
	cout << helper(arr, n) << endl;

	return 0;
}

Measured memory_bytes: 4300
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(long long &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned x){
  int s=0;
  char f[10];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(unsigned long long x){
  int s=0;
  char f[21];
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
inline void wt_L(double x){
  printf("%.15f",x);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
inline void wt_L(string &x){
  int i=0;
  for(i=0;x[i]!='\0';i++){
    putchar_unlocked(x[i]);
  }
}
long long solve(long long A){
  if(A < 0){
    return 0;
  }
  if(A%4==0){
    return A;
  }
  if(A%4==1){
    return 1;
  }
  if(A%4==2){
    return A+1;
  }
  return 0;
}
int main(){
  long long A;
  long long B;
  long long res;
  rd(A);
  rd(B);
  wt_L(solve(B) ^ solve(A-1));
  wt_L('\n');
  return 0;
}
// cLay varsion 20190925-1

// --- original code ---
// ll solve(ll A){
//   if(A < 0) return 0;
//   if(A%4==0) return A;
//   if(A%4==1) return 1;
//   if(A%4==2) return A+1;
//   return 0;
// }
// {
//   ll A, B, res;
//   rd(A,B);
//   wt(solve(B) ^ solve(A-1));
// }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mod 100000
typedef pair<int, int> P;
int n, m, s, ans;
int dp[2][2010][3010];
int main()
{
	while(cin >> n >> m >> s && n)
	{
		memset(dp, 0, sizeof(dp));
		dp[0][0][0] = 1;
		for(int i = 0; i < n * n; ++i)
		{
			for(int j = 0; j < m; ++j)
				for(int k = j; k < s; ++k)
					dp[1][j + 1][k + 1] = (dp[1][j][k]  + dp[0][j][k - j]) % mod;
			for(int j = 0; j <= m; ++j)
			{
				for(int k = 0; k <= s; ++k)
				{
					dp[0][j][k] = dp[1][j][k];
					dp[1][j][k] = 0;
				}
			}
		}
		ans = 0;
		for(int i = 0; i <= m; ++i)
		{
			ans += dp[0][i][s];
			ans %= mod;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 50264
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int a,b,x=0,i;
	scanf("%d%d",&a,&b);
	x=a*2-1;
	for(i=b-(a-1);i<=b+(a-1);i++){
		if(i>=-1000000&&i<=1000000) printf("%d ",i);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 1728
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <sstream>
typedef long long ll;
using namespace std;

int main(int argc, char const *argv[])
{
    int a, b;
    std::cin >> a >> b;
    if (a+b == 15) {
        std::cout << "+" << std::endl;
    } else if (a*b == 15) {
        std::cout << "*" << std::endl;
    } else {
        std::cout << "x" << std::endl;
    }
    return 0;
}

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

using namespace std;

#ifdef SG
	#include <debug.h>
#else
	#define show(...)
	#define debug(...)
	#define deepen(...)
	#define timer(...)
#endif

#define ARG4(_1,_2,_3,_4,...) _4

#define forn3(i,l,r) for (int i = int(l); i < int(r); ++i)
#define forn2(i,n) forn3 (i, 0, n)
#define forn(...) ARG4(__VA_ARGS__, forn3, forn2) (__VA_ARGS__)

#define ford3(i,l,r) for (int i = int(r) - 1; i >= int(l); --i)
#define ford2(i,n) ford3 (i, 0, n)
#define ford(...) ARG4(__VA_ARGS__, ford3, ford2) (__VA_ARGS__)

#define ve vector
#define pa pair
#define tu tuple
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fs first
#define sc second
#define all(a) (a).begin(), (a).end()
#define sz(a) ((int)(a).size())

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef unsigned char uc;
typedef pa<int, int> pii;
typedef pa<int, ll> pil;
typedef pa<ll, int> pli;
typedef pa<ll, ll> pll;
typedef ve<int> vi;

const ld pi = 3.1415926535897932384626433832795l;

template<typename T> inline auto sqr (T x) -> decltype(x * x) {return x * x;}
template<typename T1, typename T2> inline bool umx (T1& a, T2 b) {if (a < b) {a = b; return 1;} return 0;}
template<typename T1, typename T2> inline bool umn (T1& a, T2 b) {if (b < a) {a = b; return 1;} return 0;}

const int N = 100100;
vi a[N];
int d[N];
int n;

bool dfs(int v, int pr = -1) {
	ll sum = 0, maxx = -1;
	forn(i, sz(a[v])) {
		int to = a[v][i];
		if (to == pr) {
			continue;
		}
		if (!dfs(to, v)) {
			return false;
		}
		sum += d[to];
		umx(maxx, d[to]);
	}	
	if (maxx == -1) {
		return true;
	}
	ll x = 2 * d[v] - sum;
	if (x < 0 || x > sum) {
		return false;
	}
	ll val = min(2 * (sum - maxx), sum);
	if (val < sum - x) {
		return false;
	}
	if (pr == -1 && x > 0) {
		return false;
	}
	d[v] = x;
	return true;
}

int main () {
	cout.setf(ios::showpoint | ios::fixed);
	cout.precision(20);
#ifdef SG
	freopen((problemname + ".in").c_str(), "r", stdin);
//	freopen((problemname + ".out").c_str(), "w", stdout);
#endif
	cin >> n;
	forn(i, n) {
		scanf("%d", &d[i]);
	}
	forn(i, n - 1) {
		int u, v;
		scanf("%d%d", &u, &v);
		u--, v--;
		a[u].pb(v);
		a[v].pb(u);
	}
	if (n == 2) {
		if (d[0] == d[1]) {
			puts("YES");
		} else {
			puts("NO");
		}
		return 0;
	}
	int root = -1;
	forn(i, n) {
		if (sz(a[i]) > 1) {
			root = i;
			break;
		}
	}
	if (dfs(root)) {
		puts("YES");
	} else {
		puts("NO");
	}
	
	return 0;
}


Measured memory_bytes: 12800
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;


char next(char c) {
    if(c=='z') return 'a';
    return c+1;
}
char next(char c,int n) {
    rep(i,n) c=next(c);
    return c;
}
int n;
void solve() {
    string s;
    cin>>s;
    vector<int> a,b;
    rep(i,n) {
        int s,t;
        cin>>s>>t;
        s--,t--;
        a.pb(s);
        b.pb(t);
    }

    reverse(all(a));
    reverse(all(b));

    rep(i,n) {
        int d=abs(a[i]-b[i]);
        s[a[i]]=next(s[a[i]],d);
        s[b[i]]=next(s[b[i]],d);
        swap(s[a[i]],s[b[i]]);
    }
    cout<<s<<endl;
}
int main() {
    while(cin>>n) {
        if(n==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
int n, K, gcd, mx, a;
int main()
{
	cin >> n >> K;
	for(int i = 1;i <= n; ++ i){
		cin >> a;
		mx = max(mx, a);
		gcd = __gcd(gcd, a);
	}
	if(K % gcd == 0 && K <= mx)cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define tp tuple<int,int,int>
#define mtp make_tuple
using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,k;
    cin>>k>>a>>b;
    int val=(a/k);
    if(a%k) val++;
    val*=k;
    if(val<=b) cout<<"OK";
    else cout<<"NG";
}


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

int grouping(int n) {
  vector<int> g1 = {1, 3, 5, 7, 8, 10, 12};
  vector<int> g2 = {4, 6, 9, 11};
  for (int i = 0; i < g1.size(); i++) {
    if (n == g1.at(i)) {
      return 1;
    }
  }
  for (int i = 0; i < g2.size(); i++) {
    if (n == g2.at(i)) {
      return 2;
    }
  }
  return 3;
}

int main() {
  int x, y;
  cin >> x >> y;
  if (grouping(x) == grouping(y)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifndef ONLINE_JUDGE
#define debug(a) cout<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) #a<<" --> "<<(a)<<" , "
#define HERE cout<<"here - "<<__LINE__<<"\n";
#else
#define debug(a)
#define debug2(a)
#define HERE
#endif
const ll mod = 1e9+7 ;
const int N = 2e5 +5;
ll n,a,b,c,d;
map<ll,ll>mp;

ll solve(ll now)
{
    if(now==0)
    {
        return 0;
    }
    if(now==1)
    {
        return d;
    }
    if(mp.count(now))
        return mp[now];
    ll ans = 3e18;
    if(d*now>0)
    {
        ans = min(ans , d*now);
    }
    if(now%2==0)
    {
        ans = min(ans , a + solve(now/2));
    }
    else{
        ll md = now%2;
        ans = min(ans , a+ d*md + solve((now-md)/2));
        md = 2- md;
        ans = min(ans , a+ d*md + solve((now+md)/2));
    }
    if(now%3==0)
    {
        ans = min(ans , b + solve(now/3));
    }
    else{
        ll md = now%3;
        ans = min(ans , b+ d*md + solve((now-md)/3));
        md = 3- md;
        ans = min(ans , b+ d*md + solve((now+md)/3));
    }
    if(now%5==0)
    {
        ans = min(ans , c + solve(now/5));
    }
    else{
        ll md = now%5;
        ans = min(ans , c+ d*md + solve((now-md)/5));
        md = 5- md;
        ans = min(ans , c+ d*md + solve((now+md)/5));
    }
    return mp[now]= ans;
}

void TEST_CASES(int cas)
{
    mp.clear();
    scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
  	debug(mp);
    printf("%lld\n",solve(n));

}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }

    return 0;
}



//os.order_of_key(v): returns how many elements strictly less than v
//os.find_by_order()

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


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

//素数判定 O(√n)
bool isPrime(int n){
	if(n<=1)return false;
	for(int i=2;i*i<=n;i++)
		if(n%i==0)return false;
	return true;
}

bool isGaussianPrime(int a, int b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  if (a == 0) return b % 4 == 3 && isPrime(b);
  if (b == 0) return a % 4 == 3 && isPrime(a);
  return isPrime(a*a+b*b);
}

int main(){
	int t;
	cin>>t;
	while(t--){
		int m,n;
		cin>>m>>n;
		cout<<(isGaussianPrime(m,n)?'P':'C')<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
package main

import "fmt"

func main() {
	var a, b [4]int
	var c [3][3]int
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&c[i][j])
		}
	}

	for a[1] = 0; a[1] <= c[0][0]; a[1]++ {
		for a[2] = 0; a[2] <= c[1][0]; a[2]++ {
		Po:
			for a[3] = 0; a[3] <= c[2][0]; a[3]++ {
				b[1] = c[0][0] - a[1]
				b[2] = c[1][1] - a[2]
				b[3] = c[2][2] - a[3]
				for i := 0; i < 3; i++ {
					for j := 0; j < 3; j++ {
						if c[i][j] != a[i+1]+b[j+1] {
							continue Po
						}
					}
				}
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 512
#include <cstdio>
#include <string.h>

using namespace std;

namespace {

const size_t kHashSize = 244140624;

class Dictionary {
 public:
  Dictionary() : table_(new int[kHashSize]) {}
  ~Dictionary() { delete[] table_; }

  void insert(const char* k, size_t n) {
    const size_t i = Encode(k, n);
    table_[i] = 1;
  }

  bool find(const char* k, size_t n) const {
    return table_[Encode(k, n)] > 0;
  }

 private:
  static int Id(char c) {
      switch (c) {
        case 'A':
          return 1;
        case 'C':
          return 2;
        case 'G':
          return 3;
        case 'T':
          return 4;
      }
      // should not reach here.
      return 0;
  }

  static size_t Encode(const char* k, size_t n) {
    size_t h = 0;
    size_t p = 1;
    for (size_t i = 0; i < n; ++i) {
      h += p * Id(k[i]);
      p *= 5;
    }
    return h;
  }

  int* table_;
};

} // namespace

int main() {
  int n;
  scanf("%d", &n);

  Dictionary d;
  char op[7];
  char str[13];
  for (int i = 0; i < n; ++i) {
    scanf("%s ", op);
    scanf("%s", str);
    const char c = op[0];
    const size_t len = strnlen(str, 13);
    if (c == 'i') {
      d.insert(str, len);
      continue;
    }

    if (d.find(str, len)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

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

void solve(int TestCase) {
    long long a, b;
    cin >> a >> b;
    
    for(auto i = 0; i < 1000000; ++i)
    {
        if(i * 8 / 100 == a && i / 10 == b) {
            cout << i << endl;
            return;
        }
    }

    cout << -1 << endl;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 
    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
    //    cout << "Case #"<< i << ": ";
        solve(i);
    }
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  
  char a = s1[0] - 32;
  char b = s2[0] - 32;
  char c = s3[0] - 32;
  
  cout << a << b << c << endl;
  
  return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(int N){
  cout << ((N / 100 == 7 || (N % 100) / 10 == 7 || N % 10 == 7) ? YES : NO) << endl;
}

int main(){
    int N;
    cin >> N;
    solve(N);
    return 0;
}


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

int main(){
	string s,t;
	cin >> s >> t;

	int m = s.size();
	int n = t.size();

	int dp[m+1][n+1];

	for(int i=0;i<=m;i++){
		for(int j=0;j<=n;j++){
			if(i==0 || j==0){
				dp[i][j]=0;
			}
			else if(s[i-1]==t[j-1]){
				dp[i][j]=1+dp[i-1][j-1];
			}
			else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	//cout << dp[m][n] << "\n";
	if(dp[m][n]==0){
		cout << " ";
		return 0;
	}
	int x = dp[m][n];
	char lcs[x+1];
	lcs[x]='\0';
	int i=m;
	int j=n;
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			lcs[x-1] = s[i-1];
			i--;
			j--;
			x--;
		}
		else if(dp[i-1][j]>dp[i][j-1]){
			i--;
		}
		else{
			j--;
		}
	}
	cout << lcs;
	return 0;
}

Measured memory_bytes: 35456
from collections import deque
S = input()
que = deque()
que.append(S)
Q = int(input())
Front_flag = 1

for i in range(Q):
    Query = tuple(input().split())
    if len(Query) == 1:
        Front_flag = 1 - Front_flag
    else:
        a, b, c = Query
        if (Front_flag + int(b)) % 2 == 1:
            que.append(c)
        else:
            que.appendleft(c)

ans = ''.join(que)
if Front_flag:
    print(ans)
else:
    print(ans[::-1])

Measured memory_bytes: 6900
N, Y = gets.split.map(&:to_i)

O = 10000
P = 5000
Q = 1000


(Y/O+1).times do |i|

  break if (N - i < 0)
  
  ((Y-0*i)/P+1).times do |j|
      
    break if (N - i - j < 0)
    
    if (N - i - j) * Q == (Y - O * i - P * j)
      puts "#{i} #{j} #{N-i-j}"
      exit
    end
    
  end
    


end

puts "-1 -1 -1"

Measured memory_bytes: 3836
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        List<Integer> p = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            p.add(sc.nextInt());
        }
        int cnt1 = 0;
        int cnt2 = 0;
        int cnt3 = 0;
        for (int x : p) {
            if (x <= a) {
                cnt1++;
            }
            if (x > a && x <= b) {
                cnt2++;
            }
            if (x > b) {
                cnt3++;
            }
        }
        System.out.println(Math.min(cnt1, Math.min(cnt2, cnt3)));
    }
}


Measured memory_bytes: 23380
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        char[] cs = S.toCharArray();
        int count = 0;
        for (int i = 0; i < S.length() / 2; i++) {
            if (cs[i] != cs[S.length()-1-i]) {
                count++;
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 25044
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N,M;
ll X[1009],Y[1009],Z[1009];
ll mx=-LLINF;
bool x,y,z;

ll f(int i){
    ll res=0;
    res+=X[i]*(x?-1:1);
    res+=Y[i]*(y?-1:1);
    res+=Z[i]*(z?-1:1);
    return res;
}

void calc(){
    vector<ll> vec;
    rep(i,N) vec.push_back(f(i));
    sort(all(vec));
    reverse(all(vec));
    ll res=0;
    rep(i,M) res+=vec[i];
    chmax(mx,res);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    cin>>N>>M;
    rep(i,N) cin>>X[i]>>Y[i]>>Z[i];
    rep(i,2)rep(j,2)rep(k,2){
        x=i,y=j,z=k;
        calc();
    }
    cout1(mx)
}

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

Module Program
    Sub Main()
        Dim x As Integer = NextInt()
        Dim y As Integer = NextInt()

        Dim cnt As Integer = Integer.MaxValue

        For i As Integer = 1 To 4
            cnt = Math.Min(cnt, Solve(i, x, y))
        Next

        WriteLine(cnt)
    End Sub

    Function Solve(i As Integer, x As Integer, y As Integer) As Integer
        Dim cnt As Integer

        If i Mod 2 = 0 Then
            x *= -1
            cnt += 1
        End If

        If i <= 2 Then
            y *= -1
            cnt += 1
        End If

        If x <= y Then Return cnt + y - x
        Return Integer.MaxValue
    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: 20432
#B - Magic 2
A,B,C= map(int,input().split())
K = int(input())

for _ in range(K):
    if A < B:
        if B >= C:
            C = C*2
        else:
            pass
    else:
        B = B*2

if A < B <C :
    print("Yes")
else:
    print("No")

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

typedef long long ll;
typedef std::pair<ll, ll> P;

constexpr ll INF = 1e15;
constexpr ll mod = 1e9+7;

#define rep(i,n) for(int i = 0; i < int(n); i++)
using namespace std;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
    string s;
    cin >> s;
    ll x, y;
    cin >> x >> y;
    ll fx = 0;
    vector<ll> xys[2];
    int n = s.size();
    bool init = false;
    int direction = 0;
    rep(i, n) {
        bool r = s[i] == 'T';
        if (r) {
            init = true;
            direction++;
            direction%=2;
            xys[direction].push_back(0);
        }
        else {
            if (init) {
                xys[direction].back()++;
            }
            else {
                fx++;
            }
        }
    }
    x -= fx;
    bitset<32000> xbit, ybit;
    constexpr int center = 16000;
    xbit.set(center);
    ybit.set(center);
    for (auto p : xys[0]) {
        auto plus = xbit << p;
        auto minus = xbit >> p;
        xbit = plus | minus;
    }
    for (auto p : xys[1]) {
        auto plus = ybit << p;
        auto minus = ybit >> p;
        ybit = plus | minus;
    }
    if (xbit.test(x+center) && ybit.test(y + center)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3736
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
const int inf=1001001001; const long long INF=1001001001001001001;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>> >;
template<class T>using vv = vector<T>;
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; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int h, w, n, d[1001][1001];
char g[1001][1001];

int bfs(pii from , pii to) { 
  queue<pii> q;
  q.push(from);
  d[from.F][from.S] = 0;
  while (!q.empty()) {
    pii p = q.front(); q.pop();
    if (p == to) break;
    rep(i, 0, 4) {
      int nx = p.F + dx[i], ny = p.S + dy[i];
      if (0 <= nx && nx <h && 0 <= ny && ny < w && d[nx][ny] == -1 && g[nx][ny] != 'X') {
        d[nx][ny] = d[p.F][p.S] + 1;
        q.push({nx, ny});
      } 
    }
  }
  return d[to.F][to.S];
}

int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> h >> w >> n;
  pii v[10];
  string tmp = "S123456789";
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> g[i][j];
      for(int k=0;k<=n;k++){
        if(g[i][j] == tmp[k]) v[k] = {i,j};
      }
    }
  }
  int cnt = 0;
  for(int i=1;i<=n;i++){
    memset(d,-1,sizeof(d));
    cnt += bfs(v[i-1],v[i]);
  }
  cout << cnt << endl;
  return 0;
}




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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    int r,D;
    ll x;
    cin >> r >> D >> x;

    rep(i,10)
    {
        x = r * x - D;
        cout << x << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto& p : a) cin >> p;
  int q;
  cin >> q;
  while (q--) {
    int k;
    cin >> k;
    cout << lower_bound(a.begin(), a.end(), k) - a.begin() << endl;
  }
  return 0;
}


Measured memory_bytes: 3092
#include<iostream>
int a, b;
int n;
int s, f;
bool data[1010];
int main(){
	std::cin >> a >> b;
	std::cin >> n;
	for(int i = 0; i < n; i++){
		std::cin >> s >> f;
		for(; s < f; s++){
			data[s] = true;
		}
	}
	for(; a < b; a++){
		if(data[a]){
			std::cout << 1 << std::endl;
			return 0;
		}
	}
	std::cout << 0 << std::endl;
	return 0;
}



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

int N, L;

int main(void){
	cin >> N >> L;
	vector<string> s(N);
	rep(i, N) cin >> s[i];
	sort(s.begin(), s.end());
	string ans = "";
	rep(i, N) ans+=s[i];
	cout << ans << endl;
	return 0;
}


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

struct UnionFind{
    vector<int> d;
    UnionFind(int n): d(n,-1){}

    int root (int x){
        if(d[x] < 0) return x;
        return d[x] = root(d[x]);
    }

    bool unite(int x, int y){
        x = root(x); y = root(y);
        if(x == y)return false;
        if(d[x]>d[y])swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

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

    int size(int x){
        return -d[root(x)];
    }
};

int deg[100005];
vector<int> to[100005];

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        --a; --b;
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }

    rep(i,k){
        int a,b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    rep(i,n){
        int ans = uf.size(i) - 1 - deg[i];
        for(int u: to[i]){
            if(uf.same(i,u)) --ans;
        }
        printf("%d%c", ans , i==n-1?'\n':' ');
    }
    return 0;

}

Measured memory_bytes: 6784
#include <stdio.h>
 
#define MAX 200001
#define num 1000000007
 
long long a[MAX],b[MAX];
int H, W, A, B;
long long ans;
 
long long c(long long x,long long y){
    long long ret=1LL;
 
    while (y)   {
        if (y&1LL)        {
            ret*=x;
            ret%=num;
        }
        x*=x;
        x%=num;
        y>>=1LL;
    }
    return ret;
}
 
long long nCr(int n,int r){
    if(r==0||r==n)return 1;
    return ((a[n]*b[n-r]%num)*b[r]%num);
}
 
int main(){
    int i;
    scanf("%d %d %d %d",&H,&W,&A,&B);
 
    a[0]=1;
    for (i=1;i<=H+W;++i){
        a[i]=a[i-1]*i%num;
        b[i]=c(a[i],num-2);
    }
 
    for (i=B+1;i<=W;++i){
        ans+=nCr(H-A+i-2,i-1)*nCr(A+W-i-1,W-i)%num;
    }
    printf("%lld\n",ans%num);
 
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<unordered_map>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int, int>pii;
const int inf = 0x3f3f3f3f;
bool ok; char ch;
void read(int& x) {
	for (ok = 0, ch = getchar(); !isdigit(ch); ch = getchar()) if (ch == '-') ok = 1;
	for (x = 0; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	if (ok) x = -x;
}
void write(int x)
{
	if (x < 0) {
		putchar('-');
		x = -x;
	}
	if (x > 9)
		write(x / 10);
	putchar(x % 10 + '0');
	return;
}
map<string, int>mp;
int s[100000];
int main() {
	string a, b;
	cin >> a >> b;
	int x, y;
	cin >> x >> y;
	string c;
	cin >> c;
	if (a == c)cout << x - 1 << " " << y;
	else cout << x << " " << y - 1;

	return 0;
}

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

int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<vector<int>>sorce(n,vector<int>(m));
    vector<int>b(m);
    vector<int>seki(n,0);
    rep(i,m) cin>>b.at(i);
    rep(i,n) rep(j,m){
        cin>>sorce[i][j];
    }
    int cnt=0;
    rep(i,n){
        rep(j,m){
            seki.at(i)+=sorce[i][j]*b[j];
            
        }
        if(seki.at(i)+c>0) cnt+=1;
    }
    cout<<cnt<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
// 入力
int n;
int a[10010];  // 最大10000個ですが、少しだけ多めにとる

// DP テーブル
int dp[10010];


int main()
{
  string s;
  cin >> s;
  int c = 0;
  REP(i, 3)
  {
    if(s[i] =='o') ++c;
  }
  int price = 700 + 100*c;
  cout << price << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder.BC083
{
    public class B
    {
        public static void Main()
        {
            var nums = Console.ReadLine().Split(" ").Select(n => int.Parse(n)).ToArray();
            int sum = 0;

            for (int i = 1; i <= nums[0]; i++)
            {
                int d = DigitSum(i);
                if (nums[1] <= d && d <= nums[2]) sum += i;
            }

            Console.WriteLine(sum);
        }

        public static int DigitSum(int i)
        {
            int tmp = 0;

            while (i > 0)
            {
                tmp += i % 10;
                i /= 10;
            }

            return tmp;
        }
    }
}

Measured memory_bytes: 28204