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

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  
  int ans;
  if (a + b > c * 2) {
    ans = min(x,y) * c * 2;
    if (x > y) {
      ans += min(a * (x - y), 2 * c * (x - y));
    }
    else {
      ans += min(b * (y - x), 2 * c * (y - x));
    }
  }
  else {
    ans = a * x + b * y;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    string s;cin>>s;
    REP(i,s.size()-1){
        if(s[i]==s[i+1]){
            cout<<i+1<<" "<<i+2<<endl;
            return 0;
        }
        if(i+2<s.size()&&s[i]==s[i+2]){
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }
    cout<<-1<<" "<<-1<<endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define F2(i,a,b) for(int i=a;i<(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define Debug debug("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define MN 300005
#define MM 600005
#define ll long long
#define mod 1000000007
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
int n;
int a[MN],b[MN],f[MN],g[MN];
int h[MN],nxt[MM],to[MM],tot;
inline void ins(int x,int y){nxt[++tot]=h[x];to[tot]=y;h[x]=tot;}
ll k,q;
int main(){
	scanf("%d%lld",&n,&k);
	F(i,1,n)scanf("%d",a+i);
	F(i,1,n)F(j,i+1,n)if(a[i]>a[j])++q;
	q=q*k%mod;
	F(i,1,n)F(j,1,n)if(a[i]>a[j])q=(q+k*(k-1)/2)%mod;
	printf("%lld\n",q%mod);
	return 0;
}

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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class 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<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
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;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	lnt N, K; cin >> N >> K;
	lnt ans = 0;
	for(lnt i = K; i <= N+1; i++){
		ans += (N+N-i+1)*i/2 - (i-1)*i/2 + 1;
		ans %= MOD;
	}
	cout << ans << ln;
}

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

int main()
{
  long double a, b, c;
  std::cin >> a >> b >> c;
  bool flag = (c - a - b) > 0 && (c - a - b) * (c - a - b) > 4 * a * b;
  if(flag)
  {
    std::cout << "Yes" << std::endl;
  } else
  {
    std::cout << "No" << std::endl;
  }
  
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
	
	static List<List<Integer>> graph;
	static boolean[] visited;
	static int count;
	
	public static void main(String args[]) throws Exception {

		PrintWriter pr = new PrintWriter(System.out);
		MyScanner sc = new MyScanner();

		int n = sc.nextInt();
		int m = sc.nextInt();
		
		graph = new ArrayList<>(n + 1);
		visited = new boolean[n + 1];
		
		for(int i = 0; i <= n; i++)
			graph.add(new ArrayList<>());
		
		for(int i = 0; i < m; i++) {
			
			int u = sc.nextInt();
			int v = sc.nextInt();
			graph.get(u).add(v);
			graph.get(v).add(u);
		}
		
		int ans = Integer.MIN_VALUE;
		
		for(int i = 1; i <= n; i++) {
			
			if(!visited[i]) {
				
				count = 0;
				dfs(i);
				ans = Math.max(ans, count);
			}
		}
		
		pr.print(ans);
		pr.close();
	}

	private static void dfs(int i) {
		
		visited[i] = true;
		count++;
		
		for(int neighbour : graph.get(i)) {
			
			if(!visited[neighbour])
				dfs(neighbour);
		}
		
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}

Measured memory_bytes: 97520
#include<stdio.h>
#include<stdlib.h>
#define MAX 10000

int main(){
  unsigned short *a,*b;
  int n,i,c[MAX+1];

  scanf("%d",&n);

  a=(short*)malloc((n+1)*sizeof(short));
  b=(short*)malloc((n+1)*sizeof(short));

  for(i=1;i<=n;i++) scanf("%hu",&a[i]);

  for(i=0;i<=MAX;i++){
    c[i]=0;
  }

  for(i=0;i<n;i++){
    c[a[i+1]]++;
  }

  for(i=1;i<MAX;i++){
    c[i]=c[i]+c[i-1];
  }

  for(i=n;i>0;i--){
    b[c[a[i]]]=a[i];
    c[a[i]]--;
  }

  for(i=1;i<n;i++) printf("%d ",b[i]);
  printf("%d\n",b[i]);

  free(a);
  free(b);

  return 0;
}



Measured memory_bytes: 9204
S = [str(x) for x in input()]
length = len(S)
if length%2==0:
    count = 0
    if S[0:int(length/2)] == S[int(length/2):][::-1]:
        print(0)
    else:
        for i in range(int(length/2)):
            if S[i] != S[length-1-i] :
                count+=1
        print(count)
else:
    count=0
    if S[0:int(length//2)] == S[(int(length//2)+1):][::-1]:
        print(0)
    else:
        for i in range(int(length//2)):
            if S[i] != S[length-i-1] :
                count+=1
        print(count)

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

int main()
{
  int total = 0;
  int count[4][3][10]; 
  for(int i = 0; i < 4; i++)
  {
    for(int j = 0; j < 3; j++)
  	{
    	for(int k = 0; k < 10; k++)
  		{
    		count[i][j][k] = 0;
  		}
  	}
  }
  cin >> total;
  for(int i = 0; i < total; i++)
  {
    int a, b, c, d;
    cin >> a >> b >> c>> d;
    count[a-1][b-1][c-1] += d;
  }
 
  for(int i = 0; i < 4; i++)
  {
    for(int j = 0; j < 3; j++)
  	{
    	for(int k = 0; k < 10; k++)
  		{
    		cout << " " << count[i][j][k];
  		}
      cout << endl;
  	}
    if(i < 3)
    {
      cout << "####################" << endl;
    }
  }
}


Measured memory_bytes: 3104
#include <cstdio>
#include <tr1/unordered_set>
using namespace std;
int a[50000],b[50000],o[50000];
int main(){
	int H,W,q;
	while(scanf("%d%d%d",&H,&W,&q)&&H){
		int ans = 0;
		for(int i = 0 ; i < q ; i++)
			scanf("%d%d%d",&a[i],&b[i],&o[i]);
		tr1::unordered_set<int> g[2];
		for(int i = q-1 ; i >= 0 ; i--){
			if(a[i]==0){
				if(!g[0].count(b[i]) && o[i]) ans += W - g[1].size();
				g[0].insert(b[i]);
			}else{
				if(!g[1].count(b[i]) && o[i]) ans += H - g[0].size();
				g[1].insert(b[i]);
			}
		}
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
using namespace std;
int main() {

	int a, b, c;
	cin >> a >> b;

		if ((a * b) % 2 != 0) {
			cout << "Odd" << endl;
		}
		else {
			cout << "Even" << endl;
		}

	return 0;
}

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


int main() {
    int K, N; std::cin >> K >> N;
    std::vector<int> vec;
    int i, temp;
    int sum = 0;
    int max_dist, idx = N;

    for (i = 0; i < N; i++) {
        std::cin >> temp;
        vec.push_back(temp);
    }

    max_dist = K - vec[N-1] + vec[0];

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

    for (i = 0; i < N-1; i++) {
        if (max_dist < vec[i+1] - vec[i]) {
            max_dist = vec[i+1] - vec[i];
            idx = i;
        }
    }

    if (idx == N) i = 0; else i = idx + 1;

    for (i; i < N - 1; i++) {
        sum += vec[i+1] - vec[i];
    }

    if (idx != N) {
        sum += K - vec[N-1] + vec[0];
        for (i = 0; i < idx; i++) {
            sum += vec[i+1] - vec[i];
        }
    }

    std::cout << sum;

    return 0;
}

Measured memory_bytes: 1400
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)

class UnionFind:
    def __init__(self,n):
        self.par=[i for i in range(n+1)]
        self.rank=[0]*(n+1)
        self.size=[1]*(n+1)
    def find(self,x):
        if self.par[x]==x:
            return x
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def union(self,x,y):
        px=self.find(x)
        py=self.find(y)
        if px!=py:
            if self.rank[px]==self.rank[py]:
                self.rank[px]+=1
            elif self.rank[px]<self.rank[py]:
                px,py=py,px
            self.par[py]=px
            self.size[px]+=self.size[py]
    def same_check(self,x,y):
        return self.find(x)==self.find(y)

n,m=map(int,input().split())
edges=[list(map(int,input().split())) for _ in range(m)]
ans=[n*(n-1)//2]
uf=UnionFind(n)
for i in range(m-1,0,-1):
    tmp=ans[-1]
    a,b=edges[i][0]-1,edges[i][1]-1
    if not uf.same_check(a,b):
        tmp-=uf.size[uf.find(a)]*uf.size[uf.find(b)]
    uf.union(a,b)
    ans.append(tmp)
for i in range(1,m+1):
    print(ans[-i])

Measured memory_bytes: 36404
import sys
input = sys.stdin.readline
N,A,B,C=map(int,input().split())
l=[0]*N
for i in range(N):
    l[i]=int(input())
ans=float("inf")
for i in range(1<<2*N):
    a=[]
    b=[]
    c=[]
    for j in range(0,2*N,2):
        #print(i,j)
        if 1 & i>>j:
            if 1 & i>>(j+1):
                a.append(l[j//2])
            else :
                b.append(l[j//2])
        else:
            if 1 & i>>(j+1):
                c.append(l[j//2])

    #print(a,b,c)
    if len(a)==0 or len(b)==0 or len(c)==0:
        continue
    mp=abs(sum(a)-A)+abs(sum(b)-B)+abs(sum(c)-C)+10*(len(a)+len(b)+len(c)-3)
    ans=min(ans,mp)
print(ans)


Measured memory_bytes: 48220
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <queue>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#define ll long long
#define fr(i,k,N) for(decltype(N+k) i=k; i<N;i++)
#define rep(i,N) for(decltype(N) i=0; i<N;i++)
#define ALL(v) v.begin(),v.end()
using namespace std;
template <class X> void pr(X test){cout<<test<<endl;}
template <class X> void prr(X test){for(auto it:test){cout<<it<< " ";}cout<<endl;}
template <class X> void prrr(X test){int f=0;for(auto it:test){cout<<(f++!=0?" ":"")<<it;}cout<<endl;}
template<typename X>
istream&operator>>(istream&i,vector<X>&v){for(X&x:v)i>>x;return i;}

class UF { // union find from https://github.com/kartikkukreja/blog-codes (MIT)
    // [usage]
    // auto uf = new UF(n);
    // uf->merge(l, r); // 0 <= l, r <= n-1
    // ...
public:
    int *id; // inner id
    int cnt; // number of all vartices
    int *sz; // sz[i] means size of i's set
    UF(int N)   {
        cnt = N;
        id = new int[N];
        sz = new int[N];
        for(int i=0; i<N; i++) {
            id[i] = i;
            sz[i] = 1;
        }
    }
    ~UF() {
        delete [] id;
        delete [] sz;
    }
    int find(int p) {
        int root = p;
        while (root != id[root]) root = id[root];
        while (p != root) {
            int newp = id[p];
            id[p] = root;
            p = newp;
        }
        return root;
    }
    void merge(int x, int y) {
        int i = find(x);
        int j = find(y);
        if (i == j) return;
        
        if (sz[i] < sz[j]) {
            id[i] = j;
            sz[j] += sz[i];
        } else {
            id[j] = i;
            sz[i] += sz[j];
        }
        cnt--;
    }
    bool connected(int x, int y) {
        return find(x) == find(y);
    }
    int count() {
        return cnt;
    }
};

// return 約数unordered_set 1 <= x <= n
auto divv = [](auto n) {
  unordered_set<decltype(n)> v;
  for(decltype(n) i = 1; i*i <= n; i++) {
    if(n%i == 0) {
      v.insert(i);
      if(i*i != n) v.insert(n/i);
    }
  }
  return v;
};

// check prime (and n>=2) or not
auto isPrime = [](auto n){
  if(n <= 1) return false;
  for(decltype(n) i = 2; i <= sqrt(n); ++i) {
      if(n % i == 0) {
          return false;
      }
  }
  return true;
};

// 最小公倍数
auto lcm = [](auto a, auto b){
    if(a<b) swap(a,b);
    auto r = a % b;
    auto x = a*b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return x/b;
};

// 最大公約数
auto gcd = [](auto a, auto b){
    return (a * b)/lcm(a,b);
};

int main() {
    ll n;
    cin >> n;
    vector<string> vs;
    vector<ll> vl;
    rep(i,n){
        string s;
        ll l;
        cin>>s>>l;
        vs.push_back(s);
        vl.push_back(l);
    }
    string x ;
    cin>>x;
    ll sum = 0;
    bool flg = false;
    rep(i,n) {
        if(flg) sum+=vl[i];
        else{
            if(vs[i]==x){
                flg=true;
            }
        }
    }
    pr(sum)
;}


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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 200000;
const int mo = 998244353;

char st[N + 5];
int dp[N + 5][3][3];

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%s", st);

    int s = st[0] - 'a';
    int len = strlen(st), f0 = 1, f1 = 1;

    for(int i = 1; i < len; ++i) {
        f0 &= (st[i] != st[i-1]);
        f1 &= (st[i] == st[i-1]);
        s = (s + st[i] - 'a') % 3;
    }
    if(f1) { return !puts("1"); }
    if(len == 2) return !puts("2");
    if(s == 0 && len == 3) return !puts("3");

    int ans = 1;
    for(int i = 1; i < len; ++i) ans = 3ll * ans % mo;

    for(int i = 0; i < 3; ++i) dp[0][i][i] = 1;
    for(int i = 1; i < len; ++i) {
        for(int j = 0; j < 3; ++j) {
            for(int k = 0; k < 3; ++k) if(dp[i-1][j][k]) {
                for(int l = 0; l < 3; ++l) if(l != j) {
                    (dp[i][l][(k + l) % 3] += dp[i-1][j][k]) %= mo;
                }
            }
        }
    }

    ans = ans + f0;
    for(int i = 0; i < 3; ++i) ans = (ans - dp[len-1][i][s]) % mo;

    printf("%d\n", (ans + mo) % mo);

    return 0;
}


Measured memory_bytes: 7424
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct SegTree{
	vector<ll> data;
	int size;
	SegTree(int _size){
		for(int i=1;;i<<=1)
			if(i>=_size){
				size=i;
				break;
			}
		data.assign(2*size,0);
	}
	void Update(int i,ll n){
		for(int j=size+i;j;j>>=1)
			data[j]=max(data[j],n);
	}
	ll Query(int a,int b,int i,int l,int r){
		if(b<=l || r<=a) return 0;
		if(a<=l && r<=b) return data[i];
		ll res=0;
		int m=(l+r)/2;
		if(a<m) res=max(res,Query(a,b,i*2+0,l,m));
		if(m<b) res=max(res,Query(a,b,i*2+1,m,r));
		return res;
	}
	ll Query(int a,int b){
		return Query(a,b,1,0,size);
	}
};

int main()
{
	for(int n;cin>>n;){
		vi a(n);
		rep(i,n) cin>>a[i];
		
		vi b(n);
		rep(i,n) b[a[i]-1]=i;
		
		SegTree st(n);
		ll mx=0;
		rep(i,n){
			st.Update(b[i],+st.Query(0,b[i])+i+1);
			mx=max<ll>(mx,st.Query(0,b[i]+1));
		}
		cout<<(ll)n*(n+1)/2-mx<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3908
#include <iostream>
#include <string>
#include <vector>

std::string in;
int n;
std::vector<bool> board;

std::vector<bool> v;

int main() {
	std::cin >> in;
	bool f = (in[0] == 'o') ? true : false;
	bool e = (in[in.size() - 1] == 'o')? true : false;
	char ch;
	if (!f&&!e)
		ch = 'x';
	else
		ch = 'o';
	std::cout << ch << std::endl;
	return 0;
}

Measured memory_bytes: 1176
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ll inf = 1LL << 60;
const ld pi = (acos(-1));
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int a,b; cin >> a >> b;
  cout << max({a-b,a+b,a*b}) << endl;
}

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

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

int main(){
  int h,w;
  const int max_h = 2 * 1e3;
  string s[max_h + 1];
  cin >> h >> w;
  for(int i = 0; i < h; i++) cin >> s[i];

  vector<vector<int>> h_cnt(max_h + 1, vector<int>(max_h + 1));
  vector<vector<int>> w_cnt(max_h + 1, vector<int>(max_h + 1));
  int cnt = 0;
  int r = 0;

  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cnt = 0;
      if(s[i][j] == '#') w_cnt[i][j] = 0;
      if(s[i][j] == '.'){
        r = j;
        while(s[i][j] == '.' && j < w){
          cnt ++;
          j++;
        }
        for(int k = r; k < j; k++){
          w_cnt[i][k] = cnt;
        }
      }
    }
  }
  for(int j = 0; j < w; j++){
    for(int i = 0; i < h; i++){
      cnt = 0;
      if(s[i][j] == '#') h_cnt[i][j] = 0;
      if(s[i][j] == '.'){
        r = i;
        while(s[i][j] == '.' && i < h){
          cnt ++;
          i++;
        }
        for(int k = r; k < i; k++){
          h_cnt[k][j] = cnt;
        }
      }
    }
  }

  long long ans = 0;
  pair<int, int> res;
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(h_cnt[i][j] + w_cnt[i][j] > ans){
        res = make_pair(i, j);
        ans = h_cnt[i][j] + w_cnt[i][j] - 1;
      }
    }
  }
  cout << ans << endl;


  
  // for(int i = 0; i < h; i++){
  //   for(int j = 0; j < w; j++){
  //     cout << w_cnt[i][j];
  //   }
  //   cout << endl;
  // }

  // for(int i = 0; i < h; i++){
  //   for(int j = 0; j < w; j++){
  //     cout << h_cnt[i][j];
  //   }
  //   cout << endl;
  // }



  return 0;
}

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

typedef long long ll;
typedef long double ld;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vstr;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define asd cout << "ok" << endl;

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(it, m) for(auto it = m.begin(); it it!= m.end(); it++)

const char nl = '\n';
const int MOD = 1e9 +7;
const ll INF = 1e19;
const ld PI = acos((ld)-1);
const int MX = 2e5 + 5;

int main(){

  ios_base::sync_with_stdio(0); cin.tie(0);
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vi v1, v2;
  for(int i = 0; i < n; i++){
    int x; cin >> x;
    v1.pb(x);
  }
  for(int i = 0; i < m; i++){
    int x; cin >> x;
    v2.pb(x);
  }
  v1.pb(x);
  v2.pb(y);
  sort(all(v1));
  sort(all(v2));
  if(v1[v1.size()-1] < v2[0])
  {
    cout << "No War" << nl;
    return 0;
  }
  cout << "War" << nl;







  return 0;
}



Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String[] strArray = br.readLine().split(" ");
        int a = Integer.parseInt(strArray[0]);
        int b = Integer.parseInt(strArray[1]);

        int d = a / b;
        int r = a % b;
        String f = String.format("%.5f", 1.0 * a / b);

        System.out.println(d + " " + r + " " + f);
	}
}

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

int main() {

    string s, hitachi = ""; cin >> s;

    for(int i=0; i<5; i++){
        hitachi += "hi";
        if(hitachi == s) {
            cout << "Yes";
            return 0;
        } 
    }
    cout << "No";

}

Measured memory_bytes: 256
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,len=0,n0001,n01,n10,ans=0,res,ach10,ach01;
pii a[100010],b[100010];
vector <pair <LL,pii> > v;
vector <pii> ch11,ch00;

void chmin(int i,int j)
{
	if(i>=ch11.size()||j>=ch00.size()||ch11[i].se==ch00[j].se) return;
	ans=min(ans,res+ch11[i].fi+ch00[j].fi);
}

int main()
{
	cin>>n;
	rep(i,n)
	{
		cin>>a[i].fi>>a[i].se;
		v.pb({a[i].fi,{i,0}});
		v.pb({a[i].se,{i,1}});
	}
	sort(v.begin(),v.end());
	rep(i,n)
	{
		ans+=v[i].fi;
		if(v[i].se.se==0) b[v[i].se.fi].fi=1;
		else b[v[i].se.fi].se=1;
	}
	rep(i,n)
	{
		if((b[i].fi==0&&b[i].se==0)||(b[i].fi==1&&b[i].se==1)) n0001++;else
		if(b[i].fi==0&&b[i].se==1) n01++;else
		n10++;
	}
	if(n0001>0||(n0001==0&&(n01==0||n10==0)))
	{
		cout<<ans<<endl;
		rt0;
	}
	res=ans;
	ans=1e18;
	rep(i,n)
	{
		if(b[i].fi==1&b[i].se==0)
		{
			ch11.pb({a[i].se,i});
			ch00.pb({-a[i].fi,i});
			ach01+=a[i].se-a[i].fi;
		}
		else
		{
			ch11.pb({a[i].fi,i});
			ch00.pb({-a[i].se,i});
			ach10+=a[i].fi-a[i].se;
		}
	}
	sort(ch11.begin(),ch11.end());
	sort(ch00.begin(),ch00.end());
	chmin(0,0);
	chmin(0,1);
	chmin(1,0);
	ans=min(ans,min(res+ach01,res+ach10));
	cout<<ans<<endl;
	rt0;
}

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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
    string s;
    cin >> s;
    if(s[0] == s[1] || s[0] == s[2] || s[1] == s[2])
    {
        if(s[0] == s[1] && s[1] != s[2])
        {
            cout << "Yes" << endl;
        }
        else if(s[0] == s[2] && s[0] != s[1])
        {
            cout << "Yes" << endl;
        }
        else if(s[1] == s[2] && s[0] != s[1])
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    ll n;
    cin >> n;
    vector<ll> a(n + 2);
    a[0] = 0;
    rep(i,n) cin >> a[i+1];

    a[n+1] = 0;

    ll sum;
    sum = abs(a[0]);

    rep1(i,n+2){
        sum = sum + abs(a[i] - a[i-1]);
    }

    ll tmp;

    rep1(i,n+1){
        tmp = sum;
        cout << tmp - abs(a[i] - a[i - 1]) - abs(a[i] - a[i+1]) + abs(a[i - 1] - a[i+1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 2048
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

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

    li x;
    cin >> x;
    
    li ans = 0;
    ans += (x / 500) * 1000;
    x %= 500;
    ans += (x / 5) * 5;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int K = scan.nextInt();
			int S = scan.nextInt();
			
			
			
			int count = 0;
			
			for(int i = 0;i<=K;i++) {
				for(int j = 0;j<=K;j++) {
					if(S-i-j>=0&&S-i-j<=K)count++;	
				}
			}
			
			
			System.out.println(count);
			
			
			
		}
		
		
	}
	
	
	
	
	
		

}


Measured memory_bytes: 21844
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
//using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;
using static System.Linq.Enumerable;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        int A = cin.nextint, B = cin.nextint, C = cin.nextint, D = cin.nextint, E = cin.nextint, F = cin.nextint;


        double max = -1;
        string ans = "";
        for (int i = 0; i <= 30; i++)//Aをi回
        {
            for (int j = 0; j <= 30; j++)//Bをj回
            {
                if (i == 0 && j == 0) continue;
                int weight = A * 100 * i + B * 100 * j;
                if (weight > F) continue;
                int to = E * (A * i + B * j);

  
                for (int k = 0; k <= to / C; k++)
                {
                    for (int l = 0; l <= to / D; l++)
                    {
                        int w = C * k + D * l;
                        if (w <= to && weight + w <= F)
                        {
 
                            double nou = (double)(100 * w) / (w + weight);
                            if (max < nou)
                            {
                                max = nou;
                                ans = $"{weight + w} {w}";
                            }
                        }
                    }
                }
            }
        }
        WriteLine(ans);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13264
N = int(input())
ans = 0
seq = ""
data = list(map(int, input().split()))
for i in range(N):
    seq += "1" if data[i] == i + 1 else "0"
while seq:
    if seq[0] == "0":
        seq = seq[1:]
    else:
        try:
            if seq[1] == "1":
                ans += 1
                seq = seq[2:]
            else:
                ans += 1
                seq = seq[1:]
        except IndexError:
            ans += 1
            seq = seq[1:]
print(ans)


Measured memory_bytes: 14008
import java.util.*;

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

        int N = sc.nextInt();
        String S1 = sc.next();
        char[] S = S1.toCharArray();

        long num_r = 0, num_g = 0, num_b = 0;

        for (int i = 0; i < N; i++) {
            if (S[i] == 'R') {
                num_r++;
            } else if (S[i] == 'G') {
                num_g++;
            } else {
                num_b++;
            }
        }

        long all = num_r * num_g * num_b;

        for (int j = 0; j < N; j++) {
            for (int i = 0; i < j; i++) {
                int d = j - i;

                if (j + d >= N || S[i] == S[j]) {
                    continue;
                }

                if (S[i] != S[j + d] && S[j] != S[j + d]) {
                    all--;
                }
            }
        }

        System.out.println(all);
    }
}


Measured memory_bytes: 36260
// C.

#include <iostream>
#include <sstream>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char* argv[]) {
	LL a;
	double b;
	cin >> a >> b;
	LL ans = a * (LL)round(b * 100) / 100;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;
 
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define emb emplace_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <typename T> inline T range(T l, T r) {
    return uniform_int_distribution<T>(l, r)(rng);
}
 
inline void setin(string s) {
    freopen(s.c_str(), "r", stdin);
}
 
inline void setout(string s) {
    freopen(s.c_str(), "w", stdout);
}
 
template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

const int mod = 1e9 + 7;
const int inf = 2e9 + 5;
const int N = 1e4 + 15;
int n;

int temp[N], dp[N];

inline int add(int a, int b) {
    a += b;
    if(a >= mod)
        a -= mod;
    return a;
}

inline int mt(int a, int b) {
    return 1ll * a * b % mod;
}

inline void add_t(int &a, int b) {
    a = add(a, b);
}

inline int binpow(int n, int k) {
    int res = 1;
    while(k) {
        if(k & 1)
            res = mt(res, n);
        k >>= 1;
        n = mt(n, n);
    }
    return res;
}

string s;

main() {
    ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
    cin >> n >> s;
    dp[0] = 1;
    for(int j = 1; j <= n; ++j) {
        memcpy(temp, dp, sizeof(temp));
        memset(dp, 0, sizeof(dp));
        for(int i = 0; i <= n; ++i) {
            add_t(dp[max(0, i - 1)], temp[i]);
            add_t(dp[i + 1], add(temp[i], temp[i]));
        }
    }
    cout << mt(dp[s.size()], binpow(binpow(2, s.size()), mod - 2)) << endl;
    return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <limits>
#include <iomanip>
#include <bitset>

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------
const int M = 80*160+10;
const int M2 = M * 2;
typedef bitset<M2> bs;

bs table[6410] = {};
int cost[6410] = {};
int h, w;

void calcCost() {
    table[0][M+cost[0]] = 1;
    table[0][M-cost[0]] = 1;
    rep(i, h) {
        rep(j, w) {
            const int now_index = i * w + j;
            if (i) {
                const int prev_index = (i - 1) * w + j;
                const bs& prev = table[prev_index];
                table[now_index] |= prev << abs(cost[now_index]);
                table[now_index] |= prev >> abs(cost[now_index]);
            }
            if (j) {
                const int prev_index = i * w + j - 1;
                const bs& prev = table[prev_index];
                table[now_index] |= prev << abs(cost[now_index]);
                table[now_index] |= prev >> abs(cost[now_index]);
            }
        }
    }
}


int main() {
    cin >> h >> w;
    rep(i, h) {
        rep(j, w) {
            cin >> cost[i * w + j];
        }
    }
    rep(i, h) {
        rep(j, w) {
            int temp;
            cin >> temp;
            cost[i * w + j] -=temp;
        }
    }

    calcCost();
    int min_ans = 10000000;
    rep(i, M2) {
        if (table[h*w-1][i]) {
            min_ans = min(abs(i - M), min_ans);
        }
    }
    cout << min_ans << endl;
    return 0;
}


Measured memory_bytes: 20352
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

#define rep(i, n) for (i = 0; i < n; i++)
#define P pair<int, int>

int main()
{
  ll a;
  double b;
  cin >> a >> b;
  ll c = round(b * 100);
  cout << (a * c) / 100 << endl;
}


Measured memory_bytes: 3780
#include <stdio.h>
int main(void)
{
   int a,b;
   scanf("%d",&a);
   scanf("%d",&b);
   if(a<b){
        printf("a < b\n");
   }
   else if(a>b){
        printf("a > b\n");
   }
   else{
        printf("a == b\n");
   }
   return 0;
}


Measured memory_bytes: 2028
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
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; }
using ll = long long;
const ll MOD = 1e9+7; int INF=INT_MAX; ll LLINF = 1LL << 60;
const vector<int> d8x = {1, 0, -1, 0, 1, -1, -1, 1}; vector<int> d8y = {0, 1, 0, -1, 1, 1, -1, -1};
const vector<int> d4x = {1, 0, -1, 0}; vector<int> d4y = {0, 1, 0, -1};

//

int main(){
    int x,a; cin>>x>>a;
    if(x<a) cout<<0<<endl;
    else cout<<10<<endl;
}

Measured memory_bytes: 256
#define tasknames ""
#include <iostream>
#include <stdio.h>
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e2 + 2;
ll n;

void Read(){
    cin >> n;
}

ll mu(ll x){
    return x * x * x * x * x;
}

void Solve(){
    for(ll i = -1000; i < 1001; ++i)
        for(ll j = -1000; j < 1001; ++j)
            if(mu(i) - mu(j) == n){
                cout << i << " " << j;
                return;
            }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); if(fopen(tasknames".INP", "r"))
    freopen(tasknames".INP","r",stdin),
    freopen(tasknames".OUT","w",stdout);
    Read();
    Solve();
}


Measured memory_bytes: 3652
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define printyn(test) printf(test ? "YES\n" : "NO\n");
#define all(x) (x).begin(), (x).end()

using ll = long long;

#include <stdio.h>
#include <algorithm>
//#include <vector>

using namespace std;


int main() {

	int n, k, x, y;
	scanf("%d%d%d%d", &n, &k, &x, &y);
	printf("%d\n", n > k ? x * k + y * (n - k): x * n);

	return 0;
}

Measured memory_bytes: 128
N = gets.to_i
array = gets.chomp.split(" ").map(&:to_i)

ret = 0
skip = false
array.each_with_index do |a, index|
    if skip
        skip = false
        next
    end

    if a == index+1
        skip = true
        ret += 1
    end
end
puts ret


Measured memory_bytes: 8708
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;

    int dif=abs(a-b);
    if(dif%2==0)
    {
        cout<<"Alice"<<endl;
    }
    else
    {
        cout<<"Borys"<<endl;
    }


}


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

class Vector
{
    internal decimal X { get; set; }
    internal decimal Y { get; set; }
}
class Pg
{
    static void Main()
    {
        string line;
        while ((line = Console.ReadLine()) != null)
        {
            var op = new Operate();
            var n =line.Split().Select(decimal.Parse).ToArray();
            var A = new Vector { X = n[0], Y = n[1] };
            var B = new Vector { X = n[2], Y = n[3] };
            var C = new Vector { X = n[4], Y = n[5] };
            var D = new Vector { X = n[6], Y = n[7] };
            var AB = op.MkLine(A, B);
            var CD = op.MkLine(C, D);
            Console.WriteLine((AB.X * CD.X) + (AB.Y * CD.Y) == 0 ? "YES" : "NO");
        }
    }
}
class Operate
{
    internal Vector MkLine(Vector A, Vector B)
    {
        return new Vector
        {
            X = A.X - B.X,
            Y = A.Y - B.Y
        };
    }
}


Measured memory_bytes: 18432
#include<stdio.h>

int n, A[50];

int solve(int i, int m) {
  if (m == 0) return 1;
  if (i >= n) return 0;
  int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
  return res;
}

int main() {
  int q, M, i;

  scanf("%d",&n);
  for ( i = 0; i < n; i++) scanf("%d", &A[i]);
  scanf("%d", &q);
  for ( i = 0; i < q; i++) {
    scanf("%d",&M);
    if (solve(0, M)) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}



Measured memory_bytes: 2104
#include <cstdio>
using namespace std;
struct Edge{
	int to, w, next;
}e[200007];
int head[100008], col[100008], vis[100008], q[100008], cnt[3], en;
int fastin(){
	register int i; register char ch;
	while (ch = getchar(), ch < '0' || ch > '9');
	i = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9') i = i * 10 + ch - '0';
	return i;
}
int main(){
	register int n, m, i, j, u, v, qh, qt, ecnt, marken;
	register long long ans;
	n = fastin(), m = fastin();
	for (en = i = 1; i <= m; ++i) {
		u = fastin(), v = fastin();
		e[++en] = (Edge){v, 1, head[u]};
		head[u] = en;
		e[++en] = (Edge){u, 2, head[v]};
		head[v] = en;
	}
	ans = 0;
	for (i = 1; i <= n; ++i) if (vis[i] == 0) {
		marken = ecnt = cnt[0] = cnt[1] = cnt[2] = 0;
		q[qh = qt = 0] = i;
		vis[i] = 1;
		while (qh <= qt) {
			u = q[qh];
			++qh;
			++cnt[col[u]];
			for (j = head[u]; j; j = e[j].next) {
				++ecnt;
				if (vis[v = e[j].to]) {
					if (col[v] != (col[u] + e[j].w) % 3) marken = 1;
				}
				else {
					vis[v] = 1;
					col[v] = (col[u] + e[j].w) % 3;
					q[++qt] = v;
				}
			}
		}
		//fprintf(stderr, "%d %d %d %d %d\n", i, marken, cnt[0], cnt[1], cnt[2]);
		if (marken) ans += 1ll * (cnt[0] + cnt[1] + cnt[2]) * (cnt[0] + cnt[1] + cnt[2]);
		else if (cnt[0] && cnt[1] && cnt[2]) ans += 1ll * cnt[0] * cnt[1] + 1ll * cnt[1] * cnt[2] + 1ll * cnt[2] * cnt[0];
		else ans += ecnt >> 1;
	}
	printf("%lld", ans);
	return 0;
}

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

int main() {
  int K, N;
  cin >> K >> N;
  int mx = 0;

  int before;
  cin >> before;
  int first = before;
  int tmp;
  rep(i,N-1) {
    cin >> tmp;
    if (mx < (tmp - before)) {
      mx = (tmp - before);
    }
    before = tmp;
  }
  if (mx < (first + K - tmp)) mx = first + K - tmp;

  cout << K - mx << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<queue>
#include<functional>
#include<algorithm>
using namespace std;

const int MAX_GROUP = 100;
int waitTime[MAX_GROUP];


void Init()
{
	int firstTime[MAX_GROUP];
	const int SEAT_NUM = 17;
	bool isSitSeat[SEAT_NUM] = {false};
	typedef pair<int,int> PII;
	queue<PII> line;	//<inTime,personCount>
	priority_queue<PII,vector<PII>,greater<PII> > seat;	//<endTime,seatNum>

	int i,j,c,t,n;

	for(i=0;i<MAX_GROUP;++i)
		line.push(make_pair(i*5, (i%5==1?5:2))),firstTime[i]=i*5;

	bool canSit = false;

	//±ÌöxÈçAªV~[gµÄàÔÉ¤©
	for(t=0,n=0; !line.empty(); )
	{
		while(!seat.empty() && t >= seat.top().first)
			isSitSeat[seat.top().second] = false, seat.pop();

		canSit = false;

		if(t>=line.front().first)
		{
			//SõÀêÜ·©H
			for(c=0,i=0; i < SEAT_NUM; ++i)
			{
				if(isSitSeat[i]) c=0;
				else if(++c >= line.front().second)
				{
					//Àêéæ¤Å·
					for(j=0;j<line.front().second;++j)
					{
						isSitSeat[i-j] = true;
						seat.push(make_pair(t+ 17*(n%2)+3*(n%3)+19, i-j));
					}
					waitTime[n] = t-line.front().first;
					line.pop();
					++n;
					canSit = true;
					break;
				}
			}
		}
		//êxÉO[vÀé±Æà è
		if(!canSit)
			++t;
	}
}

int main(void)
{
	Init();
	int i;
	while(scanf("%d",&i)>0)
		printf("%d\n",waitTime[i]);
	return 0;
}

Measured memory_bytes: 0
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7


N, K, Q = rl()
A = []
for i in range(Q):
	a = ri()
	A.append(a)

scores = [0] * N
for a in A:
	idx = a-1
	scores[idx] += 1

for s in scores:
	if K > Q-s:
		print('Yes')
	else:
		print('No')


Measured memory_bytes: 49500
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  for(int i = (s.size()-1)/2; i>0; i--){
    if(s.substr(0,i) == s.substr(i,i)){
      cout << 2*i << endl;
      return 0;
    }
  }
}

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

int parent(int x, vector<int> &par){
  if(par.at(x) == x) return x;
  return par.at(x) = parent(par.at(x), par);
}

void join(int u, int v, vector<int> &par){
  int pu = parent(u, par);
  int pv = parent(v, par);
  if(pu == pv) return;
  par.at(pu) = pv;
}

int main() {
  int n, m; cin >> n >> m;
  
  vector<int> par(n);
  
  for(int i = 0; i < n; i++){
    par.at(i) = i;
  }
  
  for(int i = 0; i < m; i ++){
    int x, y, z; cin >> x >> y >> z;
    join(x-1, y-1, par);
  }
  
  int ans = 0;
  for(int i = 0; i < n; i ++){
    if (par.at(i) == i) ans++;
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
using namespace std;

int main(){
  long long  n, y;

  cin>>n>>y;
  bool f = false;
  rep(i,n+1){
    rep(j,n-i+1){
      rep(k,n-i-j+1){
        if(i * 10000 + j * 5000 + k * 1000 == y && n == i + j + k){
          f = true;
          cout<<i<<' '<<j<<' '<<k<<endl;
        }
      }
      if(f)break;
    }
    if(f)break;
  }
  if(!f)cout<<"-1 -1 -1"<<endl;
}

Measured memory_bytes: 256
def insertion_sort(array)
  1.upto @N-1 do |i|
    v = array[i]
    j = i - 1
    while j >= 0 && array[j] > v do
      array[j+1] = array[j]
      j -= 1
    end
    array[j+1] = v

    puts array.join(" ")
  end
end


@N = gets.to_i
array = gets.split(" ").map{|x| x.to_i}

puts array.join(" ")
insertion_sort array



Measured memory_bytes: 6888
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;
struct Edge{ll from, to, cost;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

llvec p;
struct rt{
  ll root;
  ll count;
};

rt root(ll a){
  ll tmp=0;
  ll atmp=a;
  while(atmp!=p[atmp]){
    atmp=p[atmp];
    tmp++;
  }
  rt t;
  t.root=atmp;
  t.count = tmp;
  return t;
}

void con(ll a, ll b){
  rt art = root(a);
  rt brt = root(b);
  if(art.count>brt.count)swap(art,brt);
  p[art.root]=brt.root;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N, M;
  cin >> N >> M;
  p.resize(N);
  rep(i, N)p[i]=i;
  rep(i, M){
    ll a, b, c;
    cin>>a>>b>>c;
    a--;b--;
    con(a,b);
  }
  set<ll> ans;
  rep(i, N){
    ans.insert(root(i).root);
  }
  cout << ans.size();
  return 0;
}


Measured memory_bytes: 5760
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    int n, k; cin >> n >> k;
    vector<int> x(n);
    rep(i, n) cin >> x[i];

    int ans = 0;
    for (int e: x) {
        ans += min(e, k - e) * 2;
    }
    cout << ans << endl;
}


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

int main()
{
	int N,Y,x,y;
	int z;
	cin>>N>>Y;
	if(Y%1000!=0)
	cout<<"-1 -1 -1";
	else
	{
		for(x=0 ; x <= N ; x++)
			for(y=0 ; y <= N ; y++)
			{
				z=N-x-y;
				if(z>=0 && z*1000+y*5000+x*10000==Y)	
				{
					cout<< x << ' ' << y << ' ' << z ;
					return 0;
				}
			}
	}
	cout<<"-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256