akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];
    
    int best = 1e8;
    repi(p, 101) {
        int sum = 0;
        rep(i, n) sum += (p - x[i]) * (p - x[i]);
        best = min(best, sum);
    }

    put(best);

    return 0;
}

Measured memory_bytes: 3544
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int n;
void dfs(int i,int j,string s){
    if(i==n){
        cout<<s<<endl;
        return;
    }
    rep(k,j+1){
        char a=k+'a';
        string S=s;
        S.push_back(a);
        if(k!=j)dfs(i+1,j,S);
        else dfs(i+1,j+1,S);
    }
    return;
}
int main(void){
    cin>>n;
    dfs(0,0,"");
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,z,w;
  cin>>n>>z>>w;
  std::vector<int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  if(n==1){
    cout<<std::abs(a[0]-w)<<endl;
  }else{
    cout<<std::max(std::abs(w-a[n-1]),std::abs(a[n-1]-a[n-2]))<<endl;
  }



  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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 mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

ll dx[2]={1,0},dy[2]={0,1};

int main(void){
    char s[10][10];
    ll reach[10][10]={};
    ll h,w;
    scanf("%lld%lld",&h,&w);
    ll black=0;
    rep(i,0,h){
        scanf("%s",s[i]);
    }
    rep(i,0,h){
        rep(j,0,w){
            if(s[i][j]=='#') black++;
        }
    }
    if(black==h+w-1){
        printf("Possible\n");
    }else{
        printf("Impossible\n");
    }
    // ll x=0,y=0;
    // while(x!=w-1 || y!=h-1){
    //     ll j=0;
    //     reach[y][x]=1;
    //     rep(i,0,2){
    //         ll X=x+dx[i],Y=y+dy[i];
    //         if( 0<=X && X<w && 0<=Y && Y<h ){
    //             if(reach[Y][X]==0 && s[Y][X]=='#') j++;
    //         }
    //     }
    //     // printf("%lld %lld %lld\n",x,y,j);
    //     if(j!=1){
    //         // printf("%lld %lld ",x,y);
    //         printf("Impossible\n");
    //         return 0;
    //     }
    //     rep(i,0,2){
    //         ll X=x+dx[i],Y=y+dy[i];
    //         if( 0<=X && X<w && 0<=Y && Y<h ){
    //             if(reach[Y][X]==0 && s[Y][X]=='#' ){
    //                 x=X; y=Y;
    //                 break;
    //             }
    //         }
    //     }
    //     // printf("%lld %lld\n",x,y);
    // }


    
    // printf("Possible\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include <boost/array.hpp>
//#include <boost/range/numeric.hpp>
//#include <boost/range/algorithm.hpp>
//#include <boost/multiprecision/cpp_int.hpp>

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
//using namespace boost::multiprecision;

constexpr long long INF = LLONG_MAX;
constexpr long long MOD = 1000000007;
constexpr long double PI = M_PI;

#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); ++i)
#define RFOR(i,n,r) for(ll i = (ll)(n-1); i >= r; --i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,n,0)
#define ALL(x) x.begin(),x.end()
#define CALL(x) x.cbegin(),x.cend()
#define RALL(x) x.rbegin(),x.rend()
#define CRALL(x) x.crbegin(),x.crend()

#define cout cout << fixed << setprecision(12)
#define dbglf cerr << '\n'

#define ACCM(arr) accumulate(ALL(arr),0LL)
#define Yes(ex) cout << ((ex) ? "Yes" : "No") << endl
#define YES(ex) cout << ((ex) ? "YES" : "NO") << endl

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using vp = vector<pair<ll, ll>>;
using vs = vector<string>;
using vc = vector<char>;
using lst = list<ll>;
using pq = priority_queue<ll>;

template < typename T >
inline void veccin(vector<T>& v) {
    for (auto && e : v) { cin >> e; }
}

template < typename T >
inline void dbg(T a) { cerr << a << ' '; }

ll n, m, k;
ll ans = 0, sum = 0, cnt = 0;
//ld d;
string s/*1, s2, s3*/;
char c/*1, c2, c3*/;
bool flag = false;

/*--------------------template--------------------*/

int main() {
    cin >> n >> s;
    	auto sr = count(ALL(s),'R');
    	auto sg = count(ALL(s),'G');
    	auto sb = count(ALL(s),'B');
	ans = sr*sg*sb;    	
	REP(j,n){
    REP(i,n){
    	if(  (s[j]!=s[j+i])
           &&(s[j+i]!=s[j+i+i])
           &&(s[j+i+i]!=s[j])
           &&(j+i+i<n)){
        	sum++;
        }
    }
    }
    cout << ans - sum << endl;
}


Measured memory_bytes: 3636
import java.util.*;
import java.io.*;

public class Main {	
	
	private static void solve(){
		//Implement solution here.
		int N = ni();
		Map<Integer,Integer> amap = new HashMap<>();
		Map<Integer,Integer> bmap = new HashMap<>();
		
		for(int i = 0; i < N; i++) {
			int A = ni();
			int L = i + A;
			int R = i - A;
			if(!amap.containsKey(L)) amap.put(L,0);
			amap.put(L, amap.get(L) + 1);
			if(!bmap.containsKey(R)) bmap.put(R,0);
			bmap.put(R, bmap.get(R) + 1);
		}

		long result = 0;
		for(int i:amap.keySet()) {
			if(bmap.containsKey(i)) {
				result += (long)amap.get(i) * (long)bmap.get(i);
			}
		}
		System.out.println(result);
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


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

void troca(int *a, int *b){
	int temp = *b;
	*b = *a;
	*a = temp;  

}

int mod(int a, int b){
	if (a % 10 == 0 )
		return b;
	else if (b % 10 == 0 )
		return a;
	else if ((a % 10) < b % 10)
		return a;
	else 
		return b;	
}
int main(){

	int a, b, c, d, e, k, sum = 0;
	scanf("%d", &a );
	scanf("%d", &b );
	scanf("%d", &c );
	scanf("%d", &d );
	scanf("%d", &e );

	k = mod (mod (mod (a, b), c), d);

	if (k == a)
		troca(&a, &e);
	else if (k == b)
		troca(&b, &e);
	else if (k == c)
		troca(&c, &e);
	else if (k == d)
		troca(&d, &e);

	if ((a % 10) != 0)
		sum += a + (10 - (a % 10));
	else
		sum += a;

	if ((b % 10) != 0)
		sum += b + (10 - (b % 10));
	else
		sum += b;

	if ((c % 10) != 0)
		sum += c + (10 - (c % 10));
	else
		sum += c;

	if ((d % 10) != 0)
		sum += d + (10 - (d % 10));
	else
		sum += d;

	printf("%d\n",sum + e );

	return 0;
	
}

Measured memory_bytes: 128
n=input()
lenn=len(n)
n=int(n)

if lenn == 1:
    print(n)
elif lenn == 3:
    print(n-90)
elif lenn == 5:
    print(n-9090)
elif lenn == 2:
    print(9)
elif lenn == 4:
    print(909)
else:
    print(90909)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
vi G[MAX_N];
int v[MAX_N];
int d[MAX_N];
int c[MAX_N];
int ans[MAX_N];
int flag[MAX_N];

struct spl{int v_, d_, c_;};

int main() {
    int n,m,q;
    cin >> n >> m;
    rep(i,m){
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    cin >> q;
    rep(i,q){
        cin >> v[i] >> d[i] >> c[i];
    }
    drep(i,q){
        queue<spl> que;
        if(ans[v[i]]==0){
            ans[v[i]] = c[i];
            flag[v[i]] = d[i];
            if(d[i]>0){
                spl s;
                s.v_ = v[i];
                s.d_ = d[i];
                s.c_ = c[i];
                que.push(s);
            }
        }else{
            if(flag[v[i]] < d[i]){
                flag[v[i]] = d[i];
                spl s;
                s.v_ = v[i];
                s.d_ = d[i];
                s.c_ = c[i];
                que.push(s);
            }
        }
        while(que.size()>0){
            spl s = que.front();
            que.pop();
            if(ans[s.v_]==0){
                ans[s.v_] = s.c_;
                flag[s.v_] = s.d_;
                if(s.d_>0){
                    rep(j,G[s.v_].size()){
                        if(flag[G[s.v_][j]]==0 || flag[G[s.v_][j]] < s.d_ - 1){
                            spl s_;
                            s_.c_ = s.c_;
                            s_.v_ = G[s.v_][j];
                            s_.d_ = s.d_ - 1;
                            que.push(s_);
                        }
                    }
                }
            }else{
                flag[s.v_] = max(flag[s.v_], s.d_);
                if(s.d_>0){
                    rep(j,G[s.v_].size()){
                        if(flag[G[s.v_][j]]==0 || flag[G[s.v_][j]] < s.d_ - 1){
                            spl s_;
                            s_.c_ = s.c_;
                            s_.v_ = G[s.v_][j];
                            s_.d_ = s.d_ - 1;
                            que.push(s_);
                        }
                    }
                }
            }
        }
    }

    srep(i,1,n+1){
        cout << ans[i] << endl;
    }

    
    return 0;
}
 
 


Measured memory_bytes: 12728
#include <stdio.h>

int main(void) {
	char s[16]="01235789";
	long long x,n,f;
	while(scanf("%lld",&n) , n != 0){
		x = 1073741824;
		f = 0;
		while(x != 0){
			if(!((n/x) == 0 && f == 0)){
				printf("%c",s[(n/x)]);
				f = 1;
			}
			n%=x;
			x/=8;
		}
		printf("\n");
	}
	return 0;
}

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

int main()
{

    int n;
    std::cin >> n;

    std::vector<int> d(n);
    for (int i = 0; i < n; i++) {
        std::cin >> d[i];
    }

    std::sort(d.begin(), d.end());

    int l, r;
    if (n % 2 == 0)
    {
        r = d[n / 2];
        l = d[n / 2 - 1];
    }

    std::cout << r - l << "\n";
}

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

using namespace std;

signed main() {
    int n;
    scanf("%d", &n);
    // dp[heads]
    // if we had i tosses, then tails=i-heads
    vector<double> dp(n + 1);
    // dp[i] - p-bility that there are i heads so far
    dp[0] = 1;
    for (int coin = 0; coin < n; coin++) {
        double p_heads;
        scanf("%lf", &p_heads);
        for (int i = coin + 1; i >= 0; i--) {
            dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
        }
    }
    double answer = 0;
    for (int heads = 0; heads <= n; heads++) {
        int tails = n - heads;
        if (heads > tails) {
            answer += dp[heads];
        }
    }
    printf("%.10lf\n", answer);
    return false;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<long long> u, std::vector<long long> v, std::vector<long long> w){
  map<ll, vector<pair<ll, ll>>> t;

  for(ll i=0; i<N-1; i++) {
    t[u[i]].push_back(make_pair(v[i], w[i]));
    t[v[i]].push_back(make_pair(u[i], w[i]));
  }
  vector<ll> ans(N+1, -1);
  queue<ll> q;
  q.push(1);
  ans[1] = 1;
  while(!q.empty()) {
    ll x = q.front();
    q.pop();
    for(auto p: t[x]) {
      if(ans[p.first]==-1) {
	if(p.second%2==0) {
	  ans[p.first] = ans[x];
	} else {
	  ans[p.first] = (ans[x]+1)%2;
	}
	q.push(p.first);
      }	
    }
  }
  for(ll i=1; i<=N; i++)
    std::cout << ans[i] << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<long long> u(N-1);
  std::vector<long long> v(N-1);
  std::vector<long long> w(N-1);
  for(int i = 0 ; i < N-1 ; i++){
    scanf("%lld",&u[i]);
    scanf("%lld",&v[i]);
    scanf("%lld",&w[i]);
  }
  solve(N, std::move(u), std::move(v), std::move(w));
  return 0;
}



Measured memory_bytes: 16512
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>



using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long  int x; cin >> x;
	int n = 0;
	long long int a = 100;
	while (true) {
		n++;
		a *= 1.01;
		if (a >= x) {
			cout << n << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3592
n, m, s = map(int,input().split())
adj = [[] for i in range(n)]
for _ in range(m):
    u, v, a, b = map(int,input().split())
    adj[u - 1].append((v - 1,-a,b))
    adj[v - 1].append((u - 1,-a,b))

for i in range(n):
    c, d = map(int,input().split())
    adj[i].append((i,c,d))

out = [-1] * n
count = 0

LARGE = 50 * n

done = dict()
from heapq import *
q = []
if s > LARGE:
    s = LARGE
heappush(q, (0, 0, s))

while q:
    time, loc, curr = heappop(q)
    if out[loc] == -1:
        out[loc] = time
        count += 1
        if count == n:
            break
    for nex, cost, timeD in adj[loc]:
        currNex = curr + cost
        timeNex = time + timeD
        if currNex > LARGE:
            currNex = LARGE
        if currNex < 0:
            continue
        if (nex, currNex) not in done or timeNex < done[(nex, currNex)]:
            done[(nex, currNex)] = timeNex
            heappush(q, (timeNex, nex, currNex))
print(*out[1:], sep = '\n')
    


Measured memory_bytes: 119848
#include<bits/stdc++.h>
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
int dp[1234567];
signed main() {
	dp[0] = 1;
	int n, a, b, ans;
	while (cin >> n >> a >> b, n) {
		ans = 0;
		for1(i, n) {
			dp[i] = 0;
			if (i >= a && dp[i - a] == 1)dp[i] = 1;
			if (i >= b && dp[i - b] == 1)dp[i] = 1;
			if (!dp[i])ans++;
		}
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 6940
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1){
    int m,t,p,r;
    cin>>m>>t>>p>>r;
    if(!m)break;
    vector<vector<int>> v(t,vector<int>(p,-1));
    REP(i,r){
      int M,T,P,J;
      cin>>M>>T>>P>>J;
      --T;--P;
      if(J!=0){
        v[T][P]--;
      }else{
        v[T][P]=M+(1+v[T][P])*(-20);
      }
    }
    vector<tuple<int,int,int>> a;
    REP(i,t){
      int ac=0;
      int pen=0;
      REP(j,p){
        if(v[i][j]>=0){
          ++ac;
          pen += v[i][j];
        }
      }
      a.emplace_back(-ac,pen,-(i+1));
    }
    sort(begin(a),end(a));
    bool nzero=false;
    for(auto itr=begin(a);itr!=end(a);++itr){
      int ac,pen,tn;
      tie(ac,pen,tn) = *itr;
      if(itr!=begin(a)){
        int pac,ppen;
        tie(pac, ppen, ignore) = *prev(itr);
        if(pac==ac&&ppen==pen){
          cout<<'=';
        }else{
          cout<<',';
        }
      }
      cout<<-tn;
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1220
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, int> LP;
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 main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string x, y;
	cin >> x >> y;
	if(x < y) cout << "<" << endl;
	else if(x == y) cout << "=" << endl;
	else cout << ">" << endl;
	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <string.h>
#include <iomanip>
using namespace std;
#define int long long
#define ull unsigned long long
#define F first
#define S second
#define nl "\n"
#define ld long double
#define div 1000000007
#define pi 3.14159265358979323846
#define pb push_back

void solve()
{
    int n,m;cin>>n>>m;
    vector<int> adj[n+1];
    for(int i=0;i<m;i++)
    {
        int a,b;cin>>a>>b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    queue<int> q;int level[n+1];
    memset(level,-1,sizeof(level));
    q.push(1);
    while(!q.empty())
    {
        int v=q.front();
        q.pop();
        for(int x:adj[v])
        {
            if(level[x]==-1)
            {
                level[x]=v;
                q.push(x);
            }
        }
    }
    bool ok=1;
    for(int i=2;i<=n;i++)
    {
        if(level[i]==-1)
            ok=0;
    }
    if(ok)
    {
        cout<<"Yes\n";
        for(int i=2;i<=n;i++)
            cout<<level[i]<<nl;
    }
    else
        cout<<"No\n";
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);

    int t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 13036
#include<bits/stdc++.h>
using namespace std;
void solve(){
  int n;
	cin>>n;
	cout<<(n^1)<<"\n";
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	long t=1;
//	cin>>t;
	while(t--)
		solve();
}

Measured memory_bytes: 3632
#include <vector>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int MAX_V = 333;
const int inf=1<<25;

struct edge { int id,to,cap,rev; };
vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];

void add_edge(int i,int f,int t,int cap)
{
  G[f].push_back((edge){i,t,cap,(int)G[t].size()});
  G[t].push_back((edge){0,f,0,(int)G[f].size()-1});
}

 void bfs(int s)
{
  memset(level,-1,sizeof(level));
  queue<int> q;
  level[s] = 0;
  q.push(s);
  while( !q.empty() ) {
    int v = q.front(); q.pop();
    for( int i = 0; i < int(G[v].size()); i++ ) {
      edge& e = G[v][i];
      if( e.cap > 0 && level[e.to] < 0 ) {
        level[e.to] = level[v]+1;
        q.push(e.to);
      }
    }
  }
}

int dfs(int v,int t,int f)
{
  if( v == t ) return f;
  for( int &i = iter[v]; i < int(G[v].size()); i++ ) {
    edge& e = G[v][i];
    if( e.cap > 0 && level[v] < level[e.to] ) {
      int d  = dfs(e.to,t,min(f,e.cap));
      if( d > 0 ) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t)
{
  int flow = 0;
  for(;;) {
    bfs(s);
    if( level[t] < 0 ) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while( (f = dfs(s,t,inf)) > 0 ) {
      flow += f;
    }
  }
}

int main(void)
{
  int n,m,s,t;
  scanf("%d%d",&n,&m);
  for( int i = 0; i < m; i++ ) {
    int a,b; scanf("%d%d",&a,&b); --a; --b;
    add_edge(0,a,b,1);
    add_edge(i+1,b,a,1);
  }
  scanf("%d%d",&s,&t); --s; --t;
  int res = max_flow(s,t);
  printf("%d\n",res);
  vector<int> v;
  for( int i = 0; i < n; i++ ) {
    for( int j = 0; j < int(G[i].size()); j++ ) {
      edge& e = G[i][j];
      if( e.id != 0 ) {
        if( e.cap == 0 ) v.push_back(e.id);
      }
    }
  }
  sort(v.begin(),v.end());
  printf("%d\n",int(v.size()));
  for( int i = 0; i < int(v.size()); i++ ) printf("%d\n",v[i]);
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
	//入力
	int A, B;
	cin >> A;
	vector<int> S(A);
	for (int i = 0; i < A; i++) cin >> S[i];
	cin >> B;
	vector<int> T(B);
	for (int i = 0; i < B; i++) cin >> T[i];
	//入力ここまで

	int res = 0; // ans用

	sort(S.begin(), S.end()); //数列Sをソート

	for (int i = 0; i < (int)T.size(); i++){
		int key = T[i];
		auto lower_iter = lower_bound(S.begin(), S.end(), key);
	//	auto upper_iter = upper_bound(S.begin(), S.end(), key);
	//	int dis = distance(lower_iter, upper_iter);
		if (lower_iter != S.end() && *lower_iter == key) res++;
	}

	cout << res << endl;




}



Measured memory_bytes: 3328
N=int(input())
X=[0]*4
S=''
for i in range(N):
  S=input()
  if S=='AC':
    X[0]+=1
  elif S=='WA':
    X[1]+=1
  elif S=='TLE':
    X[2]+=1
  else:
    X[3]+=1
print('AC x',X[0])
print('WA x',X[1])
print('TLE x',X[2])
print('RE x',X[3])


Measured memory_bytes: 69912
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

const llong INF = 1ll << 60ll;
llong h, n;
llong a[1005];
llong b[1005];

llong dp[1005][10005];
int main() {
    cin >> h >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= h; j++) {
            if (dp[i][j] == 0) dp[i][j] = INF;

            if (j - a[i] <= 0) {
                if (i == 0) dp[i][j] = b[i];
                else dp[i][j] = min(dp[i - 1][j], b[i]);
            }
            else {
                if (i == 0) {
                    dp[i][j] = dp[i][j - a[i]] + b[i];
                }
                else {
                    dp[i][j] = min({dp[i - 1][j],
                                    dp[i - 1][j - a[i]] + b[i], dp[i][j - a[i]] + b[i]});
                }
            }
        }
    }

    cout << dp[n - 1][h] << endl;

    return 0;
}


Measured memory_bytes: 78464
#define _CRT_SECURE_NO_WARNINGS

#include<fstream>
#include<iostream>
#include<string>
#include<iomanip>
#include<list>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>

using namespace std;

int main(int argc, char **argv){
	int n;
	int kane[] = { 500, 100, 50, 10, 5, 1 };
	int count;
	while (cin >> n && n != 0) {
		count = 0;
		n = 1000 - n;
		for (int i = 0; i < 6; i++) {
			count += (n / kane[i]);
			n %= kane[i];
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int main ()
{   
    long long int n;
    long long int ans;
    cin>>n;
    ans=n+1;
    long long int i;
    for (i=1;i*i<=n;i++)
    {    if (n%i==0)
        ans=min(ans,i+n/i);
    }
    cout<<ans-2<<"\n";
    return 0;
}


Measured memory_bytes: 256
using AtCoderBeginnerContest149.Questions;
using AtCoderBeginnerContest149.Extensions;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoderBeginnerContest149.Questions
{
    public class QuestionB : AtCoderQuestionBase
    {
        public override IEnumerable<object> Solve(TextReader inputStream)
        {
            var abk = inputStream.ReadLongArray();
            var takahashiCookie = abk[0];
            var aokiCookie = abk[1];
            var toEat = abk[2];

            if (takahashiCookie > toEat)
            {
                yield return $"{takahashiCookie - toEat} {aokiCookie}";
            }
            else if (takahashiCookie + aokiCookie > toEat)
            {
                yield return $"0 {takahashiCookie + aokiCookie - toEat}";
            }
            else
            {
                yield return "0 0";
            }
        }
    }
}

namespace AtCoderBeginnerContest149
{
    class Program
    {
        static void Main(string[] args)
        {
            IAtCoderQuestion question = new QuestionB();    // 問題に合わせて書き換え
            var answers = question.Solve(Console.In);
            foreach (var answer in answers)
            {
                Console.WriteLine(answer);
            }
        }
    }
}

#region Base Classes

namespace AtCoderBeginnerContest149.Questions
{

    public interface IAtCoderQuestion
    {
        IEnumerable<object> Solve(string input);
        IEnumerable<object> Solve(TextReader inputStream);
    }

    public abstract class AtCoderQuestionBase : IAtCoderQuestion
    {
        public IEnumerable<object> Solve(string input)
        {
            var stream = new MemoryStream(Encoding.Unicode.GetBytes(input));
            var reader = new StreamReader(stream, Encoding.Unicode);

            return Solve(reader);
        }

        public abstract IEnumerable<object> Solve(TextReader inputStream);
    }

}

#endregion

#region Extensions

namespace AtCoderBeginnerContest149.Extensions
{
    internal static class TextReaderExtensions
    {
        internal static int ReadInt(this TextReader reader) => int.Parse(ReadString(reader));
        internal static long ReadLong(this TextReader reader) => long.Parse(ReadString(reader));
        internal static double ReadDouble(this TextReader reader) => double.Parse(ReadString(reader));
        internal static string ReadString(this TextReader reader) => reader.ReadLine();

        internal static int[] ReadIntArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(int.Parse).ToArray();
        internal static long[] ReadLongArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(long.Parse).ToArray();
        internal static double[] ReadDoubleArray(this TextReader reader, char separator = ' ') => ReadStringArray(reader, separator).Select(double.Parse).ToArray();
        internal static string[] ReadStringArray(this TextReader reader, char separator = ' ') => reader.ReadLine().Split(separator);
    }
}

#endregion

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

int main()
{
    int n;
    cin >> n;
    vector<ll> v(n + 1);
    rep(i, n)
    {
        int x;
        cin >> x;
        v[x] = i + 1;
    }
    multiset<ll> wall;
    wall.insert(0);
    wall.insert(0);
    wall.insert(n + 1);
    wall.insert(n + 1);
    wall.insert(v[n]);
    ll ans = 0;
    for (ll i = n - 1; i > 0; i--)
    {
        ll w1, w2, w3, w4;
        auto it = wall.upper_bound(v[i]);
        it++;
        w4 = *it;
        it--;
        w3 = *it;
        it--;
        w2 = *it;
        it--;
        w1 = *it;
        ans += i * ((w2 - w1) * (w3 - v[i]) + (w4 - w3) * (v[i] - w2));
        wall.insert(v[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn partition(a: &mut Vec<u32>) -> usize {
    let mut i: usize = 0;
    let x = *a.last().unwrap();

    for j in 0..a.len() {
        if a[j] <= x {
            a.swap(i, j);
            i += 1;
        }
    }
    return i - 1;
}

fn main() {
    let n: usize = read();
    let mut a: Vec<u32> = (0..n)
        .map(|_| {
            let number: u32 = read();
            number
        })
        .collect();
    let partition_index: usize = partition(&mut a);
    for (index, number) in a.iter().enumerate() {
        if (index + 1) != a.len() {
            if index == partition_index {
                print!("[{}] ", number);
            } else {
                print!("{} ", number);
            }
        } else {
            println!("{}", number);
        }
    }
}



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

using namespace std;
typedef long long ll;

const int N = 310;
int n, a[4];
double dp[N][N][N];

double solve(int x, int y, int z)
{
	if (x < 0 || y < 0 || z < 0)
		return 0;
	if (x == 0 && y == 0 && z == 0)
		return 0;
	if (dp[x][y][z] != -1.0)
		return dp[x][y][z];
	double &ret = dp[x][y][z];
	double m = x + y + z;
	double val = n + x * solve(x - 1, y, z) + y * solve(x + 1, y - 1, z) + z * solve(x, y + 1, z - 1);
	return ret = val / m;
}

int main()
{
	ios_base::sync_with_stdio(false);

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int b;
		cin >> b;
		a[b]++;
	}
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			fill_n(dp[i][j], N, -1.0);
		}
	}
	double ans = solve(a[1], a[2], a[3]);
	cout << fixed << setprecision(12) << ans;

	return 0;
}

Measured memory_bytes: 233088
#include "bits/stdc++.h"
using namespace std;
const int N=5e3+20;
int n,dp[N][N];
char a[N];



// source - https://www.geeksforgeeks.org/longest-repeating-and-non-overlapping-subaing/
int longestRepeatedSubstring() 
{  
	int res_length  = 0; // To store length of result 
  
	// building table in bottom-up manner 
	int i, index = 0; 
	for (i=1; i<=n; i++) 
	{ 
		for (int j=i+1; j<=n; j++) 
		{ 
			// (j-i) > dp[i-1][j-1] to remove 
			// overlapping 
			if (a[i-1] == a[j-1] && 
				dp[i-1][j-1] < (j - i)) 
			{ 
				dp[i][j] = dp[i-1][j-1] + 1; 
  
				// updating maximum length of the 
				// subaing and updating the finishing 
				// index of the suffix 
				if (dp[i][j] > res_length) 
				{ 
					res_length = dp[i][j]; 
					index = max(i, index); 
				} 
			} 
			else
				dp[i][j] = 0; 
		} 
	} 
  
	return res_length; 
} 

int main()
{
	scanf("%d %s",&n,a);
	printf("%d",longestRepeatedSubstring());
}

Measured memory_bytes: 98560
import Data.List

main :: IO ()
main = do
  _ <- readLn :: IO Int
  as <- (map read . words) <$> getLine :: IO [Int]
  let (alice, bob) = oddEven $ sortBy (flip compare) as
  print $ sum alice - sum bob

-- | リストの要素を偶数番目の要素と奇数番目の要素のリストに分ける関数
oddEven :: [Int] -> ([Int], [Int])
oddEven list = halves list [] []
    where
        halves []       oddList evenList = (oddList,evenList)
        halves [x]      oddList evenList = (oddList++[x],evenList)
        halves (x:y:ys) oddList evenList = halves ys (oddList++[x]) (evenList++[y])


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<bool> res(n + 1);
	FOR(i, 1, n) {
		cin >> a[i];
	}
	RFOR(i, n, 1) {
		bool isodd = false;
		for (ll j = 2*i; j <= n; j += i) {
			if (res[j] & 1)isodd = !isodd;
		}
		res[i] = isodd^a[i];
	}
	int cnt = count(RANGE(res, 1, n + 1), 1);
	pv(cnt);
	if (cnt) {
		FOR(i, 1, n) {
			if(res[i])pv(i)
		}
	}
	return(0);
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>

using namespace std;

int cunting(int cunt,int n){
  int t;
  t = 0;
  int i;
  for( i = 0;t < n;i++){
    t += cunt;
  }
  return i;
}

typedef struct{
  int num;
  int value;
}pencil;

int main(){
  pencil a1;
  pencil a2;
  int N;

  cin >> N;
  cin >> a1.num >> a1.value;
  cin >> a2.num >> a2.value;

  int c1,c2;

  c1 = cunting(a1.num,N);
  c2 = cunting(a2.num,N);


  cout << min(a1.value*c1,a2.value*c2) << endl;
}



Measured memory_bytes: 3088
import math
N,H = map(int,input().split())
L = []
for i in range(N):
  L.append(list(map(int,input().split())))
cnt = 0
S = 0
k = L[0][0]
t = 0
flag = False
for i in range(1,N):
  k = max(k,L[i][0])
L = sorted(L,key = lambda x:x[1])
for j in range(N):
  if L[N-j-1][1] >= k:
    cnt += 1
    S += L[N-j-1][1]
    if S >= H:
      flag = True
      break
  else:
    break
if flag:
  print(cnt)
else:
  print(cnt+int(math.ceil((H-S)/k)))

Measured memory_bytes: 29784
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
    int K, N, Abuf, maxAdist;
    vector<int> A;
    cin >> K >> N;
    for(int i=0; i<N; i++){
        cin >> Abuf;
        A.push_back(Abuf);
    }
    maxAdist = 0;
    for(int i=0; i<N; i++){
        Abuf = A[(i+1)%N]-A[i];
        if(Abuf<0) Abuf += K;
        maxAdist = max(maxAdist, Abuf);
    }
    cout << K-maxAdist << endl;
    return 0;
}

Measured memory_bytes: 1400
N = int(input())
A = []
X = [[] for _ in range(N)]
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        X[i].append(list(map(int,input().split())))
ans = 0
for i in range(2**N):
    flag = False
    for j in range(N):
        if ((i >> j) & 1):
            for k in range(A[j]):
                if X[j][k][1]==1 and not ((i>>X[j][k][0]-1)&1):
                    flag = True
                    break
                if X[j][k][1]==0 and ((i>>X[j][k][0]-1)&1):
                    flag = True
                    break
        if flag:
            break
    if not flag:
        tmp = 0
        for j in range(N):
            if ((i >> j) & 1):
                tmp += 1
        ans = max(tmp,ans)
print(ans)

Measured memory_bytes: 45552
n=int(input())
a=list(map(int,input().split()))
if n%2==0:
    b=[0 for i in range(n//2)]
    k=n//2
    for i in range(n):
        if a[i]//2>k:
            print(0)
            break
        else:
            if b[a[i]//2-1]>1:
                print(0)
                break
            else:
                b[a[i]//2-1]+=1
    else:
        print(pow(2,n//2,10**9+7))
else:
    b=[0 for i in range(n//2+1)]
    for i in range(n):
        if a[i]//2>n//2+1:
            print(0)
            break
        elif a[i]==0:
            if b[0]==1:
                print(0)
                break
            else:
                b[0]+=1
        else:
            if b[a[i]//2]>1:
                print(0)
                break
            else:
                b[a[i]//2]+=1
    else:
        print(pow(2,n//2,10**9+7))

Measured memory_bytes: 14324
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;
using pint = pair<int,int>;
const int INF = 1<<29;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
bool chmin(int &a, int b) { if (a > b) {a = b; return true;} return false; }

int H, W, A, B;
vector<string> fi;

int main() {
    cin >> H >> W >> A >> B;
    fi.resize(H);
    for (int i = 0; i < H; ++i) cin >> fi[i];
    int sx, sy, tx, ty;
    for (int i = 0; i < H; ++i) for (int j = 0; j < W; ++j) {
            if (fi[i][j] == 's') sx = i, sy = j;
            if (fi[i][j] == 'g') tx = i, ty = j;
        }
    
    priority_queue<pair<int,pint>, vector<pair<int,pint> >,
                   greater<pair<int,pint> > > que;
    que.push({0, pint(sx, sy)});
    vector<vector<int> > dp(H, vector<int>(W, INF));
    dp[sx][sy] = 0;
    while (!que.empty()) {
        auto cur = que.top(); que.pop();
        int cur_dist = cur.first;
        int x = cur.second.first;
        int y = cur.second.second;
        if (cur_dist > dp[x][y]) continue;

        //cout << x << ", " << y << ": " << cur_dist << endl;

        // 通常の移動
        for (int dir = 0; dir < 4; ++dir) {
            int nx = x + dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (fi[nx][ny] == '#') continue;
            if (chmin(dp[nx][ny], dp[x][y] + A)) que.push({dp[nx][ny], pint(nx, ny)});
        }

        // 魔法
        bool can = true;
        for (int i = x-1; i <= x+1; ++i)
            for (int j = y-1; j <= y+1; ++j) {
                if (i < 0 || i >= H || j < 0 || j >= W) continue;
                if (fi[i][j] == '*') can = false;
            }
        if (can) {
            for (int i = x-1; i <= x+1; ++i)
                for (int j = y-1; j <= y+1; ++j) {
                    if (i < 0 || i >= H || j < 0 || j >= W) continue;
                    if (i == x && j == y) continue;
                    if (fi[i][j] != '#') continue;
                    if (chmin(dp[i][j], dp[x][y] + B + A * (abs(i-x) + abs(j-y))))
                        que.push({dp[i][j], pint(i, j)});
                }       
        }
    }
    if (dp[tx][ty] < INF) cout << dp[tx][ty] << endl;
    else cout << "INF" << endl;
}



Measured memory_bytes: 7744
#include <bits/stdc++.h>
using LL = long long;
const LL MOD = 1e9+9;
using namespace std;



int main(){
    LL N,L;cin >> N >> L;
    vector<LL> vec;
    for(int a = 0;a < N;a++){
        LL b;cin >> b;
        vec.push_back(b);
    }
    int ins = -1;
    for(int a = 0;a < N-1;a++){
        if(vec.at(a)+vec.at(a+1) >= L){
            ins = a;
        }
    }
    if(ins == -1){
        cout<<"Impossible"<<endl;
        return 0;
    }
    cout<<"Possible"<<endl;
    for(int a = 1;a <= ins;a++){
        cout<<a<<endl;
    }
    for(int a = N-1;a >= ins+1;a--){
        cout<<a<<endl;
    }
}


Measured memory_bytes: 1780
#!/usr/bin/env python3
import sys

def solve(h, w, a):
    dp = [[-1] * (h * w) for _ in range(h * w)]
    dx = [0, 0, 1, -1]
    dy = [1, -1, 0, 0]
    def bfs(x1, y1, x2, y2):
        s = y1 * w + x1
        t = y2 * w + x2
        visited = [[False] * w for _ in range(h)]
        cur = []
        visited[y1][x1] = True
        cur.append((x1, y1))
        cnt = 1
        while True:
            nex = []
            for x, y in cur:
                for i in range(4):
                    tx = x + dx[i]
                    ty = y + dy[i]
                    if 0 <= tx < w and 0 <= ty < h and a[ty][tx] != '#' and not visited[ty][tx]:
                        visited[ty][tx] = True
                        dp[s][ty * w + tx] = cnt
                        dp[ty * w + tx][s] = cnt
                        if tx == x2 and ty == y2:
                            return cnt
                        nex.append((tx, ty))
            if len(nex) > 0:
                cur = nex
            else:
                break
            cnt += 1
        return -1

    ret = -1
    for i in range(h):
        for j in range(w):
            for i2 in range(h):
                for j2 in range(w):
                    if (i == i2 and j == j2):
                        dp[w * i + j][w * i2 + j2] = 0
                        dp[w * i2 + j2][w * i + j] = 0
                    elif a[i][j] == '.' and a[i2][j2] == '.' and dp[w * i + j][w * i2 + j2] < 0:
                        tmp = bfs(j, i, j2, i2)
                        ret = max(ret, tmp)
                        #dp[w * i + j][w * i2 + j2] = tmp
                        #dp[w * i2 + j2][w * i + j] = tmp
                        #print(i, j, i2, j2)
                        #print(tmp)
    print(ret)
    return

def main():
    h, w = map(int, input().split())
    a = []
    for i in range(h):
        a.append(input())
    solve(h, w, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 54360
n = int(input())
a = list(map(int, input().split()))
ans = 0
count = 0
for i in range(n):
    if a[i] < 0:
        count += 1
    a[i] = abs(a[i])
    ans += a[i]
if count % 2 == 0:
    print(ans)
else:
    ans -= 2 * min(a)
    print(ans)

Measured memory_bytes: 20000
def ans():
  N, M, C = map(int,input().split())
  B = list(map(int,input().split()))
  A = [list(map(int,input().split())) for _ in range(N)]
  cnt  = 0
  for a in A:
    tmp = C
    for i in range(M):
      tmp += a[i]*B[i]
    if(tmp > 0):
      cnt += 1
  print(cnt)
ans()

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

typedef long long ll;
using namespace std;

ll dp[3010][3010][4];
int v[3010][3010];

int main() {
    memset(v,-1,sizeof(v));
    memset(dp, 170, sizeof(dp));
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int R, C, k;
    cin >> R >> C >> k;
    for(;k;k--){
        int r,c;
        cin>>r>>c;
        r--;c--;
        cin>>v[r][c];
    }
    if(v[0][0]!=-1){
        dp[0][0][1]=v[0][0];
    }
    dp[0][0][0]=0;
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            for(int t=0;t<=3;t++) {
                if (v[i + 1][j] != -1) {
                    dp[i + 1][j][1]=max(dp[i+1][j][1],dp[i][j][t]+v[i+1][j]);
                }
                if (v[i][j + 1] != -1&&t!=3) {
                    dp[i][j + 1][t+1]=max(dp[i][j + 1][t+1],dp[i][j][t]+v[i][j + 1]);
                }
                dp[i + 1][j][0]=max(dp[i+1][j][0],dp[i][j][t]);
                dp[i][j + 1][t]=max(dp[i][j + 1][t],dp[i][j][t]);
            }
        }
    }
    ll ans = 0;
    for(int t=0;t<=3;t++){
        ans=max(ans,dp[R-1][C-1][t]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 322076
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int a[105],b[105]={};
    int x,n;
    cin >> x >> n;
    if(n==0)
    {
        cout << x << endl;
        return 0;
    }
    for(int i=1;i<=n;i++)
    {
        cin >> a[i];
        b[a[i]]=1;
    }

    int mn1,mn2;
    for(int i=x;i>=0;i--)
    {
        if(b[i]==0)
        {
            mn1 = i;
            break;
        }
    }

    for(int i=x+1;i<=101;i++)
    {
        if(b[i]==0)
        {
            mn2 =i;
            break;
        }
    }

    if(abs(x-mn1)<=abs(x-mn2))
        cout << mn1 << endl;
    else
        cout << mn2 << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,m,x,ma=0,ans=0;
	cin>>n>>m;
	int a[n],b[n];
	for(int i=0;i<n;i++){
		b[i]=0;
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		cin>>x;
		for(int j=0;j<n;j++){
			if(x>=a[j]){
			b[j]++;
				if(b[j]>ma){
				ma=b[j];
				ans=j+1;
				}
			break;
			}
		}
	}
	cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <vector>
#include <string>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF

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

#define maxs(x,y) (x=std::max(x,y))
#define mins(x,y) (x=std::min(x,y))

int main() {
  ll N;
  std::cin >> N;
  ull tmp_N = N*(N-1);
  cout << tmp_N / 2 << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<string>
#include <cstdlib>
using namespace std;
int main() {
	string A, B;
	cin >> A >> B;
	if (A == B) {
		cout << "EQUAL" << endl;
	}
	else if (A > B && A.size() >= B.size()) {
		cout << "GREATER" << endl;
	}
	else cout << "LESS" << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  vector<int> d(N);
  
  for (int i = 0; i < N; i++) {
    cin >> d.at(i);
  }
  
  sort(d.begin(), d.end());
  
  int x;
  
  x = d[N/2] - d[N/2 - 1];
  cout << x << endl;
  
  return 0;
}

Measured memory_bytes: 640