akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define sz(a) int(a.size())
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define chu(x)  if(DEBUG_Switch) cout<<"["<<#x<<" "<<(x)<<"]"<<endl
#define du3(a,b,c) scanf("%d %d %d",&(a),&(b),&(c))
#define du2(a,b) scanf("%d %d",&(a),&(b))
#define du1(a) scanf("%d",&(a));
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
ll powmod(ll a, ll b, ll MOD) { if (a == 0ll) {return 0ll;} a %= MOD; ll ans = 1; while (b) {if (b & 1) {ans = ans * a % MOD;} a = a * a % MOD; b >>= 1;} return ans;}
ll poww(ll a, ll b) { if (a == 0ll) {return 0ll;} ll ans = 1; while (b) {if (b & 1) {ans = ans * a ;} a = a * a ; b >>= 1;} return ans;}
void Pv(const vector<int> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%d", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
void Pvl(const vector<ll> &V) {int Len = sz(V); for (int i = 0; i < Len; ++i) {printf("%lld", V[i] ); if (i != Len - 1) {printf(" ");} else {printf("\n");}}}
inline long long readll() {long long tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
inline int readint() {int tmp = 0, fh = 1; char c = getchar(); while (c < '0' || c > '9') {if (c == '-') fh = -1; c = getchar();} while (c >= '0' && c <= '9') tmp = tmp * 10 + c - 48, c = getchar(); return tmp * fh;}
void pvarr_int(int *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%d%c", arr[i], i == n ? '\n' : ' ');}}
void pvarr_LL(ll *arr, int n, int strat = 1) {if (strat == 0) {n--;} repd(i, strat, n) {printf("%lld%c", arr[i], i == n ? '\n' : ' ');}}
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
#define DEBUG_Switch 0
int main()
{
#if DEBUG_Switch
    freopen("C:\\code\\input.txt", "r", stdin);
#endif
    //freopen("C:\\code\\output.txt","w",stdout);
    int k = readint();
    int cnt = 0;
    int isok = 0;
    int now = 7;
    repd(i, 1, 20000000)
    {
        now %= k;
        if (now == 0)
        {
            cnt = i;
            isok = 1;
            break;
        }
        now *= 10;
        now += 7;
    }
    if (isok)
    {
        printf("%d\n", cnt);
    } else
    {
        printf("-1\n");
    }

    return 0;
}




Measured memory_bytes: 3752
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
 
public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			int[] array = new int[3];
			for(int i = 0; i < 3; i++) {
				array[i] = sc.nextInt();
			}
			Arrays.sort(array);
			
			System.out.println(Math.abs(array[0] - array[1]) + Math.abs(array[1] - array[2]));
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define IOS                \
  ios::sync_with_stdio(0); \
  cin.tie(0);              \
  cout.tie(0);
#define int long long
const unsigned int M = 1000000007;
using namespace std;
int32_t main()
{
  IOS int n;
  cin >> n;
  int ac = 0, wa = 0, tle = 0, re = 0;
  for (int i = 0; i < n; i++)
  {
    string s;
    cin >> s;
    if (s == "AC")
      ac++;
    if (s == "TLE")
      tle++;
    if (s == "WA")
      wa++;
    if (s == "RE")
      re++;
  }
  cout << "AC"
       << " "
       << "x" <<" "<< ac << endl;
  cout << "WA"
       << " "
       << "x"
       << " " << wa << endl;
  cout << "TLE"
       << " "
       << "x"
       << " " << tle << endl;
  cout << "RE"
       << " "
       << "x"
       << " " << re << endl;

  return 0;
}


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

bool path[9][9] = {};
int n, m;

int solve(int before, bool visit[]){
    bool judge = true;
    for(int i = 1; i <= n; i++){
        if(!visit[i])   judge = false;
    }

    if(judge){
        return 1;
    }

    int ret = 0;

    for(int j = 1; j <= n; j++){
        if(path[before][j] && !visit[j]){
            visit[j] = true;
            ret += solve(j, visit);
            visit[j] = false;
        }
    }

    return ret;
}

int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        path[a][b] = path[b][a] = true;
    }

    bool visit[9];
    for(int i = 1; i <= n; i++)  visit[i] = false;
    visit[1] = true;
    
    cout << solve(1, visit) << endl;
    return 0;
}

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

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

int n;
long long w;
const long long INF = 1LL << 60;
long long v[110];
long long s[110];
long long dp[110][100010] = {0};
long long max = 0;

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

    for(int i = 0; i < 110; ++i) 
    {
        for(int j = 0; j < 100010; ++j)
        {
            dp[i][j] = 0;
        }
    }

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

    for(int i = 0; i < n; ++i)
    {
        for(int j = 0; j <= w; ++j)
        {
            if(j - s[i] >= 0)
            {
                chmax(dp[i + 1][j], dp[i][j - s[i]] + v[i]);
            }

            chmax(dp[i + 1][j], dp[i][j]);
        }
    }

    cout << dp[n][w] << endl;
    return 0;
}

Measured memory_bytes: 86144
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int m = 0, a = 0, r = 0, c = 0, h = 0;
	int N;
	cin >> N;
	string S;
	for (int i = 0; i < N; i++) {
		cin >> S;
		if (S[0] == 'M') m++;
		if (S[0] == 'A') a++;
		if (S[0] == 'R') r++;
		if (S[0] == 'C') c++;
		if (S[0] == 'H') h++;
	}
	ll ans = 0;
	ans += (ll)m * a * r;
	ans += (ll)m * a * c;
	ans += (ll)m * a * h;
	ans += (ll)m * r * c;
	ans += (ll)m * r * h;
	ans += (ll)m * c * h;
	ans += (ll)a * r * c;
	ans += (ll)a * r * h;
	ans += (ll)a * c * h;
	ans += (ll)r * c * h;
	cout << ans << endl;
}

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

bool is_pal(string s) {
  string t(s.rbegin(), s.rend());
  return s == t;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;
  cin >> s;
  const int n = s.size();
  cout << (is_pal(s) && is_pal(s.substr(0, n / 2)) && is_pal(s.substr(n / 2 + 1)) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<math.h>
int main() {
	int a;
	std::string s;
	std::cin >> a >> s;
	if (a >= 3200) {
		std::cout << s << std::endl;
	}
	else {
		std::cout << "red" << std::endl;
	}
	return 0;
}

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


int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int k;
  int seven = 7;
  cin >> k;
  if (k%2 == 0) cout << "-1\n";
  else {
    int ans = 1;
    set<int> s;
    while (seven%k != 0) {
      if (s.count(seven%k)) {
        cout << "-1\n";
        return 0;
      }
      s.insert(seven%k);
      seven = seven*10 + 7;
      seven %= k;
      ++ans;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 50476
#include <stdio.h>
#define N 8
#define FREE -1
#define NOT_FREE 1

int row[N], col[N], dpos[15], dneg[15];

void printBoard() {
	int i,j;
	for (i = 0;i < N;i++) {
		for (j = 0;j < N;j++) {
			if(row[i] == j) printf("Q");
			else printf(".");
		}
		printf("\n");
	}
}

void putQueen(int i) {
	int j;
	if(i == N) {
		printBoard();
		return;
	}

	if(row[i] != FREE) putQueen(i+1);
	else {
		for(j = 0; j < N; j++) {
			if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+N-1] == NOT_FREE) continue;
			row[i] = j;
			col[j] = dpos[i+j] = dneg[i-j+N-1] = NOT_FREE;
			putQueen(i+1);
			col[j] = dpos[i+j] = dneg[i-j+N-1] = FREE;
			row[i] = FREE;
		}
	}
}

int main() {
	int i, j;
	int k,r,c;

	for(i = 0; i < N; i++) {
		row[i] = col[i] = FREE;
	}
	for(i = 0; i < 15; i++) {
		dpos[i] = dneg[i] = FREE;
	}

	scanf("%d", &k);
	for(i = 0; i < k; i++) {
		scanf("%d", &r);
		scanf("%d", &c);
		row[r] = col[c] = dpos[r+c] = dneg[r-c+N-1] = NOT_FREE;
		row[r] = c;
	}
	putQueen(0);

	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    rep(i, N)
    {
        cin >> A[i] >> B[i];
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    if (N % 2 == 1) {
        cout << B[N / 2] - A[N / 2] + 1 << endl;
    } else {
        cout << (B[(N - 1) / 2] + B[N / 2]) - (A[(N - 1) / 2] + A[N / 2]) + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 6356
program name
    implicit none
    integer(4):: n,t,i,nmin,nmax,cnt
    integer(4),allocatable:: a(:), p(:)

    read*, n,t
    allocate(a(n),p(n))
    read*, a(:)
    nmin = maxval(a)
    nmax=0
    do i=1,n
        nmin = min(nmin,a(i))
        p(i) = a(i)-nmin
        nmax = max(nmax,p(i))
    end do

    cnt=0
    do i=1,n
        if (p(i) == nmax) cnt=cnt+1
    end do
    print*, cnt
end program name

Measured memory_bytes: 1536
import math
N = int(input())
X = N / 1.08
X = int(X)
X2 = X - 1
X3 = X + 1
#print(X)
#print(math.floor(X * 1.08))
#print(math.floor(X2 * 1.08))
#print(math.floor(X3 * 1.08))
#print(X == int(X))
if N == math.floor(X * 1.08):
    print(int(X))
elif N == math.floor(X2 * 1.08):
    print(int(X2))
elif N == math.floor(X3 * 1.08):
    print(int(X3))
else:
    print(":(")


Measured memory_bytes: 3060
def alice_brown():
	x, y = map(int, raw_input().split())
	# when |x-y|>1, A have a strategy to choose a "i"
	# so that |x-y|<=1. As a result, no matter B choose what "i"
	# |x-y|>1 holds (which means A can always move on). So, A wins.
	if abs(x-y) <= 1:
		print "Brown"
	else:
		print "Alice"

if __name__ == "__main__":
	alice_brown()

Measured memory_bytes: 2568
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n;cin >> n;
    vector<int> a(n); rep(i,n) cin >> a[i];
    map<int,int> mp;
    long long int ans = 0;
    mp[a[0] + 1] = 1;
    for(int i=1;i<n;i++){
        int is = a[i] + i+1;
        int rd = i + 1 - a[i];
        if(mp.count(rd)==0) ans = ans;
        else ans = ans + mp[rd];

        if(mp.count(is)==0) mp[is] = 1;
        else mp[is] = mp[is]+1;
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13520
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int X = sc.nextInt();

		//Xとxiの差を計算してlistに入れる
		List<Integer> list = new ArrayList<>();
		for (int i = 0; i < N; i++) {
			list.add(Math.abs(sc.nextInt() - X));
		}

		//listから重複を削除してソートする
		Set<Integer> set = new HashSet<Integer>(list);
		list = new ArrayList<>(set);
		Collections.sort(list);

		//listの全要素の最大公約数を求める
		if (list.size() == 1) {
			System.out.println(list.get(0));
		} else {
			int D = list.get(0);
			for(int i=1;i<list.size();i++) {
				D = gcd(D,list.get(i));
			}
			System.out.println(D);
		}
	}

	public static int gcd(int a, int b) {
		if (b == 0)
			return a;
		else
			return gcd(b, a % b);
	}

}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};

int main() {
  int x, y;

  while(1) {
    cin >> x >> y;
    if(x+y == 0) break;
    if(x < y) swap(x, y);
    int cnt = 0;
    while(y != 0) {
      x = x%y;
      swap(x, y);
      cnt++;
    } 
    cout << x << ' ' << cnt << endl;
  }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main(){
  ll a,b;
  cin>>a>>b;
  if(a==b){
    rep(i,0,a){
      cout << a;
    }
    cout << endl;
  }
  else{
    if(a>b)swap(a,b);
    rep(i,0,b){
      cout << a;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int n  , ji = 0 , ou = 0 , a[1000001];
int main ()
{
	cin >> n ;
	for (int i = 1 ; i <= n ; i ++)
	cin >> a[i] ;
	for ( int i = 1 ; i <= n ; i ++)
	{
	     if ( a[i] % 2 == 0 )
	     ou ++ ;
	     else
	     ji ++ ;
	}
	if ( ji % 2 != 0 ) cout << "NO" ;
	else cout << "YES" ;
	return 0 ;
}

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

int main(){
  string S;
  int K;

  cin >> K >> S;
  if(S.size() <= K){
    cout << S << endl;
  }else{
    for(int i=0;i<K;++i){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

int main()
{
    int a, b;
    std::cin >> a >> b;

    if ((a * b) % 2 == 0) {
        std::cout << "No" << std::endl;
    } else {
        std::cout << "Yes" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define mod 1000000007
#define maxn 200010
#define LL long long
using namespace std;
LL f[maxn],inv[maxn];//f[i]=i!,inv[i]=j  i!的乘法逆元是j
LL quick_pow(LL a,LL b){
	LL ret=1;
	while(b){
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
LL C(LL n,LL m){
	LL ans;
	ans=f[n]*inv[n-m]%mod*inv[m]%mod;
	return ans;
}
int main(){
	LL n,k,i,ans=0;
	scanf("%lld%lld",&n,&k);
	f[0]=1;
	for(i=1;i<=n;i++)f[i]=f[i-1]*i%mod;
	for(i=0;i<=n;i++)inv[i]=quick_pow(f[i],mod-2)%mod;
	k=min(k,n-1);
	for(i=0;i<=k;i++)
		ans=(ans+C(n,i)*C(n-1,i)%mod)%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4820
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<queue>
#include<vector>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;

int main(){
  int N;
  int L[10];
  cin >> N;
  int max=0;
  int index;
  for(int i=0;i<N;i++){
    cin >> L[i];
    if(max<=L[i]){
      max = L[i];
      index = i;
    }
  }
  int sum=0;
  for(int i=0;i<N;i++){
    if(i!=index){
      sum+=L[i];
    }
  }
  if(max<sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll r,g,b,n,ans=0;
	cin >> r >> g >> b >> n;
	ll a=n/r;
	for(ll i=0;i<=a;i++){
		ll c=(n-i*r)/g;
		for(ll j=0;j<=c;j++){
			ll tmp=n-i*r-j*g;
			if(tmp>=0 && tmp%b==0) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
int N, M;
void func()
{
    string S;
    cin >> S;
    rep(i, 0, 3)
    {
        cout << S[i];
    }
    cout << '\n';
}
int main()
{
    func();
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long ll;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,sou[ohara],niku[ohara];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

ll dfs(ll le,ll pa){
    if(pa==0)return 0;
    else if(le==0)return 1;
    else if(pa<=sou[le-1]+1)return dfs(le-1,pa-1);
    else if(pa==sou[le-1]+2)return niku[le-1]+1;
    else if(pa<=sou[le-1]*2+2)return niku[le-1]+1+dfs(le-1,pa-2-sou[le-1]);
    else return niku[le-1]*2+1;
}

int main(void){
       cin.tie(0);
    ios::sync_with_stdio(false);
      
    cin>>n>>x;
    sou[0]=1;
    rrep(i,1,100){
        sou[i]=sou[i-1]*2+3;
    }
    niku[0]=1;
    rrep(i,1,100){
        niku[i]=2*niku[i-1]+1;
    }
    Cout(dfs(n,x));
    return 0;
}


Measured memory_bytes: 2304
while True:
  a,b=map(int, input().split())
  if a == 0 and b == 0:
    break
  for i in range(a):
    for j in range(b):
      if i>0 and i < a-1 and j>0 and j<b-1 and a>0 and b>0:
        print(".",end="")
      else:
        print('#',end='')
    print('')
  print('')
    

Measured memory_bytes: 7012
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
deque<int> t;
int n,k,change;
void typeA()
{
	for(int i=0;i<t.size();++i){
		if(t.at(i)==0){
			cout<<"A";
		}
		else cout<<"B";
	}
}
void typeB()
{
	for(int i=0;i<t.size();++i){
		if(t.at(i)==0){
			cout<<"B";
		}
		else cout<<"A";
	}
}
int main()
{
	char c;
	cin>>n>>k;
	for(int i=1;i<=n;++i){
		cin>>c;
		if(c=='A'){
			t.push_back(0);
		}
		else{
			t.push_back(1);
		}
	}
	for(int i=1;i<=min(k,2*n);++i){
		int temp=t.front();
		t.pop_front();
		if(change%2==0)
		{
			if(temp==0){
				t.push_front(1);
			}
			else{
				change++;
				t.push_back(1);
			}
		}
		else{
			if(temp==1){
				t.push_front(0);
			}
			else{
				change++;
				t.push_back(0);
			}
		}
//		for(int i=0;i<t.size();++i){
//			cout<<t.at(i);
//		}
//		cout<<" "<<change<<endl;
	}
//	cout<<change<<" "<<endl;
	if(k>2*n){
		k-=2*n;
		if(k%2==1){
			int temp=t.front();
			t.pop_front();
			if(change%2==0)
			{
				if(temp==0){
					t.push_front(1);
				}
				else{
					change++;
					t.push_back(1);
				}
			}
			else{
				if(temp==1){
					t.push_front(0);
				}
				else{
					change++;
					t.push_back(0);
				}
			}
			if(change%2==0) typeA();
			else typeB();	
		}
		else{
			if(change%2==0) typeA();
			else typeB();
		}
		return 0;
	}
	if(change%2==0){
		for(int i=0;i<t.size();++i){
			if(t.at(i)==0){
				cout<<"A";
			}
			else cout<<"B";
		}
	}
	else{
		for(int i=0;i<t.size();++i){
			if(t.at(i)==1){
				cout<<"A";
			}
			else cout<<"B";
		}
	}
	return 0;
}

Measured memory_bytes: 1280
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int MOD =  1000000007;
    boolean move[] = new boolean[N+3];
    //初期化
    for (int i=0;i<N+3;i++){
      move[i] = true;
    }
    for (int i=0;i<M;i++){
      int a = sc.nextInt();
      move[a] = false;
    }
    
    int DParray[] = new int[N+5];
    for (int i=0;i<N+3;i++){
      DParray[i] = 0;
    }
    DParray[0] = 1;
    
    for (int i=0;i<N;i++){
      if(move[i+1]){
        DParray[i+1] += DParray[i];
        DParray[i+1] %= MOD;
      }
      if(move[i+2]){
        DParray[i+2] += DParray[i];
        DParray[i+2] %= MOD;
      }
    }
    
    System.out.println(DParray[N]%MOD);
  }
}
  

Measured memory_bytes: 47092
#include <stdio.h>
int main(void){
   int N;
   int num[100];
   int i,j,num_min=101,num_max=-101;
   int min = 1000000,ans;
   
   scanf("%d",&N);
   
   for(i=0;i<N;i++){
       scanf("%d",&num[i]);
       if(num_min > num[i]){
           num_min = num[i];
       }
       if(num_max < num[i]){
           num_max = num[i];
       }
   }
   
   for(i=num_min;i<=num_max;i++){
       ans = 0;
       for(j=0;j<N;j++){
           ans += (i-num[j])*(i-num[j]);
       }
       if(min > ans){
           min = ans;
       }
   }
   printf("%d\n",min);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    char x,y;

    cin >>x >> y;
    if(x < y){
        cout << '<' << endl;
    }else if(x > y){
        cout << '>' << endl;
    }else{
        cout << '=' << endl;
    }
}

Measured memory_bytes: 256
from collections import deque


def nearlist(N, LIST):
    NEAR = [set() for _ in range(N)]
    for a, b in LIST:
        NEAR[a - 1].add(b - 1)
        NEAR[b - 1].add(a - 1)
    return NEAR


def bfs(NEAR):
    que, frag = deque([0]), set([0])
    while que:
        q = que.popleft()
        for i in NEAR[q]:
            if i in frag:
                continue
            ans[i] += ans[q]
            que.append(i), frag.add(i)
    return

n, q = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n - 1)]
px = [list(map(int, input().split())) for _ in range(q)]

ans = [0] * n
for p, x in px:
    ans[p - 1] += x

near = nearlist(n, ab)
bfs(near)
print(*ans)

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

#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)

const int mxN = (1<<18)+5;
const int mxW = 1e5+5;
int N, V[mxN], W[mxN], Q;
int dp[(1<<9)+5][mxW];

int lim = (1<<9)-1;
void dfs(int i) {
    int p = i/2;
    FOR(x,0,mxW-1){
        dp[i][x] = dp[p][x];
        if (x >= W[i]) dp[i][x] = max(dp[i][x], dp[p][x-W[i]]+V[i]);
    }
    if (i*2 <= lim) dfs(i*2);
    if (i*2+1 <= lim) dfs(i*2+1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    lim = min(lim,N);
    FOR(i,1,N){
        cin >> V[i] >> W[i];
    }
    dfs(1);
    cin >> Q;
    FOR(i,1,Q){
        int v, L; cin >> v >> L;
        if (v <= lim) cout << dp[v][L] << '\n';
        else {
            vector<int> vec;
            int u;
            for (u = v; u > lim; u /= 2) {
                vec.push_back(u);
            }
            int ans = 0;
            int k = SZ(vec);
            FOR(x,0,(1<<k)-1){
                int sw = 0, sv = 0;
                FOR(j,0,k-1) if (x&(1<<j)) sw += W[vec[j]], sv += V[vec[j]];
                if (sw <= L) ans = max(ans,sv+dp[u][L-sw]);
            }
            cout << ans << '\n';
        }
    }
}



Measured memory_bytes: 205340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n;
string s;
map<string,int>S;
int main(){
	cin>>n;
	rep(i,n){
		cin >> s;
		sort(s.begin(),s.end());
		S[s]++;
	}
	ll ans = 0;
	for(auto A:S) ans += 1LL*A.sc*(A.sc-1)/2;
	cout<<ans<<endl;
}

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

int main(void) {
  int N;
  int t=0,x=0,y=0;

  scanf("%d", &N);

  for (int i =0; i < N; i++) {
    int t1,x1,y1;
    scanf("%d%d%d",&t1,&x1,&y1);
    int dt = abs(t1 - t);
    int dx = abs(x1 - x);
    int dy = abs(y1 - y);
    if (dx + dy > dt || (dt - dx - dy) % 2 ) {
      printf("No");
      return 0;
    }
    t = t1;
    x = x1;
    y = y1;
  }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 1712
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxd = 1e5+10;
int a[maxd],b[maxd],n;
int main()
{
    // freopen("a.in","r",stdin);
    // freopen("k.out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n+1;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) scanf("%d",&b[i]);
	long long ans = 1ll * min(a[1],b[1]);
	b[1] -= ans;	
	for(int i=2;i<=n+1;i++)
	{
		int k = min(a[i],b[i-1]);
		ans += k;
		a[i] -=k;
		if(i==n+1) break;
		k = min(a[i],b[i]);
		ans += k;
		b[i] -=k;
	}
	printf("%lld",ans);
    return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <vector>

using namespace std;

int main() {
    int n;  cin >> n;
    int *a = new int[n];
    int **x = new int*[n], **y = new int*[n];

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        x[i] = new int[a[i]], y[i] = new int[a[i]];

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

    int ans = 0;
    for (int bit = 0; bit < (1<<n); bit++) {
        vector<int> s;

        for (int i = 0; i < n; i++) {
            if (bit & (1<<i)) {
                s.push_back(i);
            }
        }

        bool can = true;    int sum = 0;
        for (int i = 0; i < s.size(); i++) {
            int k = s[i];

            for (int j = 0; j < a[k]; j++) {
                if (y[k][j]) {
                    int x_ = x[k][j];
                    bool check = false;
                    for (int l = 0; l < s.size(); l++) {
                        if (s[l] == x_)
                            check = true;
                    }
                    if (!check)
                        can = false;
                }
                else {
                    int x_ = x[k][j];
                    for (int l = 0; l < s.size(); l++) {
                        if (s[l] == x_)
                            can = false;
                    }
                }
            }
        }

        if (can)
            ans = max(ans, (int)s.size());
    }

    cout << ans << endl;

    return 0;
}

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

class Program
{
	static void Main()
	{
		var s = Console.ReadLine();

		var sCount = 0;
		var delCount = 0;
		foreach (var c in s) {
			if (sCount > 0) {
				if (c == 'S') {
					++sCount;
				} else {
					--sCount;
					++delCount;
				}
			} else if (c == 'S') {
				++sCount;
			}
		}

		Console.WriteLine(s.Length - (delCount * 2));

		//デバッグ実行での確認用。そのまま提出しても問題なし
		Console.ReadKey();
	}
}


Measured memory_bytes: 11616
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<ll,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n % i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n, p;
  cin >> n >> p;
  vector<pair<ll,int>> res = factorize(p);
  ll ans = 1;
  rep(i,(int)res.size()) {
    debug(res[i].first, res[i].second);
    ans *= pow(res[i].first, res[i].second/n);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

long long inf=1000000007;

int main(){
	int n;
	cin>>n;
	vector<int> mon(n+1,-1);

	queue<int> que;
	mon.at(0)=0;
	que.push(0);

	while(!que.empty()){
		int now=que.front();
		que.pop();
		if(now==n){
			cout<<mon.at(now)<<endl;
			return 0;
		}

		int pre=now+1;
		if(pre<=n && mon.at(pre)==-1){
			mon.at(pre)=mon.at(now)+1;
			que.push(pre);
		}

		for(int i=6;now+i<=n;i*=6){
			if(mon.at(now+i)!=-1) continue;

			mon.at(now+i)=mon.at(now)+1;
			que.push(now+i);
		}

		for(int i=9;now+i<=n;i*=9){
			if(mon.at(now+i)!=-1) continue;

			mon.at(now+i)=mon.at(now)+1;
			que.push(now+i);
		}
	}

	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
int main(void){
int s;
int S=0;
int m=100;
int i=0;
    
for(;~scanf("%d",&s);i++&&(S+=s))i&&s%10&&(m=fmin(m,s));
m>99&&(S=m);
printf("%d",S%10?S:S-m);
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

struct edge{ int to,cost; };
const int INF=123456789;

vector<edge> G[100];
int d[100][3];

int main()
{
    int n,m;
    while(scanf(" %d %d", &n, &m),n)
    {
        rep(i,100) G[i].clear();
        fill(d[0],d[100],INF);

        rep(i,m)
        {
            int a,b,c;
            scanf(" %d %d %d", &a, &b, &c);
            --a; --b;
            G[a].pb(edge{b,c});
            G[b].pb(edge{a,c});
        }

        queue<pi> que;
        que.push(pi(0,0));
        d[0][0]=0;
        while(!que.empty())
        {
            pi now=que.front(); que.pop();
            int v=now.fi;
            int st=now.se;

            if(st==1)
            {
                rep(i,G[v].size())
                {
                    edge e=G[v][i];
                    if(d[e.to][2]>d[v][st])
                    {
                        d[e.to][2]=d[v][st];
                        que.push(pi(e.to,2));
                    }
                }
            }
            else
            {
                rep(i,G[v].size())
                {
                    edge e=G[v][i];
                    if(d[e.to][st]>d[v][st]+e.cost)
                    {
                        d[e.to][st]=d[v][st]+e.cost;
                        que.push(pi(e.to,st));
                    }
                }

                if(st==0)
                {
                    rep(i,G[v].size())
                    {
                        edge e=G[v][i];
                        if(d[e.to][1]>d[v][st])
                        {
                            d[e.to][1]=d[v][st];
                            que.push(pi(e.to,1));
                        }
                    }

                }
            }
        }

        printf("%d\n", min(d[n-1][0],d[n-1][2]));
    }
    return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

//for debugging 
/*
g++ -D_GLIBCXX_ASSERTIONS -DDEBUG -ggdb3 -std=c++14 
*/
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) {++recur_depth; auto x_=x; --recur_depth; cerr<<string(recur_depth, '\t')<<"\e[91m"<<__func__<<":"<<__LINE__<<"\t"<<#x<<" = "<<x_<<"\e[39m"<<endl;}
#else
#define dbg(x)
#endif
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	os<<"[";
	for(auto& x:v){os<<x<<", ";}
	return os<<"]";
}
template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os<<"{"<<p.first<<", "<<p.second<<"}";
}
// debugging ends here

typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;

void solve(){
	ll n;
	cin >> n;
	ll ans = 0;
	for(ll i = 1;i<n;i++){
		ll check = n-i;
		map<ll,int> count;
		for(ll j = 2;j*j<=check;j++){
			if(check%j==0){
				int cur = 0;
				while(check%j==0){
					cur++;
					check/=j;
				}
				count[j] = cur;
			}
		}
		if(check>1){
			count[check] = 1;
		}
		ll cur = 1;
		for(auto e:count){
			cur*=(e.second+1);
		}
		ans+=cur;
	}
	cout << ans << endl;
}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
typedef long long ll;
const ll INF = 1LL<<60;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) {return (x+y)%MOD;}
inline ll mul(ll x, ll y) {return (x*y)%MOD;}
inline ll sub(ll x, ll y) {
    ll res = x - y;
    if(res < 0) res += MOD;
    return res;
}

int main(){
    int N, K; cin >> N >> K;
    vector<ll> H(N);
    REP(i,N) cin >> H[i];
    sort(all(H));
    ll ans = 0;
    for(int i=0; i<N-K; ++i) ans += H[i];
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct Point {
  int y, x;
  Point(){}
  Point(int y, int x):y(y), x(x){}
  int operator-(Point p) {
    return abs(y-p.y)+abs(x-p.x);
  }
};

int dp[5][1001];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int w, h;
  while(cin >> w >> h, w+h) {
    Point s, g;
    vector<Point> ps[5];
    set<char> st;
    rep(i, h) rep(j, w) {
      char c;
      cin >> c;
      if(c == '.') continue;
      Point p(i, j);
      if(c == 'S') s = p;
      else if(c == 'G') g = p;
      else if(isdigit(c)) ps[c-'0'-1].push_back(p);
      st.insert(c);
    }
    /*
    if(st.size() < 7) {
      cout << "NA" << endl;
      return 0;
    }
    */
    int ans = inf;
    int sel = -1;
    rep(i, 5) {
      fill(dp[0], dp[5], inf);
      dp[i][0] = 0;
      rep(j, 4) {
	int prev = (i+j)%5;
	int next = (i+j+1)%5;
	int sz = (prev == i ? 1 : ps[prev].size());
	rep(k, sz) {
	  if(dp[prev][k] == inf) continue;
	  int val = dp[prev][k];
	  Point p = (prev == i ? s : ps[prev][k]);
	  rep(l, ps[next].size()) {
	    Point q = ps[next][l];
	    chmin(dp[next][l], val + (q-p));
	  }
	}
      }
      int last = (i+4)%5;
      rep(j, ps[last].size()) {
	if(dp[last][j] == inf) continue;
	Point p = ps[last][j];
	int val = dp[last][j] + (g-p);
	if(val < ans) {
	  ans = val;
	  sel = i+1;
	}
      }
    }
    if(ans == inf) cout << "NA" << endl;
    else cout << sel << " " << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  vector<int>V(N);
  vector<int>C(N);
  for (int i = 0; i < N; i++) {
    cin >> V.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> C.at(i);
  }
  vector<int>A(N);
  for (int i = 0; i < N; i++) {
    A.at(i) = V.at(i) - C.at(i);
  }
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) > 0){
      sum += A.at(i);
    }
  }
  cout << sum << endl;
}
 

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    if(n == 0){
        cout << 0 << endl;
    }
    long long temp = 2,sum = 0,spare1,spare2;
    int i = 0;
    vector<int> array;
    while(n != sum){
        spare1 = n%temp;
        if(spare1 < 0){spare1 += temp;}
        spare2 = sum%temp;
        if(spare2 < 0){spare2 += temp;}
        if(spare1 != spare2){
            if(i%2 == 0){
                sum += temp/2;
            }else{
                sum -= temp/2;
            }
            array.push_back(1);
        }else{
            array.push_back(0);
        }
        ++i;
        temp *= 2;
    }
    for(i = array.size()-1;i >= 0;--i){
        cout << array.at(i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>


#define REP(i,N) for(auto i = 0; i <N; i++)
const int MAX = INT_MAX;
using namespace std;
typedef long long ll;


int in(){
    int temp;
    scanf("%d",&temp);
    return temp;
}

ll lin(){
    ll temp;
    scanf("%lld",&temp);
    return temp;
}



int main() {

    int N = in();
    
    int F[N][11];
    
    for(auto i = 0; i<N; i++){
        
        for(auto j = 1; j<11; j++){
            F[i][j] = in();
        }
        
    }
    
    int P[N][11];
    
    for(auto i = 0; i<N; i++){
        
        for(auto j = 0; j<11; j++){
            P[i][j] = in();
        }
        
    }
    
    // P[i][j] は, iとjoisino店が共通して空いている時間の個数がjのときの利益.
    
    int profitMax = -MAX;
    
    int profit;
    
    for(auto i = 1; i< (1<<10); i++){
        
        profit = 0;
        
        int open[11];
        
        for(auto j = 1; j <11; j++){
            
            open[j] = (i>>(j-1))&1; //オープンしているスロットに 1
            
        }
        
        
        for(auto k = 0; k<N; k++){
            
            auto countTemp = 0;
            
            for(auto l = 1; l<11; l++){
                
                countTemp += (open[l]==1 && F[k][l] == 1);
                
            }
            
            profit += P[k][countTemp]; /// 0 <= countTemp <=10
            
        }

        if (profitMax < profit) profitMax = profit;
        
        
    }
    cout << profitMax << endl;
    
    return 0;
}


                          
                        




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 200200;
const int MV = 1e6+10;
const ll M = 998244353;
typedef vector<ll> vl;
ll w[MN],sf[MV];
ll sa[MV],sb[MV];
ll fr[MV];
inline ll mul(ll a, ll b) {return (a*b)%M;}
ll bp(ll b, ll p) {
	ll ac = 1;
	while(p) {
		if(p&1) {ac = mul(b,ac);}
		b = mul(b,b);
		p >>= 1;
	}
	return ac;
}
inline ll inv(ll v) {
	return bp(v,M-2);
}
void pre() {
	memset(fr,0,sizeof(fr));
	memset(sf,0,sizeof(sf));
	/*
	for(int i=1;i<=MV;i++) {
		for(int j=1;j*i<MV;j++) {
			fac[j*i].push_back(i);
		}
	}
	*/
	for(int i=1;i<MV;i++) {
		sf[i] += inv(i);
		if(sf[i] < 0)  {
			sf[i] = sf[i]%M+M;
		}
		for(int j=2;i*j<MV;j++) {
			sf[i*j] -= sf[i];
		}
	}
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	ll H = inv(2);
	cin >> n;
	pre();
	for(int i=0;i<n;i++) {
		cin >> w[i];
		fr[w[i]]++;
	}
	ll res = 0;
	for(int i=1;i<MV;i++) {
		for(int j=1;j*i<MV;j++) {
			ll sm = (i*j);
			sa[i] += (sm*fr[i*j])%M;
			sb[i] += (((sm*sm)%M)*fr[i*j])%M;
		}
		sa[i] %= M;
		sb[i] %= M;
		//cout << sa[i] << " -* " << sb[i] << "*" << sf[i] << '\n';
		res += (sf[i]*((sa[i]*sa[i]-sb[i])%M)%M)*H;
		//cout << ((sf[i]*((sa[i]*sa[i]-sb[i])%M)%M)*H)%M << '\n';
		res %= M;
	}
	cout << res << '\n';
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if ( a == 1 && b == 2 || a == 2 && b == 1 ) {
        cout << 3 << endl;
    }
    else if ( a == 2 && b == 3 || a == 3 && b == 2 ) {
        cout << 1 << endl;
    }
    else {
        cout << 2 << endl;
    }
    return 0;
}


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

#define INF 0x3f3f3f3f
#define NINF -0x3f3f3f3f

using namespace std;

typedef pair<int,int> pii;

char str[200005];
int total[30];

int main ()
{
	scanf("%s",str);
	
	int len = strlen(str);
	
	long long ans = 1;
	for (int i = 0; i < len; i += 1)
	{
		int idx = str[i]-'a';
		
		int diff = i-total[idx];
		total[idx]++;
		
		ans += diff;
		
	}
	
	printf("%lld\n",ans);
	
	return 0;
}


Measured memory_bytes: 384
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        k: usize,
    }
    let mut f = vec![false; k];
    let mut x = 0;
    for i in 1.. {
        x *= 10;
        x += 7;
        x %= k;
        if x == 0 {
            println!("{}", i);
            break;
        }
        if f[x] {
            println!("-1");
            return;
        }
        f[x] = true;
    }
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
#define EPS (1e-10)
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	string s[3]; rep(i,3) cin>>s[i];
	int l[3]; rep(i,3) l[i]=s[i].size();
	int idx[3]; CLR(idx);
	int now=0;
	while(idx[now]<l[now]){
		int next=s[now][idx[now]]-'a';
		idx[now]++;
		now=next;
		// cerr<<now<<endl;
		// rep(i,3) cerr<<idx[i]<<' ';
		// cerr<<endl;
	}
	cout<<(char)('A'+now)<<endl;
	return 0;
}


Measured memory_bytes: 256