akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	x=0;char c=getchar();bool f=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
	if(x<0){putchar('-'),write(-x);}
	else{if(x>9)write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=5e3+5;
int k,q,a[N],pre[N],zero[N];

void doit(){
	int n,x,m;
	read(n);read(x);read(m);
	for(int i=1;i<=k;i++) pre[i]=pre[i-1]+a[i]%m;
	int y=x+pre[k]*((n-1)/k)+pre[(n-1)%k];
	for(int i=1;i<=k;i++) zero[i]=zero[i-1]+(a[i]%m==0);
	write((n-1)-((y/m-x/m)+(zero[k]*((n-1)/k)+zero[(n-1)%k])));puts("");
}

signed main(){
	read(k);read(q);
	for(int i=1;i<=k;i++) read(a[i]);
	while(q--) doit();
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <vector>
#include <functional>
#include <list>


using namespace std;

bool cmp(pair<int,string> a , pair<int,string> b){  
	return a.first > b.first; 
} 

int main(void){
	bool b=false;
	while(1){
		int a,n;
		string s;
		multimap<int, string, greater<int> > P;
		int w,d,l;
		cin >> n;
		if(n==0)break;
		if(b==true)cout << endl;
		b=true;
		for(a=0;a<n;a++){
			 cin >> s >> w >> l >> d; 
			P.insert( pair<int, string>(w*3+d,s));
		}
		multimap<int, string, greater<int> >::iterator it = P.begin();
		while( it != P.end() )	{
			cout << (*it).second << "," << (*it).first << endl;
			++it;
		}
	}
	return 0;
}

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
	string s;
	cin >> s;
	
	int ia = -1, iz;
	fr(i,sz(s)){
		if(ia==-1 and s[i]=='A') ia = i;
		if(s[i]=='Z') iz = i;
	}
	cout << iz-ia+1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rt "\n"
#define sp " "
#define test(n) cout << "test" << n << endl;
#define fixsp(n) fixed << setprecision(n)
#define defsp(n) defaultfloat << setprecision(n)
#define kyopro ios::sync_with_stdio(false);cin.tie(NULL)
#define MOD 1000000007
#define iikae auto&
#define zenbu(a) a.begin(), a.end()
#define rep(i, s, N) for(ll i{s}; i < N; i++)
#define rem(i, N, s) for(ll i{N}; i > s; i--)
using namespace std;using ll = long long;using ld = long double;using P = pair<ll,ll>;
template<typename T> T gcd(T a, T b){return b != 0 ? gcd(b, a % b) : a;}
template<typename T> struct UnionFind{vector<T> par;UnionFind(T n) : par(n, -1){}void init(T n){par.assign(n, -1);}T root(T x){if (par[x] < 0) return x;else return par[x] = root(par[x]);}bool issame(T x, T y){return root(x) == root(y);}bool merge(T x, T y){x = root(x); y = root(y);if(x == y) return false;if(par[x] > par[y]) swap(x, y);par[x] += par[y];par[y] = x;return true;}int size(int x) {return -par[root(x)];}};

/* ここからコード開始 */

int main(){
  kyopro;
  ll N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  ll saishou = min({A, B, C, D, E});
  ll ans = (N - 1) / saishou + 5;
  cout << ans << rt;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		long A  = keyboard.nextLong();
		long B  = keyboard.nextLong();
		long C  = keyboard.nextLong();
		long D  = keyboard.nextLong();
		
		long b = 0;
		long a = 0;
		
		b = B - (B/C +B/D - B/(lcm(C, D)));
		a = (A-1) - ((A-1)/C +(A-1)/D - (A-1)/(lcm(C, D)));

		System.out.println(b - a);
		keyboard.close();	
	}
	
	private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
	}
	
	private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
        }
}


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

bool p(string s) {
  for (int i = 0; i < s.length()/2; ++i) {
    if (s[i] != s[s.length()-1-i]) return false;
  }
  return true;
}
int main() {
  cin.tie(0), ios::sync_with_stdio(false);
  string s;
  cin >> s;
  if (p(s) && p(s.substr(0, s.length()/2)) && p(s.substr(s.length() - s.length()/2))) cout << "Yes\n";
  else cout << "No\n";
}

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

int main(){
  ll x;cin>>x;
  for(ll i=-1000;i<=1000;i++){
      for(ll j=-1000;j<=1000;j++){
          if(i*i*i*i*i-j*j*j*j*j==x){
              cout<<i<<" "<<j;
              return 0;
          }
      }
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> d(N);
  int res = 0;
  for (int i = 0; i < N; i++) cin >> d[i];
  for (int i = 0; i < N-1; i++) {
    for (int j = i+1; j < N; j++) {
      int tmp = d[i]*d[j];
      res += tmp;
    }
  }
  cout << res;
}


Measured memory_bytes: 256
/******************gourav_j**************/
#include <bits/stdc++.h>
#define FF first
#define SS second
#define pb push_back
#define mp make_pair
#define INF 1e18
#define MOD 1000000007
#define MAXN 100005
#define mem(a, v) memset(a, v, sizeof a)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define fori(i,a,b) for(int  i=(a);i<=(b);i++)
#define forl(i,a,b) for(ll  i=(a);i<=(b);i++)
#define rfor(i,a,b) for(int i=(b);i>=(a);i--)
#define forit(i, a) for ( __typeof( (a).begin() ) i = (a).begin(); i != (a).end(); i++ )
#define all(v) (v.begin(),v.end())
using namespace std;
 
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef map<string,ll> msi;
typedef set<ll> si;
int dx[] = {-1, 0, 0, 1};
int dy[] = { 0,-1, 1, 0};
                /***********code begins here***********/

void solve(){
    int m,d;
    int c=0;
    cin>>m>>d;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            int a = j/10;
            int b = j%10;
            if(a>=2&&b>=2&&a*b==i){ 
                c++;
            }
        }
    }
    cout<<c;
}
int main() {
    
    int T=1; 
    //cin>>T;
    while(T--){
        solve();
        cout<<'\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char field[101][101];
int cou,H,W;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
void func(int x,int y,char mark){
    if(x<0||x>W||y<0||y>H||field[y][x]!=mark)return;
    field[y][x]='0';
    for(int i=0;i<4;i++){
            func(x+dx[i],y+dy[i],mark);
    }
}
int main(){
    for(;;){
        cou=0;
        cin>>H>>W;
        if(H==0&&W==0)break;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin>>field[i][j];
            }
        }
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(field[i][j]!='0'){
                    func(j,i,field[i][j]);
                    cou++;
                }
            }
        }
        cout<<cou<<endl;
    }
    return 0;
}

Measured memory_bytes: 1632
#include <iostream>

using namespace std;

int main() {
	int N, D, X;
	int A[100];
	cin >> N >> D >> X;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		int j = 0, cnt = 0;
		while (cnt <= D) {
			cnt = j * A[i] + 1;
			if (cnt > D) {
				break;
			}
			ans++;
			j++;
		}
	}
	

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

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int n;
int a[100010];
int b[100010];
LL f[100010];
LL inv[100010];
const LL mod = 1e9 + 7;

void func(){
	inv[n+1] = 1;
	LL z = mod-2;
	LL x = f[n+1];
	for(; z > 0 ; z /= 2){
		if(z%2==1) (inv[n+1] *= x) %= mod;
		x = x * x % mod;
	}
}

LL com(int x , int y){
	if(x<y || x < 0 || y < 0) return 0;
	return f[x] * inv[y] % mod * inv[x-y] % mod;
}

int main(){
	scanf("%d" , &n);
	fill(b,b+n+1,-1);
	f[0] = 1;
	repp(i,1,n+2){
		f[i] = f[i-1] * i % mod;
	}
	func();
	repm(i,n,0){
		inv[i] = inv[i+1] * (i+1) % mod;
	}
	inv[0] = 1;
	repp(i,0,n+1){
		scanf("%d" , a + i);
		if(b[a[i]]>=0){
			b[0] = i;
		} else {
			b[a[i]] = i;
		}
	}
	int q = b[0];
	int p = b[a[q]];
	q = n - q;
	repp(i,0,n+1){
		printf("%lld\n" , (com(n+1,i+1) - com(p+q,i) + mod) % mod);
	}
	return 0;
}


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

int main() {
    int N, c = 0;
    cin >> N;
    int a[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    while (true) {
        for (int i = 0; i < N; i++) {
            if (a[i] % 2 == 0) {
                a[i] /=2;
            }
            else {
                cout << c << endl;
                return 0;
            }
        }
        c++;
    }
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

const double PI = acos(-1);
int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m;
	cin >>n >>m;
	
	VI a(m), c(m);
	rep(i, m){
		int b, z;
		cin >> a[i] >>b;
		rep(j, b){
			cin >>z; c[i] |= 1<<(z-1);
		}
	}
	VI dp(1<<n, MD); dp[0] = 0;
	rep(i, m) rep(j, 1<<n) if(dp[j]<MD){
		int nj = j | c[i];
		dp[nj] = min(dp[nj], dp[j]+a[i]);
	}
	int ans = dp[(1<<n) -1];
	cout << (ans==MD? -1: ans )<<"\n";
	return 0;
	
}


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

int main(){
  int64_t A,B,K;
  cin >> A >> B >>K;
  
  if(A >= K) A -= K;
  else if(A+B >= K){
    B = B-K+A;
    A = 0;
  }
  else if(A+B < K) {
    A = 0;
    B = 0;
  }
  cout << A << " " << B;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  intmax_t x;
  scanf("%zu %jd", &N, &x);

  std::vector<intmax_t> a(N);
  for (size_t i=0; i<N; ++i)
    scanf("%jd", &a[i]);

  std::vector<intmax_t> b=a;
  uintmax_t res=1e18;
  for (size_t i=0; i<N; ++i) {
    for (size_t j=0; j<N; ++j)
      b[j] = std::min(b[j], a[(j+N-i)%N]);

    uintmax_t cur=i*x;
    for (size_t j=0; j<N; ++j)
      cur += b[j];

    res = std::min(res, cur);
  }

  printf("%jd\n", res);
}


Measured memory_bytes: 384
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))

x = 0
num = 0
while( num <= N):
    if x == 1:
        print(num)
        break
    elif num == N:
        print(-1)
    num += 1
    x = a[x] - 1

Measured memory_bytes: 7212
#include<cstdio>
main(){
	int a[3],buf=4096;
	scanf("%d%d%d",&a[0],&a[1],&a[2]);

	for(int i=0;i<3;i++){
		for(int j=1;j<3;j++){
			if(a[j-1]>a[j]){
				buf = a[j];
				a[j] = a[j-1];
				a[j-1] = buf;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
}

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

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

    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a.at(i);
    }

    for(int i = n-1; i >= 0; i--) {
        cout << a.at(i);
        i == 0 ? cout << endl : cout << ' ';
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
const ll MOD=1e9+7;
using namespace std;

class UnionFind{
private:
  //par[x]はxの根の値
  vector<ll> par;
public:
  UnionFind(ll N){
    par.assign(N,-1);
  }
  ll root(ll x){
    return (par[x]<0 ? x : par[x]=root(par[x]));
  }
  //親が同じ
  ll same(ll x, ll y){
    return (root(x)==root(y));
  }
  //xの集合とyの集合を結合
  void unite(ll x, ll y){
    x=root(x), y=root(y);
    if(x==y){
      return;
    }
    //要素の個数が大きい方に、小さい方を結合させる
    //要素の個数が大きいほうがx、小さい方がy
    if(par[y]<par[x]) swap(x,y);
    par[x]+=par[y];
    par[y]=x;
  }
  ll size(ll x){
    return -par[root(x)];
  }

};

int main(){
  ll N,M;
  cin >> N >> M;
  vector<ll> p(N),x(M),y(M);
  rep(i,N){
    cin >> p[i];
    p[i]--;
  }
  rep(i,M){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  UnionFind uf(N);
  ll ans=0;
  rep(i,M){
    uf.unite(x[i],y[i]);
  }
  rep(i,N){
    if(uf.same(i,p[i])) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

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

int main() {
  unsigned long long X, S = 0;
  long long A = 1, B;
  long long A5;
  cin >> X;
  while (true) {
    A5 = pow(A, 5);
    for (size_t i = 0; i < A; ++i) {
      B = i;
      if (A5 + pow(B, 5) == X) {
        cout << A << " " << -B << endl;
        return 0;
      }
      if (A5 - pow(B, 5) == X) {
        cout << A << " " << B << endl;
        return 0;
      }
    }
    A++;
  }

  return 0;
}


Measured memory_bytes: 3952
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long

int main(){
  long x;
  cin>>x;
  long ans = (x/11)*2;
  x%=11;
  if(x>6) ans+=2;
  else if(x>0) ans+=1;

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int H, W;
    while(1){
        scanf("%d %d", &H, &W);
        if((H && W) == 0){
            break;
        }for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((i + 1) % 2 == 1){
                    if((j + 1) % 2 == 1){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }else{
                    if((j + 1) % 2 == 1){
                        printf(".");
                    }else{
                        printf("#");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2696
import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

A2=[(num,ind) for ind,num in enumerate(A)]
A2.sort(reverse=True)

L=[0]*N

for i in range(N):
    num,ind=A2[i]
    NL=[0]*N
    for j in range(i+1):
        right=N-1-(i-j)
        NL[j]=max(NL[j],abs(right-ind)*num+L[j])

        if j!=N-1:
            NL[j+1]=max(NL[j+1],abs(j-ind)*num+L[j])
    L=NL
print(max(L))

Measured memory_bytes: 78820
n,a,b=map(int,input().split())

def total_devision(j):
    sum=0
    while j>0:
        sum+=int(j%10)
        j=int(j/10)
    return sum

total_2=0
for i in range(n+1):
    total=total_devision(i)
    if a<=total<=b:
        total_2+=i

print(total_2)

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	a := getString()
	b := getString()
	c := getString()

	ans := "NO"
	if a[len(a)-1] == b[0] && b[len(b)-1] == c[0] {
		ans = "YES"
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
    int Q; cin >> Q;

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

    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21724
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  sort(A.rbegin(),A.rend());
  int sum = 0;
  for(int i=0; i<N; i++){
    if(i%2){
      sum -= A[i];
    }else{
      sum += A[i];
    }
  }
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 3648
from collections import deque
s=deque(list(input()))
q=int(input())
l = [list(input().split()) for i in range(q)]
c=0
for i in range(q):
  if l[i][0]=="1":
    c+=1
  elif c%2==0 and l[i][1]=="1":
    s.appendleft(l[i][2])
  elif c%2==0:
    s.append(l[i][2])
  elif c%2==1 and l[i][1]=="1":
    s.append(l[i][2])
  else:
    s.appendleft(l[i][2])
s=list(s)
if c%2==1:
  s=s[::-1]
print(*s, sep="")

Measured memory_bytes: 40036
import std.stdio, std.string, std.conv;
import std.algorithm, std.array;
 
void main()
{
    for(string s_; (s_=readln.chomp()).length;)
    {
        auto NL = s_.split.map!(to!int);
        immutable N=NL[0], L=NL[1];
        immutable a = readln.split.map!(to!int).array();
        int k=0,m=-1;
        foreach(i;1..N) if(m<a[i-1]+a[i]) k=i,m=a[i-1]+a[i];
        if(m<L) writeln("Impossible");
        else
        {
            writeln("Possible");
            foreach(i;1..k) writeln(i);
            foreach_reverse(i;k+1..N) writeln(i);
            writeln(k);
        }
    }
}

Measured memory_bytes: 4040
# include <bits/stdc++.h>
# define int long long
# define fi first
# define se second

using namespace std ;

const int N = 1e5 + 1 ;
int v[N], us[N], mx, ans ;
vector < int > vc[N] ;

int dfs( int u ) {
    if( us[u] ) return us[u] ;
    int mx = 0 ;
    for( auto i : vc[u] ) {
        mx = max( mx, dfs( i ) + 1 ) ;
    }
    us[u] = mx ;
    return mx ;
}

int32_t main() {
    //freopen("haybales.in", "r", stdin ) ;
    //freopen("haybales.out", "w", stdout ) ;
    int n, m ;
    cin >> n >> m ;
    for( int i = 1 ; i <= m ; i ++ ) {
        int x, y ;
        cin >> x >> y ;
        vc[x].push_back(y) ;
    }
    for( int i = 1 ; i <= n ; i ++ ) {
        if( !us[i] ) {
            ans = max( ans, dfs( i ) ) ;

        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 11888
import java.awt.*;
import java.awt.geom.*;
import java.io.*;

import java.util.*;
class Main {


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[n];
		for(int i = 0; i < n; i++) {
			l[i] = sc.nextInt();
		}
		System.out.print(l[n-1]);
		for(int i = n-2; i >= 0; i--) {
			System.out.print(" " + l[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 17256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define pb push_back
inline bool check(int i, int x) {
	return i & (1 << x);
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> a(h);
	for (int i = 0; i < h; i++)
		cin >> a[i];
	int hw = 1 << (h + w);
	int ans = 0;
	for (int i = 0; i < hw; i++) {
		int cnt = 0;
		for (int hh = 0; hh < h; hh++)
			for (int ww = 0; ww < w; ww++)
				if (a[hh][ww] == '#' && !check(i, hh) && !check(i, ww + h))
					cnt++;
		if (cnt == k) ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
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;
	}
}
long long COMB(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;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
class UnionFind {
protected:
	int* par, * rank, * size;
public:
	UnionFind(unsigned int size) {
		par = new int[size];
		rank = new int[size];
		this->size = new int[size];
		rep(i, size) {
			par[i] = i;
			rank[i] = 0;
			this->size[i] = 1;
		}
	}
	int find(int n) {
		if (par[n] == n)return n;
		return par[n] = find(par[n]);
	}
	void unite(int n, int m) {
		n = find(n);
		m = find(m);
		if (n == m)return;
		if (rank[n] < rank[m]) {
			par[n] = m;
			size[m] += size[n];
		}
		else {
			par[m] = n;
			size[n] += size[m];
			if (rank[n] == rank[m])rank[n]++;
		}
	}
	bool same(int n, int m) {
		return find(n) == find(m);
	}
	int getsize(int n) {
		return size[find(n)];
	}
};
int n;
int a[114];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	int ans = inf;
	rep(i, 111) {
		int memo = 0;
		rep(j, n) {
			memo += (i - a[j]) * (i - a[j]);
		}
		chmin(ans, memo);
	}
	cout << ans << endl;
	ggr
}


Measured memory_bytes: 256
N = int(input())
L = list(map(int, input().split()))

dic = {}
for i in range(N):
    if L[i] in dic:
        dic[L[i]] += 1
    else:
        dic[L[i]] = 1
        
res = 1
for d in dic:
    if d != 0:
        if dic[d] != 2:
            res = 0
            break
        else:
            res = (res*2)%(10**9+7)
    else:
        if N%2 == 0 and dic[d] != 0:
            res = 0
            break
        elif N%2 == 1 and dic[d] != 1:
            res = 0
            break

if res != 0:
    i = 0
    for _ in range(N+1):
        if N - 2*i - 1 < 1:
            break
        if (N - 2*i - 1 in dic) == False:
            res = 0
            break
        i += 1
        
print(res)

Measured memory_bytes: 14436
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void){
	int i,n;
	int taro=0, hanako=0;
	int flag;
	char t[100], h[100];

	scanf("%d", &n);
	while(n!=0){
		scanf("%s %s", t, h);
		flag = strcmp(t,h);
		if(flag==0){
			taro++;
			hanako++;
		} else if(flag >0)
			taro +=3;
		else
			hanako += 3;
		n--;
	}


	printf("%d %d\n", taro, hanako);

	return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>

using namespace std;

using ll = long long;

map<ll, ll> fact(ll n) {
    map<ll, ll> res;
    
    ll tmp = n;
    
    for (ll i = 2; i * i <= n; i++) {
        while(tmp % i == 0) {
            res[i]++;
            
            tmp /= i;
        }
    }
    
    if (tmp != 1) {
        res[tmp]++;
    }
    
    return res;
}

int main()
{
    
    ll n, m;
    cin >> n >> m;
    
    auto f = fact(m);
    
    const ll mod = 1000000000 + 7;

    const int maxi = 1000000;
    
    vector<ll> inv(maxi);
    vector<ll> fact(maxi);
    vector<ll> fact_inv(maxi);

    for (ll i = 1; i < maxi; i++) {
        inv[i] = (i == 1) ? 1 : (mod - (mod / i) * inv[mod % i] % mod);
    }

    fact[0] = 1;
    fact_inv[0] = 1;

    for(int i = 1; i < maxi; ++i) {
        fact[i] = fact[i - 1] * i % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }

    auto comb = [&](int n, int k) {
        if (n < 0 || n < k) {
            return ll(0);
        }

        return fact[n] * fact_inv[n - k] % mod * fact_inv[k] % mod;
    };
    
    ll ans = 1;
    
    for (auto p : f) {
        ans = ans * comb(p.second + n - 1, n - 1) % mod;   
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 24312
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int A[] = new int[n];
        int B[] = new int[n];
        int C[] = new int[n];
        for (int i = 0; i < n; i++) {
            A[i] = s.nextInt();
        }
        for (int i = 0; i < n; i++) {
            B[i] = s.nextInt();
        }
        for (int i = 0; i < (n-1); i++) {
            C[i] = s.nextInt();
        }
        int ans=0;
        for(int i=0;i<n;i++){
            ans+=B[i];
        }
        for(int i=0;i<n-1;i++){
            if((A[i]+1)==A[i+1]) {
                ans += C[A[i]-1];
            }
        }
        System.out.print(ans);
    }
}

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

int main() {
  int k;
  cin >> k;
  int p = 0;
  for (int i = 1; i <= k; i++) {
    p = (10*p+7)%k;
    if (p == 0) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
vector<int> E[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		E[y].push_back(x);
	}
	int pre=0;
	int cnt=0;
	FOR(i,101000) {
		int ng=0;
		FORR(e,E[i]) if(e>=pre) ng++;
		if(ng) cnt++, pre=i;
	}
	cout<<cnt<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 4992
from collections import Counter
n, m = map(int, input().split())
a = list(map(int, input().split()))
l = [0]
for i in range(n):
    l.append(a[i] + l[i])
for i in range(n + 1):
    l[i] %= m
c = Counter(l)
ans = 0
for i in c.values():
    ans += i * (i - 1) // 2
print(ans)

Measured memory_bytes: 21880
#define    ll           long long
    #define    dn           double
    #define    mp           make_pair
    #define    pb           push_back
    #define    se           second
    #define    fi           first
    #define    mod          1000000007
    #define    sob(v)       v.begin(),v.end()
    #define    sobr(v)      v.rbegin(),v.rend()
    #define    fr(i,a,b)    for(int i=a;i<=b;++i)
    #define    frr(i,a,b)   for(int i=a;i>=b;--i)
    #define    pi           acos(-1.00)
    #define    check        cout<<"*"<<endl
    #define    ffix(x)      cout<<fixed<<setprecision(x)
    #define    fast         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)

    #include<bits/stdc++.h>
    #include<string.h>
    using namespace std;


    typedef vector<int> vi;
    typedef map<int,int> mii;
    typedef pair<int,int> pii;
    typedef pair<int,vi> pp;

    int dr[8]= {0,0,-1,1,-1,-1,+1,+1};
    int dc[8]= {-1,1,0,0,-1,+1,-1,+1};

    const int N=2000000;

    int main()
    {
        int a,b,c,k;
        cin>>a>>b>>c>>k;
        if(a>=b)
        {
            while(k>0)
            {
                b*=2;
                k--;
                if(b>a)break;
            }
        }
        if(b>=c)
        {
            while(k>0)
            {
                c*=2;
                k--;
                if(c>b)break;
            }
        }
        if(c>b && b>a)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }


Measured memory_bytes: 3600
#!/usr/bin/env pypy3

import itertools


MAX_ANS = 3500


def solve(n):
    for h, m in itertools.product(range(1, MAX_ANS + 1), repeat=2):
        d = 4 * h * m - n * m - n * h
        if d <= 0:
            continue
        w, mo = divmod(n * h * m, d)
        if mo == 0 and w > 0:
            return h, m, w
    assert False


def main():
    n = int(input())
    res = solve(n)
    print(*res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39152
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
place = lines[1]

answer = 100000000000000000
for x in 1..100 do
  sum = 0
  for i in 1..N do
    sum += (place[i-1] - x) ** 2
  end
  if sum < answer then
    answer = sum
  end
end
  
print answer

Measured memory_bytes: 1788
/**
  @date Time-stamp: <2019-04-27 21:15:21 tagashira>
  @file a.cpp
  @brief https://atcoder.jp/contests/abc123/tasks/abc124_a
**/

#include <cmath>
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
  int A, B, T;
  cin >> A >> B >> T;

  int count = T / A;
  // cout << count << "\n";
  int sum = B * count;

  cout << sum << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
struct data{
    int ly,lx,ry,rx;
    data(int ly,int lx,int ry,int rx):ly(ly),lx(lx),ry(ry),rx(rx){}
};

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

int H,W;
char L[50][50],R[50][50];
int dp[50][50][50][50];
int sly,slx,sry,srx;
int gly,glx,gry,grx;
bool ok(int y,int x,bool isL){
    if(isL)return !(y<0||y>=H||x<0||x>=W||L[y][x]=='#');
    return !(y<0||y>=H||x<0||x>=W||R[y][x]=='#');
}

void solve(){
    queue<data>q;
    REP(i,50)REP(j,50)REP(k,50)REP(l,50)dp[i][j][k][l]=INF;
    dp[sly][slx][sry][srx]=0;
    q.push(data(sly,slx,sry,srx));
    while(q.size()){
        data d=q.front();q.pop();
        REP(i,4){
            int nly=d.ly+dy[i],nlx=d.lx+dx[i];
            int nry=d.ry+dy[i],nrx=d.rx-dx[i];
            if(!ok(nly,nlx,true)){
                nly=d.ly;nlx=d.lx;
            }
            if(!ok(nry,nrx,false)){
                nry=d.ry;nrx=d.rx;
            }
            if(dp[nly][nlx][nry][nrx]!=INF)continue;
            dp[nly][nlx][nry][nrx]=dp[nly][nlx][nry][nrx]+1;
            if((gly==nly&&glx==nlx)&&!(gry==nry&&grx==nrx))continue;
            if(!(gly==nly&&glx==nlx)&&(gry==nry&&grx==nrx))continue;
            q.push(data(nly,nlx,nry,nrx));
        }
    }
    if(dp[gly][glx][gry][grx]!=INF)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

int main(){
    while(1){
        cin>>W>>H;
        if(W==0&&H==0)break;
        REP(i,H){
            REP(j,W)cin>>L[i][j];
            REP(j,W)cin>>R[i][j];
        }
        REP(i,H){
            REP(j,W){
                if(L[i][j]=='L'){
                    sly=i;slx=j;
                }
                if(L[i][j]=='%'){
                    gly=i;glx=j;
                }
                if(R[i][j]=='R'){
                    sry=i;srx=j;
                }
                if(R[i][j]=='%'){
                    gry=i;grx=j;
                }
            }
        }
        solve();
    }
}


Measured memory_bytes: 28308
#include<iostream>
int gcd(int x,int y){
  if(x%y == 0){
    return y;
  }else{
    return gcd(y,x%y);
  }
}

int main()
{
  int a,b;
  std::cin >> a >> b;
  if (a < b){
    int tmp = a;
    a = b;
    b = tmp;
  }

  std::cout << gcd(a,b) << std::endl;
  return 0;
}



Measured memory_bytes: 3088
#include <iostream>
using namespace std;
int main(){
    int N;
    cin >> N;
    bool can = false;
    for(int i=1;i<=9;i++){
        if(N%i==0){
            if(N/i<10) can = true;
        }
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  string S;
  cin >> S;
  string out;
  for(int i = 0; i < S.size(); i++){
    if(i % 2 == 1){
      if(S.at(i) == 'R'){
        cout << "No";
        break;
      }
    }else{
      if(S.at(i) == 'L'){
        cout << "No";
        break;
      }
    }
    if(i == (S.size() - 1)){
      cout << "Yes";
    }
  }
}

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

using namespace std;

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

	vector <int> t(n);
	for (int i=0;i<n;i++){
		cin >> t[i];
	}
	int mx =0;
	for (int i=0;i<n-1;i++){
		if (t[i+1]-t[i] > mx){
			mx =t[i+1]-t[i];
		}
	}
	if (t[0]+k -t[n-1]>mx){
		mx = t[0]+k-t[n-1];
	}
	cout << k -mx << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>
#define ll long long

using namespace std;
typedef pair<int, int> P;

int main()
{
    ll n;
    cin >> n;
    vector<char> s;
    while (1)
    {
        if (n - 1 < 0)
        {
            break;
        }
        s.push_back((n - 1) % 26 + 'a');
        if (n / 26 == 0)
        {
            break;
        }
        n = (n - (n - 1) % 26) / 26;
    }
    for (int i = s.size() - 1; i >= 0; i--)
    {
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3576
n = int(input())
a = []

for i in range(n):
    a.append(int(input()))

Max = max(a)
if(a.count(Max)>1):
    for _ in range(n):
        print(Max)
else:
    for i in range(n):
        if(a[i]==Max):
            a[i]=0
            print(max(a))
        else:
            print(Max)

Measured memory_bytes: 12520
#include <iostream>
using namespace std;
int main(){
  int A,B,C;
  cin >> A >> B >> C;
  for(int i=1;i<=B;i++){
    if(A*i % B == C){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std;
 
int main() {
    int n, k, y, x;
    cin >> n;
    cin >> k;
    cin >> y;
    cin >> x;
    if (n < k) {
        cout << n*y;
    } else {
        cout << k*y + (n-k)*x;
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <queue>
#include <stack>
#define rep(i, s, g) for (i = s; i <= g; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1e9 + 7;

int H, W;

int d[20][20];

char map[20][20];

int bfs(P s, P g)
{
    queue<P> q;
    P dx[4] = {P(1, 0), P(0, 1), P(-1, 0), P(0, -1)};
    int i, j;

    rep(i, 0, H - 1)
    {
        rep(j, 0, W - 1)
        {
            d[i][j] = MOD;
        }
    }

    d[s.first][s.second] = 0;
    q.push(s);

    while (q.size())
    {
        P p = q.front();
        q.pop();

        if (p == g)
        {
            break;
        }

        for (int i = 0; i < 4; i++)
        {
            int nx = p.first + dx[i].first;
            int ny = p.second + dx[i].second;

            if (nx < H && ny < W && nx >= 0 && ny >= 0 && map[nx][ny] == '.' && d[nx][ny] == MOD)
            {
                q.push(P(nx, ny));

                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }

    return d[g.first][g.second];
}

int main(void)
{
    int ans = 0;
    int i, j, k, l;

    cin >> H >> W;

    rep(i, 0, H - 1)
    {
        rep(j, 0, W - 1)
        {
            cin >> map[i][j];
        }
    }

    rep(i, 0, H - 1)
    {
        rep(j, 0, W - 1)
        {
            rep(k, 0, H - 1)
            {
                rep(l, 0, W - 1)
                {
                    if (map[i][j] == '.' && map[k][l] == '.')
                    {
                        ans = max(bfs(P(i, j), P(k, l)), ans);
                    }
                }
            }
        }
    }

        cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
typedef pair<ll, l_l> lll;
ll N, M, C;
vector<l_l> paths[100];
ll dp[101][101];


void solve() {
    for(int i = 0; i < N; i++) paths[i].clear();
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < N; j++) {
            dp[i][j] = 1e18;
        }
    }
    for(int i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        paths[a].emplace_back(b, c);
    }
    dp[0][0] = 0;
    priority_queue<lll, vector<lll>, greater<lll>> que;
    que.push({0, {0, 0}});
    while(!que.empty()) {
        auto tmp = que.top();
        que.pop();
        ll pos = tmp.second.first;
        ll timer = tmp.second.second;
        if(timer > N) continue;
        for(auto tmp : paths[pos]) {
            int to = tmp.first;
            ll newcost = dp[pos][timer] + tmp.second;
            if(chmin(dp[to][timer], newcost)) {
                que.push({newcost, {to, timer}});
            }
            if(chmin(dp[to][timer+1], dp[pos][timer])) {
                que.push({dp[to][timer+1], {to, timer+1}});
            }
        }
    }
    ll ans = 1e9;
    for(ll i = 0; i <= N; i++) {
        if(dp[N-1][i] <= C) {
            chmin(ans, i);
        }
    }
    /*
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= 3; j++) {
            cerr << dp[i][j] << " ";
        }
        cerr << endl;
    }
    */
    cout << ans << endl;
}

int main() {
    //cout.precision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> M >> C) {
        if(N == 0) break;
        solve();
    }
    return 0;
}


Measured memory_bytes: 3512
import java.nio.ByteBuffer;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        long[] a = new long[n];
        long[] suma = new long[n+1];
        for(int i=0; i<n; i++){
            a[i] = sc.nextLong();
            suma[i+1] = suma[i] + a[i];
        }
        sc.close();

        int num = (n+1)*n/2;
        long[] b = new long[num];
        ArrayList<String> bs = new ArrayList<String>();
        ArrayList<boolean[]> bb = new ArrayList<boolean[]>();
        int len = 51;
        int count = 0;
        for(int i=0; i<n; i++){
            for(int j=i; j<n; j++){
                b[count] = suma[j+1] - suma[i];
                // bs.add(String.format("%" + len + "s", Long.toBinaryString(b[count])).replace(' ', '0'));
                // ByteBuffer.
                long tmp = b[count];
                boolean[] mbb = new boolean[len];
                for(int l=0; l<len; l++){
                    if(tmp % 2 == 1){
                        mbb[len-1-l] = true;
                    }
                    tmp = tmp >> 1;
                }
                bb.add(mbb);
                count++;
            }
        }

        boolean[] one = new boolean[len];
        for(int i=0; i<len; i++){
            count = 0;
            for(int j=0; j<bb.size(); j++){
                // if(bs.get(j).charAt(i) == '1') count++;
                if(bb.get(j)[i]) count++;
            }
            if(count >= k){
                one[i] = true;
                // int size = bs.size();
                int size = bb.size();
                for(int l=0; l<size; l++){
                    // if(bs.get(size-l-1).charAt(i) == '0') bs.remove(size-l-1);
                    if(!(bb.get(size-l-1)[i])) bb.remove(size-l-1);
                }
            }
        }

        long ans = 0;
        for(int i=0; i<len; i++){
            if(one[i]) ans += Math.pow(2, (len-1-i));
        }

        System.out.println(ans);

    }
}

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


int main()
{
   int n,pos;
   int sum = 0;
   string str="", x="";
   int t;
   vector<string> s;
   vector<int> a;
   cin>>n;
   for(int i=0;i<n;i++)
   {
     cin>>str>>t;
     s.push_back(str);
     a.push_back(t);
   }
  
  cin>>x;

  for(int i=0;i<n;i++)
  {
    if(s[i]==x)
    pos = i;
  }

  for(int i=(pos+1);i<n;i++)
  {
     sum = sum + a[i];
  }
   
   cout<<sum<<endl;
   return 0;
   
}


Measured memory_bytes: 256
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(13)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, A[100001], B[100000]; cin >> N;
  REP(i, N+1) cin >> A[i];
  REP(i, N) cin >> B[i];
  int ans = 0;
  REP(i, N){
    int tmp = A[i];
    A[i] = max(A[i]-B[i], 0ll);
    ans += tmp-A[i];
    B[i] -= (tmp-A[i]);
    tmp = A[i+1];
    A[i+1] = max(A[i+1]-B[i], 0ll);
    ans += tmp-A[i+1];
    B[i] -= (tmp-A[i+1]);
  }
  cout << ans << endl;
}

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

int main() {
    int n; ll k; cin >> n >> k;
    vector<vector<ll>> data(63,vector<ll>(n));
    for (int i = 0; i < n; i++) { cin >> data[0][i]; data[0][i]--; }
    for (int i = 0; i+1 < 63; i++) {
        for (int j = 0; j < n; j++) {
            data[i+1][j] = data[i][data[i][j]];
        }
    }
    int town = 0;
    for (int i = 62; i >= 0; i--) {
        if (k & 1ll<<i) town = data[i][town];
    }
    cout << town + 1 << endl;
    return 0;
}

Measured memory_bytes: 103268
#include<stdio.h>
int main()
{
    int S,h,m,s;
    scanf("%d",&S);
    if(S>=0&&S<=86400)
    {
        h=S/3600;
        S=S%3600;
        m=S/60;
        S=S%60;
        s=S;
        printf("%d:%d:%d\n",h,m,s);


    }
    return 0;
}



Measured memory_bytes: 2044