akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

constexpr int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
constexpr int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    vector<int> a(n);
    vector<lint> b(n);
    rep(i, n){
        cin >> a[i] >> b[i];
    }

    lint ans = 0;
    int tmp = 0;
    lint val = 0;
    rep(i, 31){
        if(k >> i & 1){
            tmp = 0;
            val = 0;
            for(int j = 30 ; j > i ; --j){
                tmp |= (k >> j & 1) << j;
            }
            for(int j = 0 ; j < i ; ++j){
                tmp |= 1 << j;
            }
            rep(j, n){
                if((a[j] | tmp) <= tmp){
                    val += b[j];
                }
            }
            chmax(ans, val);
        }
    }

    tmp = k;
    val = 0;
    rep(j, n){
        if((a[j] | tmp) <= tmp){
            val += b[j];
        }
    }
    chmax(ans, val);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <numeric>
#include <random>
#include <vector>
#include <array>
#include <bitset>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
 
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

int main() {
    int n;
    cin >> n;
    switch(n % 10){
        case 2:
        case 4:
        case 5:
        case 7:
        case 9: cout << "hon"; break;
        case 0:
        case 1:
        case 6:
        case 8: cout << "pon"; break;
        case 3: cout << "bon";
    }
    
    
    
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    if (S == "AAA" or S == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
d = Counter(a)
key = list(d.keys())

ans = 0
for k in key:
    if k > d[k]:
        ans += d[k]
    elif k == d[k]:
        pass
    else:
        ans += d[k] - k
print(ans)

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - ABC Swap
            var line = ReadLine();
            var X = line[0];
            var Y = line[1];
            var Z = line[2];

            Console.WriteLine("{0} {1} {2}", Z, X, Y);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> arr(N);
  for(int i =0; i < N; i++) cin >> arr[i];

  sort(arr.begin(), arr.end());
  double cur = arr[0];
  for(int i = 1; i < N; i++)
    cur = (cur + arr[i]) / 2.0;
  printf("%.12lf", cur);
}



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

int getP(int X[], int N)
{
    double ave = 0;
    for (int i = 0; i < N; i++)
    {
        /* code */
        ave += X[i];
    }
    ave /= N;
    return round(ave);
}
int calcCost(int X[], int N)
{
    int cost = 0;
    int P = getP(X, N);
    for (int i = 0; i < N; i++)
    {
        cost += pow(X[i] - P, 2);
    }
    return cost;
}

int main(){
    int N, X[100];
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        /* code */
        cin >> X[i];
    }

    cout << calcCost(X, N) << endl;
}

Measured memory_bytes: 3700
n = int(input())
an = []
if n % 2 == 0:
    a = 1
else:
    a = 0

for i in range(n,0,-1):
    for j in range(1, i):
        if j != a:
            an.append([i,j])
    a += 1
print(len(an))
for i in an:
    print(i[0], i[1])

Measured memory_bytes: 4112
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

#n = int(input())
m,d = [int(i) for i in readline().split()]
#xy = [[int(i) for i in readline().split()] for i in range(n)]

ans = 0
for d in range(1,d+1):
    for j in range(1,m+1):
        dd, ddd = d//10, d%10
        if dd >= 2 and ddd >= 2 and j == dd*ddd:
            ans += 1

print(ans)












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

n,k=map(int,input().split())
xy=[list(map(int,input().split())) for i in range(n)]
ru=[[0]*(n+1) for i in range(n+1)]
lst=sorted(xy)
lst2=sorted(xy,key=lambda x: x[1])

for i in range(n):
    for j in range(n):
        flag=0
        for l in range(n):
            if xy[l]==[lst[i][0],lst2[j][1]]:
                flag=1
        if flag:
            ru[i+1][j+1]=1
        ru[i+1][j+1]+=ru[i+1][j]+ru[i][j+1]-ru[i][j]
# print(ru)
xdic=defaultdict(int)
ydic=defaultdict(int)
for i in range(n):
    xdic[lst[i][0]]=i+1
    ydic[lst2[i][1]]=i+1
# print(xdic)
# print(ydic)
lst=[0]*n
lst2=[0]*n
for i in range(n):
    x,y=xy[i]
    lst[i],lst2[i]=x,y
lst,lst2=list(permutations(lst,2)),list(permutations(lst2,2))
ans=float('inf')
for i in range(len(lst)):
    xl,xr=min(lst[i]),max(lst[i])
    for j in range(len(lst2)):
        yl,yr=min(lst2[j]),max(lst2[j])
        # print(ru[xdic[xr]][ydic[yr]]-ru[xdic[xr]][ydic[yl]-1]-ru[xdic[xl]-1][ydic[yr]]+ru[xdic[xl]-1][ydic[yl]-1])
        if ru[xdic[xr]][ydic[yr]]-ru[xdic[xr]][ydic[yl]-1]-ru[xdic[xl]-1][ydic[yr]]+ru[xdic[xl]-1][ydic[yl]-1] >=k:
            ans=min(ans,(xr-xl)*(yr-yl))
print(ans)

Measured memory_bytes: 72280
H, W = map(int,input().split())
HW = [input() for _ in range(H)]
HW = ["".join(hw) for hw in zip(*HW) if hw.count("#") > 0]
HW = ["".join(hw) for hw in zip(*HW) if hw.count("#") > 0]
print("\n".join(HW))

Measured memory_bytes: 3316
s = input()
year = int(s[:4])
month = int(s[5:7])
day = int(s[9:])
if year > 2019:
  print('TBD')
elif year < 2019:
  print('Heisei')
else:
  if month > 4:
    print('TBD')
  elif month < 4:
    print('Heisei')
  else:
    if day > 30:
      print('TBD')
    else:
      print('Heisei')


Measured memory_bytes: 3060
import math

a, b, x = map(int, input().split())

if x > a * a * b / 2:
    rad = math.atan(2*b/a - 2*x/(a**3))
elif x < a * a * b / 2:
    rad = math.atan(a*b*b / 2 / x)
else:
    rad = math.atan(b/a)

print(rad / (2*math.pi) * 360)





Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n, m;
    cin >> n >> m;
    int a[50][50];
    int r;
    int s;
     for(int i = 1; i < n + 1; i ++){
         for(int j = 1; j <m + 1; j ++ ){
             a[i][j] = 0;
         }}
    for(int i = 1; i < n + 1; i ++){
        cin >> r;
        for(int j = 1; j <r + 1; j ++ ){
            
            cin >> s;
            a[i][s] += 1;
            }
            
            }
        
    
    int t = 0;
    for(int j = 1; j < m+ 1; j ++){
        int q = 0;
        for(int i = 1; i < n + 1; i ++){
            
            q += a[i][j];
            
            }
            if(q == n){
                t ++;
            
            
        }
    }
    cout << t << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

bool success(string& s)
{
    for (int i = 0; i < s.size(); i++)
    {
        if (i % 2 == 0 && s[i] == 'L')
        {
            return false;
        }
        if (i % 2 == 1 && s[i] == 'R')
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string s;
    cin >> s;
    cout << (success(s) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <cstring>
#include <numeric>
#include <algorithm>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef unsigned long long u64;
const int M=401;
const u32 P=998244353;
u32 a[M], b[M], fac[M], inv[M], f[M][M], g[M];
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar(), c-'0'>9&c!='-');
	for(a=(b=c=='-')?0:c-'0'; (c=getchar()-'0')<=9; a=a*10+c);
	return b?-a:a;
}
u64 power(u64 a, int b) {
	u64 ans=1;
	for(; b; a=a*a%P, b>>=1) if(b&1) ans=ans*a%P;
	return ans;
}
int main() {
	int (*rd)()=read<int>, n=rd(), s=0, t=0, max;
	u32 ans=0;
	for(int i=0; i<n; ++i) a[i]=rd(), b[i]=rd();
	max=*std::max_element(b, b+n);
	inv[1]=1;
	for(int i=2; i<max; ++i) inv[i]=(u64)inv[P%i]*(P-P/i)%P;
	f[0][0]=P-1;
	for(int i=0; i<n; ++i) {
		g[0]=1;
		for(int j=1; j<b[i]; ++j) g[j]=(u64)g[j-1]*a[i]%P*inv[j]%P;
		for(int j=s; j>=0; --j)
			for(int k=0; k<=t; ++k)
				for(int l=0; l<b[i]; ++l)
					f[j+a[i]][k+l]=(f[j+a[i]][k+l]+(u64)(P-f[j][k])*g[l])%P;
		s+=a[i], t+=b[i]-1;
	}
	fac[0]=1;
	for(int i=1; i<=t; ++i) fac[i]=(u64)fac[i-1]*i%P;
	for(int i=1; i<=s; ++i)
		for(int j=0; j<=t; ++j)
			ans=(ans+fac[j]*power(i, P-j-2)%P*f[i][j])%P;
	ans=(u64)s*ans%P;
	printf("%u\n", ans);
	return 0;
}


Measured memory_bytes: 768
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <iostream>
#include <string>

#include <algorithm>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define PB push_back
#define MP make_pair

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

#define ALL(v) (v).begin(),(v).end()

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VPII;

const int MOD = 1000000007;
const int INF = 1e9;

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

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; }

int N, A[101];

int main() {
    cin >> N;
    REP (i, N) {
        cin >> A[i];
    }
    bool flag = true;
    REP (i, N) {
        flag = false;
        if (A[i] % 2 == 0) {
            if (A[i] % 3 == 0 || A[i] % 5 == 0) {
                flag = true;
            }
        }
        else {
            flag = true;
        }
        if (!flag) {
            break;
        }
    }
    if (flag) {
        cout << "APPROVED";
    }
    else {
        cout << "DENIED";
    }
    cout << endl;
    return 0;
}


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


int main() {
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll k;
    cin>>k;
    string s;
    cin>>s;
    if(s.length()<=k)
        cout<<s;
    else {
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"...";
    }
    
	return 0;
}

Measured memory_bytes: 3620
""" ABC071D
"""

N = int(input())
S = [input() for _ in range(2)]
C = [[0]*N for _ in range(2)]
MOD = 1000000007
pos = 0
ans = 0
if S[0][pos] == S[1][pos]:
    ans = 3
else:
    ans = 6
    pos += 1

while 1:
    if pos >= N:
        break
    if S[0][pos] == S[1][pos]:
        pos += 1
        if pos >= N:
            break
        if S[0][pos] == S[1][pos]:
            ans *= 2
            ans %= MOD
            
        else:
            ans *= 2
            ans %= MOD
            pos += 1
    else:
        pos += 1
        if pos >= N:
            break
        if S[0][pos] == S[1][pos]:
            continue
        else:
            ans *= 3
            ans %= MOD
            pos += 1

print(ans % MOD)

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int k,t;
    cin>>k>>t;
    vector<pii>cake(100,pii(0,0));

    rep(i,t){
        int ki;
        cin>>ki;
        cake[i] = pii(ki,i+1);
    }

    int prev=-1;
    rep(i,k){
        sort(all(cake),greater<pii>());

        if(cake[0].se == prev){
            if(cake[1].fi == 0){cake[0].fi-=1;ans++;continue;}
            cake[1].fi -= 1;
            prev = cake[1].se;
        }else{
            cake[0].fi -= 1;
            prev = cake[0].se;
        }
    }


    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

long min(long a,long b){
  if(a>=b){
    return b;
  }else{
    return a;
  }
}

long abso(long x){
  if(x>=0){
    return x;
  }else{
    return -x;
  }
}

long main(void){
  long N;
  scanf("%ld",&N);

  long point[N];
  long dp[N];

  for(long i = 0;i<N;i++){
    scanf("%ld",&point[i]);
    dp[i] = 0;
  }
  for(long i = 1;i<N;i++){
    dp[i] = min(dp[i-1]+abso(point[i]-point[i-1]),dp[i-2]+abso(point[i]-point[i-2]));
  }

  printf("%ld\n",dp[N-1]);

  return 0;
}

Measured memory_bytes: 1664
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int d = sc.nextInt();
    int x = sc.nextInt();
    int[] a = new int[n];

    for (int i = 0; i < n; i++) {
      a[i] = sc.nextInt();
    }

    for (int i = 0; i < n; i++) {
      for (int j = 0; ; j++) {
        if (j * a[i] + 1 <= d) {
          x++;
        } else {
          break;
        }
      }
    }

    System.out.println(x);

  }

}


Measured memory_bytes: 21588
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n,k; cin>>n>>k;
    map<ll,ll>mp;
    rep(i,k){
        ll d;
        cin>>d;
        rep(j,d){
            ll d;
            cin>>d;
            mp[d]++;
        }

    }
    ll ans=0;
    for(auto p:mp){
        ans++;
    }
    cout<<n-ans<<endl;
}





Measured memory_bytes: 3644
// 2020 03/28 ABC 160 A
#include <iostream>
#include <string>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
int main () {

    string s;

    cin >> s;

    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 888
#include<cstdio>
#include<cmath>
#define ll long long
using namespace std;
const int maxn = 2e5+5;

int _;

int main()
{
  //fastio();
  double r;
  scanf("%lf",&r);
  printf("%.8f\n",(double)r*2*acos(-1));
  return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  unordered_map<string,int> memo;
  rep(i,N){
    string s;
    cin >> s;
    memo[s]++;
  }

  cout << memo.size() << endl;
  
  return 0;
}


Measured memory_bytes: 17792
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define Int long long
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

char C[110][110];
int main() {
  int H, W; cin >> H >> W;
  rep(i, H) {
    rep(j, W) {
      cin >> C[i][j];
    }
  }
  rep(i,H) {
    rep(n,2) {
      rep(j, W) {
        cout << C[i][j];
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define endl '\n'
#define INF 1e18L+1
using namespace std;
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll parent[100005];
ll find(ll a)
{
    std::vector<ll> v;
    while(parent[a]>0)
    {
        v.push_back(a);
        a = parent[a];
    }
    for(ll i=0;i<v.size();i++)
        parent[v[i]] = a;
    return a;
}
bool prime[100005];
void SieveOfEratosthenes(int n) 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}  
void union1(ll a, ll b)
{
    a = find(a);
    b = find(b);
    if(a!=b)
    {
        parent[a] = min(parent[a],parent[b]);
        parent[b] = a;
    }
}  
int main()
{
    //fastio();
    string s,t;
    cin >> s >> t;
    ll dp[s.length()+1][t.length()+1];
    memset(dp,0,sizeof(dp));
    string result = "";
    for(ll i=0;i<=s.length();i++)
    {
        for(ll j=0;j<=t.length();j++)
        {
            if(i==0||j==0)
                dp[i][j] = 0;
            else if(s[i-1]==t[j-1])
            {
             //   result+=s[i-1];
                dp[i][j] = 1+dp[i-1][j-1];
            }
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    // for(ll i=0;i<=s.length();i++)
    // {
    //     for(ll j=0;j<=t.length();j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll i=s.length(),j=t.length();
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            result+=s[i-1];
            i--;j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
        {
            i--;
        }
        else
            j--;
    }
    reverse(result.begin(),result.end());
    cout << result << endl;
}

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

int num_comb(const vector<int>& powers, int e) {
    int cnt = 0;
    for (int p : powers) {
        if (p >= e - 1) cnt++;
    }
    return cnt;
}

int main() {
    int n;
    cin >> n;
    vector<int> powers(n + 1, 0);
    for (int i = 2; i <= n; i++) {
        int num = i;
        for (int k = 2; k * k <= num; k++) {
            while (num % k == 0) {
                num /= k;
                powers[k]++;
            }
        }
        if (num > 1) powers[num]++;
    }
    // // if you wanna have a lil peek inside "powers"
    // for (int a : powers) {
    //     cout << a << " ";
    // }
    // cout << endl;
    int ans = 0;
    ans += num_comb(powers, 75);
    ans += num_comb(powers, 25) * (num_comb(powers, 3) - 1);
    ans += num_comb(powers, 15) * (num_comb(powers, 5) - 1);
    ans += num_comb(powers, 5) * (num_comb(powers, 5) - 1) * (num_comb(powers, 3) - 2) / 2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <cmath>
 
using namespace std;
using ll = long long;
 
int main(void){
    ll n;cin>>n;
    bool f = false;
    for(int i=0;i<n;++i){
        ll a;cin>>a;
        if(a%2 == 1) f = true;
    }
    cout << ((f)?"first" : "second") << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 21 23:53:42 2020

@author: liang
"""

N = int(input())

prev = (0, 0, 0)

flag = True

for i in range(N):
    t, x, y = map(int, input().split())
    if t%2 != (x+y)%2:
        flag = False
    if abs(x+y - prev[1] - prev[2]) > t-prev[0]:
        flag = False
    prev = (t,x,y)

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

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 5005;

typedef pair<int,int>   ii;

char w[N][N];

int main()  {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int n;  cin >> n;

    if (n == 2) {
        cout << -1;
        return  0;
    }
    if (n == 3) {
        cout << "aa.\n";
        cout << "..a\n";
        cout << "..a";
        return  0;
    }

    for(int i = 0 ; i < n ; ++i)
    for(int j = 0 ; j < n ; ++j)
        w[i][j] = '.';

    int s = n / 4 * 4 - 4;

    #define a(x,y)  w[i + x)[i + y]

    for(int i = 0 ; i < s ; i += 4) {
        #define a(x,y)  w[i + x][i + y]

        a(0,0) = a(0,1) = a(2,2) = a(2,3) = 'a';
        a(1,0) = a(1,1) = a(3,2) = a(3,3) = 'b';
        a(0,2) = a(1,2) = a(2,0) = a(3,0) = 'c';
        a(0,3) = a(1,3) = a(2,1) = a(3,1) = 'd';
    }
    int i = s;

    if (n % 4 == 0) {
        a(0,0) = a(0,1) = a(2,2) = a(2,3) = 'a';
        a(1,0) = a(1,1) = a(3,2) = a(3,3) = 'b';
        a(0,2) = a(1,2) = a(2,0) = a(3,0) = 'c';
        a(0,3) = a(1,3) = a(2,1) = a(3,1) = 'd';
    }
    if (n % 4 == 1) {
        a(0,0) = a(0,1) = a(0,4) = a(3,0) = a(4,0) = a(1,4) = a(4,3) = a(4,4) = 'a';
        a(0,2) = a(0,3) = a(1,0) = a(2,0) = a(4,1) = a(4,2) = a(2,4) = a(3,4) = 'b';
        a(1,1) = a(1,2) = a(2,3) = a(3,3) = 'c';
    }
    if (n % 4 == 2) {
        a(0,0) = a(0,1) = a(2,2) = a(2,3) = a(4,4) = a(4,5) = 'a';
        a(0,2) = a(1,2) = a(4,0) = a(5,0) = a(2,4) = a(3,4) = 'b';
        a(0,3) = a(1,3) = a(4,1) = a(5,1) = a(2,5) = a(3,5) = 'c';
        a(1,0) = a(1,1) = a(3,2) = a(3,3) = a(5,4) = a(5,5) = 'd';
    }
    if (n % 4 == 3) {
        a(0,0) = a(0,1) = a(1,6) = a(2,6) = 'a';
        a(0,2) = a(0,3) = a(3,6) = a(4,6) = 'b';
        a(0,4) = a(0,5) = a(5,6) = a(6,6) = 'c';
        a(1,0) = a(1,1) = a(1,3) = a(1,4) = a(2,2) = a(3,2) = a(2,5) = a(3,5) = 'd';
        a(4,0) = a(4,1) = a(4,3) = a(4,4) = a(5,2) = a(6,2) = a(5,5) = a(6,5) = 'd';
    }
    for(int i = 0 ; i < n ; ++i)
    for(int j = 0 ; j < n ; ++j)
        cout << w[i][j] << (j == n - 1 ? "\n" : "");
}

Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+7;
int n,m,k,a[20][20],sum[15],c[15],ans=0x3f3f3f3f,g;
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=0;i<n;i++){
	scanf("%d",&c[i]);	
	for(int j=0;j<m;j++) scanf("%d",&a[i][j]); 
	}
	for(int i=1;i<(1<<n);i++){
	  memset(sum,0,sizeof(sum)); g=0;
	 for(int j=0;j<n;j++){
	  if(!(i&(1<<j))) continue;
	  for(int l=0;l<m;l++) sum[l]+=a[j][l];
	  g+=c[j];
	 }
	bool flag=0;
	for(int j=0;j<m;j++) {
	 if(sum[j]<k) {
	 	flag=1;
	 	break;
	 }
	}
	if(!flag) ans=min(ans,g);
	}
	printf("%d\n",ans==0x3f3f3f3f? -1:ans);
 } 

Measured memory_bytes: 3816
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)


int n;
int h[101010];
int m[101010];

int dp(int cur){
    if(m[cur] != -1)return m[cur];
    if(cur == 1)return m[cur] = 0;
    int ret = INF<int>();
    if(cur - 1 >= 1)ret = min(ret, dp(cur - 1) + abs(h[cur - 1] - h[cur]));
    if(cur - 2 >= 1)ret = min(ret, dp(cur - 2) + abs(h[cur - 2] - h[cur]));
    return m[cur] = ret;
}

int main(){
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> h[i];
    }
    for(int i = 1;i <= n;i++){
        m[i] = -1;
    }
    cout << dp(n) << endl;
}

Measured memory_bytes: 4096
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
ans = 0
for _ in range(N):
    A = list(map(int, input().split()))
    sum = 0
    for i, Ai in enumerate(A):
        sum += Ai*B[i]
    if sum+C > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
def main():
    import sys
    input = sys.stdin.readline
    mod = 10**9+7
    
    N,M = map(int,input().split())
    X = list(map(int,input().split()))
    Y = list(map(int,input().split()))
    XX = 0
    YY = 0
    for i in range(N-1):
        l = X[i+1]-X[i]
        XX += l*(i+1)*(N-i-1)
        XX %= mod
    for i in range(M-1):
        l = Y[i+1]-Y[i]
        YY += l*(i+1)*(M-i-1)
        YY %= mod
    ans = (XX*YY)%mod
    print(ans)
        
    
    
    
main()

Measured memory_bytes: 74340
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int cnt = 0;
	rep(i, n - 1) {
		cnt += a[i];
	}
	if (cnt > a[n-1]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

int main(){
    long N;
    cin >> N;
    int keta = 100000;
    for(long i=1;i<=100000;++i) {
        int tmp = 0;
        if(N % i == 0){
            string a = to_string(i);
            long B = N/i; 
            string b = to_string(B);
            tmp = max(a.size(),b.size());
            if(keta>tmp) {
                keta = tmp;
            }
        }
    }
    cout << keta << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int p;fixprec(int p):p(p){}}; ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.p);}
int main() {
    int D, T, S;
    cin >> D >> T >> S;
    cout << (T * S >= D ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define REP(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 1e9+7;
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; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

//ll P[20001], M[20001];

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
// O(log n)
ll mod_pow(ll x, ll n){
    ll res = 1LL;
    while (n > 0) {
        
        if (n & 1LL) res = res * x % MOD;
        x = x * x % MOD;
        n >>= 1LL;
    }
    return res;
}
// �e�[�u�������O����
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// �񍀌W���v�Z
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // �O����
    COMinit();
    ll N, K;
    cin >> N >> K;
    // �v�Z��
    K = min(N, K);
    ll ans = 0;
    for (int i = K; i >= 0; i--){
        //ll tmp = mod_pow(N - i, i);
        ll tmp = COM(N-1, i);
        ll tmp2 = COM(N, N - i);
        //cout << i << " " << N - i << " " << i <<  " " << N << " " << N - i <<  endl;
        ll tmp3 = (tmp * tmp2) % MOD;
        //cout << i << " " << tmp3 << endl;
        (ans += tmp3) %= MOD;
    }
    cout << ans;
}


Measured memory_bytes: 12160
//“ In order to be irreplaceable, one must always be different”
#include <bits/stdc++.h>
using namespace std;
# define ll long long
#define endl "\n"
# define pi 3.14159265359
# define str string
# define vll vector<ll>
# define vstr vector<str>
# define vchar vector<char>
# define pb push_back
# define popb pop_back
# define pf push_front
# define popf pop_front
# define sll set<ll>
# define schar set<char>
//find()
//erase(x) removes element x
//erase(position,position)
# define qll queue<ll>
# define qstr queue<str>
//front(),back()
# define stll stack<ll>
# define ststr stack<str>
//top()
# define dll deque<ll>
//at()
# define mll map<ll,ll>
#define mchar map<char, ll>
# define mstr map<str,ll>
# define mss map<str,str>
# define mci map<char,ll>
# define vp vector< pair<ll,ll> >
#define mp make_pair
#define ff first
#define ss second
#define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
# define r(x,y) for(int x=y;x>=0;x--)
# define fr(x,y,z) for(int x=y;x<z;x++)
# define rr(x,y,z) for(int x=y;x>z;x--)
ll power(ll a , ll b){ll res=1;for(ll i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}
ll gcd(ll a, ll b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b){
    return (a*b)/gcd(a, b);
}
void print(vll a){
    for(int i=0;i<a.size();i++){
        cout<<a[i]<<' ';
    }
    cout<<endl;
}
vll inp(int n){
    vll a;
    ll x;
    f(i,n){
        cin>>x;
        a.pb(x);
    }
    return a;
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll x,y,z;
    cin>>x>>y>>z;
    swap(x,y);
    swap(x,z);
    cout<<x<<" "<<y<<" "<<z;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        if(n%2==0)
        {
            printf("%d\n",n);
        }
        else
        {
            printf("%d\n",n*2);
        }
    }
    return 0;
}


Measured memory_bytes: 128
//        VIVEK UPADHYAY
//        MANIT, BHOPAL(M.P)

#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<unistd.h>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<set>
#include<unordered_map>
#include<cstdio>
#include<map>
#include<numeric>
using namespace std;
#define F first
#define S second
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
typedef long long ll;
const int MAXN = 1e6+10; ;
const int MAX = 1e7;
double pi = 3.1415926535897932384626433832795;
const ll inf=1e10 ;
int tot=0 ;
int main(){
    int A,B ;
    cin >>A>>B ;
    if(A<=8 && B<=8){
        cout<<"Yay!\n";
        return 0;
    }
    else
        cout<<":(\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
#define INF 10000000000
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;

struct state { int n, s; double t; };

int N, M, P, A, B, T[20];
double dp[50][300];

class Compare {
public:
  bool operator()(struct state a, struct state b) {
    return a.t > b.t;
  }
};

int main(void) {
  while(cin >> N >> M >> P >> A >> B, N) {
    vector<pii> E[50];
    REP(i, 0, N) cin >> T[i];
    REP(i, 0, P) {
      int X, Y, Z; cin >> X >> Y >> Z;
      E[X - 1].push_back(pii(Y - 1, Z));
      E[Y - 1].push_back(pii(X - 1, Z));
    }

    REP(i, 0, M) REP(j, 0, pow(2, N)) dp[i][j] = INF;

    priority_queue<struct state, vector<struct state>, Compare> q;
    struct state first = { A - 1, 0, 0.0 };
    q.push(first);

    double ans = 0;
    while(!q.empty()) {
      struct state c = q.top();
      q.pop();

      // cout << c.n << " " << c.s << " " << c.t << endl;

      if(c.n == B - 1) {
        ans = c.t;
        break;
      }
      if(dp[c.n][c.s] <= c.t) continue;
      dp[c.n][c.s] = c.t;

      REP(i, 0, N) {
        if(!(c.s & (1 << i))) {
          int ns = c.s | (1 << i);
          REP(j, 0, E[c.n].size()) {
            int nn = E[c.n][j].fi;
            double nt = c.t + ((double) E[c.n][j].se / T[i]);
            if(dp[nn][ns] <= nt) continue;
            struct state n = { nn, ns, nt };
            q.push(n);
          }
        }
      }
    }

    if(ans > 0) printf("%.7lf\n", ans);
    else cout << "Impossible" << endl;
  }

  return 0;
}

Measured memory_bytes: 18056
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try (Scanner sc = new Scanner(System.in)) {
			int AGE, PRICE, ans;
			AGE = sc.nextInt();
			PRICE = sc.nextInt();
			
			if (AGE < 6) {
				ans = 0;
			} else if (AGE < 13) {
				ans = PRICE/2;
			} else {
				ans = PRICE;
			}
			
			System.out.println(ans);
			
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
 
    long long n,k;
    cin>>n>>k;
    double ans=0;

    for(int i=1;i<=n;i++){
        int cnt=0;
        while(i*pow(2,cnt)<k) cnt++;
        ans+=(double)1/n/pow(2,cnt);
    }
    printf("%.13f\n",ans);
    
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

int main(int argc, char const *argv[])
{
    ll k,x;
    cin >> k >> x;
    for (ll i = -1000000; i <= 1000000; i++)
    {
        if (abs(i - x) < k)
        {
            cout << i << " ";
        }
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int cc=0;
    cin>>s;
    if(s[0]!='A' || (s[1]<'a'||s[1]>'z') || (s[s.size()-1]<'a'||s[s.size()-1]>'z')){
        cout<<"WA"<<endl;
        return 0;
    }
    for(int i=1;i<s.size()-1;i++){
        if(s[i]>='A' && s[i]<='Z'){
            if(s[i]!='C'){
                cout<<"WA"<<endl;
                return 0;
            }
            else if(s[i]=='C' && cc==0)cc++;
            else if(s[i]=='C' && cc==1){
                cout<<"WA"<<endl;
                return 0;
            }
        }
    }
    if(cc==1)cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
}


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

using namespace std;
#define INF 99999999
struct Edge
{
	int b;
	int x;
	int y;
};

vector<int> get_path(int t, int* prev)
{
	vector<int> path;
	while(t != -1)
	{
		path.push_back(t);
		t = prev[t];
	}
	reverse(path.begin(), path.end());
	return(path);
}

vector<int> dijkstra(int src,int dst, const vector<Edge>& edge)
{	
	double d[1001];
	int prev[1001];
	bool used[1001];

	fill((double*)d, (double*)d + 1001, INF);
	fill((bool*)used, (bool*)used + 1001, false);
	fill((int*)prev, (int*)prev + 1001, -1);
	d[src] = 0.0;
	while(true)
	{
		int v = -1;
		for(int u = 0; u < edge.size(); ++u)
		{
			if(!used[u] && (v == -1 || d[u] < d[v]))
			{
				v = u;
			}
		}
		if(v == -1)
		{
			break;
		}
		used[v] = true;
		int srcX = edge[v].x;
		int srcY = edge[v].y;
		for(int u = 0; u < edge.size(); ++u)
		{
			if(u == v)
			{
				continue;
			}
			double cost = sqrt((double)(edge[u].x - srcX) * (double)(edge[u].x - srcX) + (double)(edge[u].y - srcY) * (double)(edge[u].y - srcY));
			if(cost > 50.0)
			{
				continue;
			}
			if(d[u] > d[v] + cost)
			{
				d[u] = d[v] + cost;
				prev[u] = v;
			}
		}
	}
	return get_path(dst, prev);
}

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<Edge> edge;
		for(int i = 0; i < n; ++i)
		{
			int b,x,y;
			cin >> b >> x >> y;
			Edge e = {b,x,y};
			edge.push_back(e);
		}
		int m;
		cin >> m;
		for(int i = 0; i < m; ++i)
		{
			int src, dst;
			cin >> src >> dst;
			int src_idx, dst_idx;
			for(int j = 0; j < edge.size(); ++j)
			{
				if(edge[j].b == src)
				{
					src_idx = j;
				}
				if(edge[j].b == dst)
				{
					dst_idx = j;
				}
			}
			vector<int> route = dijkstra(src_idx,dst_idx,edge);
			if(route[0] == src_idx && route[route.size() - 1] == dst_idx)
			{
				for(int j = 0; j < route.size(); ++j)
				{
					cout << edge[route[j]].b;
					if(j == route.size() - 1)
					{
						cout << endl;
					}
					else
					{
						cout << " ";
					}
				}
			}
			else cout << "NA" << endl; 
		}
	}
}

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

Measured memory_bytes: 1228
n = int(input())

li = list(map(int,input().split()))

sm = 0

for i in range(n-1):
    sm += abs(li[i] - li[i+1])
else:
    sm += abs(li[0])
    sm += abs(li[n-1])
    
for i in range(n):
    if i == 0:
        print(sm - abs(li[0]) + abs(li[1]) - abs(li[i] - li[i+1]))
    elif i == n-1:
        print(sm - abs(li[n-1]) + abs(li[n-2]) - abs(li[n-2] - li[n-1]))
    else:
        print(sm - abs(li[i] - li[i+1]) -abs(li[i-1] - li[i]) + abs(li[i-1] - li[i+1]))
    

Measured memory_bytes: 14172
import java.util.Scanner;

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

		int input=sc.nextInt();
		int[] suji=new int[100001];

		for(int i=0; i<100001; i++) {
			suji[i]=0;
		}

		for(int i=0; i<input; i++) {
			suji[sc.nextInt()]++;
		}

		int[] wa=new int[100003];
		wa[0]=suji[0];		//-1
		wa[1]=suji[0]+suji[1];	//0
		wa[100001]=suji[99999]+suji[100000];	//100000
		wa[100002]=suji[100000];		//100001

		for(int i=2; i<=100000; i++) {
			wa[i]=suji[i-2]+suji[i-1]+suji[i];
		}

		int max=0;
		for(int i=0; i<=100002; i++) {
			if(max<wa[i]) {
				max=wa[i];
			}
		}

		System.out.println(max);
	}
}

Measured memory_bytes: 50880
import Foundation

class Scanner {
    static func readInt() -> Int {
        return Int(readLine()!)!
    }
    
    static func readIntArr() -> [Int] {
        return readLine()!.split(separator: " ").map { Int($0)! }
    }
    
    static func readM(_ n: Int) -> [[Int]] {
        var res = [[Int]]()
        for _ in 0..<n {
            res.append(readIntArr())
        }
        return res
    }
    
    static func readUknownIntMat() -> [[Int]] {
        var res = [[Int]]()
        while let line = readLine() {
            res.append(line.split(separator: " ").map { Int($0)! })
        }
        return res
    }
    
    static func readString() -> String {
        return readLine()!
    }
}

class Printer {
    static func printIntArray(_ arr: [Int]) {
        print(arr.map { String($0) }.joined(separator: " "))
    }
}
class Solution {
    var zeros = [Int](repeating: 0, count: 64)
    var ones = [Int](repeating: 0, count: 64)
    var can = [Int](repeating: 0, count: 64)
    var dp = [[Int]](repeating: [Int](repeating: -1, count: 2), count: 64)
    var n = 0
    var total = 0
    func maxXXOR(_ arr: [Int], _ k: Int, _ total: Int) -> Int {
        guard k > 0 else {
            return arr.reduce(0) { $0 + $1 }
        }
        
        self.total = total
        //how many sets maximum we can set
        self.n = Int(log(Double(k))/log(Double(2))) + 1
        for i in stride(from: 0, to: 64, by: 1) {
            let j = 1<<i
            if k&j == j {
                can[i] = 1
            }
            for num in arr {
                if num&j == 0 {
                    zeros[i] += 1
                } else {
                    ones[i] += 1
                }
            }
        }
        
        var res = dfs(n-1, true)
        for i in stride(from: n, to: ones.count, by: 1) {
            let j = 1<<i
            res += j * ones[i]
        }
        return res
    }
    
    func dfs(_ pos: Int,_ isOnBorder: Bool) -> Int {
        guard pos >= 0 else {
            return 0
        }
        
        guard dp[pos][isOnBorder ? 1 : 0] == -1 else {
            return dp[pos][isOnBorder ? 1 : 0]
        }
        //1 0 0 1
        //^
        let cur = 1<<pos
        var res = 0
        if isOnBorder {
            if can[pos] == 1 {
                res = max(cur * zeros[pos] + dfs(pos-1, true), cur * ones[pos] + dfs(pos-1, false))
            } else {
                res = max(res, cur * ones[pos] + dfs(pos-1, true))
            }
        } else {
            res = cur * max(zeros[pos], ones[pos]) + dfs(pos-1, false)
        }
        dp[pos][isOnBorder ? 1 : 0] = res
        return res
    }
}


let nk = Scanner.readIntArr()
let arr = Scanner.readIntArr()
print(Solution().maxXXOR(arr,nk[1], nk[0]))

Measured memory_bytes: 20428
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
const int N=1000000007;
int p[100005];
int np[100005];
bool vis[100005];
vector<vector<int>>adj;
void dfs(int v, int pa){
	p[v]=pa;
	for(auto u:adj[v]){
		if(u==pa){
			continue;
		}
		dfs(u, v);
	}
}

main() {
	int n, k;
	cin>>n>>k;
	adj.resize(n+1);
	for(int i=0; i<n-1; i++){
		int u, v;
		cin>>u>>v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	int ans=k;
	dfs(1, 1);
	queue<int>q;
	q.push(1);
	vis[1]=1;
	while(!q.empty()){
		int node=q.front();
		q.pop();
		vis[node]=1;
		for(auto u:adj[node]){
			if(vis[u]==1){
				continue;
			}
			int num;
			if(p[p[u]]==p[u]){
				num=1;
			}
			else{
				num=2;
			}
			num+=np[node];
			np[node]++;
			if(num>=k){
				cout<<0;
				return 0;
			}
			ans=(ans*(k-num))%N;
			q.push(u);
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 13964
#include <iostream>

using namespace std;
typedef long long ll;
#define min(a, b) ((a) < (b)? (a):(b))
#define abs(a) ((a) < (0)? -(a):(a))
#define rep(i, n) REP(i, 0, (n))
#define REP(i, a, n) for(typeof(n) i=(a); i<(n); i++)

int N;
int a[100010];

int main() {
	cin >> N;
	int mini = 0, maxi = 0;
	ll total = 0;
	REP(i, 1, N+1) {
	    cin >> a[i];
	    mini = a[i] < a[mini]? i:mini;
	    maxi = a[i] > a[maxi]? i:maxi;
	    total += abs(a[i-1]-a[i]);
	}
    total += abs(a[N]);
    REP(i, 1, N+1) {
        cout << total - (abs(a[i-1]-a[i]) + abs(a[i]-a[i+1]) - abs(a[i-1]-a[i+1])) << endl;
    }
}


Measured memory_bytes: 1664
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        N: usize, W: usize,
        wv: [(usize, i64); N]
    }

    let mut ans = 0;
    for k in 1..=N {
        let w0 = wv[0].0;
        if W < k * w0 {
            continue;
        }
        let W = min(W - k * w0, 3 * k);
        let wv = wv.iter().map(|&(w, v)| (w - w0, v)).collect_vec();

        let mut dp = vec![vec![vec![0; 3 * k + 1]; k + 1]; N];
        let (w0, v0) = wv[0];
        dp[0][1][w0] = v0;
        for (i, (w, v)) in (0..).zip(wv).skip(1) {
            dp[i] = dp[i-1].clone();
            dp[i][1][w] = max(dp[i][1][w], v);
            for count in 1..k {
                for prev_w in (0..=3*k-w).rev() {
                    let prev_v = dp[i-1][count][prev_w];
                    dp[i][count+1][prev_w+w] = max(dp[i][count+1][prev_w+w], prev_v+v);
                }
            }

        }
        for w in 0..=W {
            ans = max(ans, dp[N-1][k][w]);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 26172