akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define JN ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#define mod 1000000007

#define pb push_back
#define mp make_pair

using namespace std;
typedef unsigned long long int ull;
typedef long long int          ll;




int main()
{

	int n;
	cin >> n;
	int frog[n+2], cost[n+2];

	for(int i=1; i<=n; i++)
		cin >> cost[i];

	frog[1] =0;
	frog[2] = abs(cost[2]-cost[1]);
	for(int i=3; i<=n; i++)
	{

		frog[i] = min(frog[i-1]+abs(cost[i]-cost[i-1]), frog[i-2]+abs(cost[i]-cost[i-2]));
	}
	cout << frog[n] << endl;
	return 0;
}

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

int main(){
  int i,j,k,n,m,sum=0,check=0,d,f,loop_count;
  char a[51][51];
  char b[51][51];

  cin>>n>>m;

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      cin>>a[i][j];
    }
  }

  for(i=0;i<m;i++){
    for(j=0;j<m;j++){
      cin>>b[i][j];
    }
  }

  d=0;
  f=0;
  loop_count=(n-m+1)*(n-m+1);
  for(i=0;i<loop_count;i++){
    for(j=0;j<m;j++){
      for(k=0;k<m;k++){
	if(a[j+d][k+f]==b[j][k]) sum+=1;
	
      }
    }
     if(sum==m*m) check=1;
      sum=0;
    f++;
    if( (f+m)==n){
      f=0;
      d+=1;
    }
  }
  if(check==1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;


  return 0;
}


Measured memory_bytes: 256
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n, m, a;
    int[] x, h, p, q;
    int i, j, tmp;

    for(;;){
      n = sc.nextInt();
      m = sc.nextInt();
      a = sc.nextInt();
      if(n == 0)break;

      x = new int[n];
      h = new int[m];
      p = new int[m];
      q = new int[m];

      for(i = 0;i < n;i++)x[i] = i + 1;
      for(i = 0;i < m;i++){
        h[i] = sc.nextInt();
        p[i] = sc.nextInt();
        q[i] = sc.nextInt();
      }

      quicksort(h, p, q, 0, m);
      for(i = 0;i < m;i++){
        tmp = x[p[i] - 1]; x[p[i] - 1] = x[q[i] - 1]; x[q[i] - 1] = tmp;
      }

      for(i = 0;i < n;i++){
        if(a - 1 == x[i] - 1)System.out.println(i + 1);
      }
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }

  private static void quicksort(int[] h, int[] p, int[] q, int l, int r){
    int mid;
    if(l < r){
      mid = partition(h, p, q, l, r);
      quicksort(h, p, q, l, mid);
      quicksort(h, p, q, mid + 1, r);
    }
    return;
  }
  private static int partition(int[] h, int[] p, int[] q, int t, int s){
    int k, j, tmp;
    for(k = t - 1;;){
      for(j = k + 1;j < s;j++){
        if(h[j] >= h[s - 1]){
          k++;
          tmp = h[k];h[k] = h[j];h[j] = tmp;
          tmp = p[k];p[k] = p[j];p[j] = tmp;
          tmp = q[k];q[k] = q[j];q[j] = tmp;
          if(j == s - 1)return k;
          break;
        }
      }
    }

  }

}

Measured memory_bytes: 62924
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n, m;
    cin>>n>>m;
    vector<pair<long long,long long>> v1;
    vector<pair<long long,long long>> v2;

    for(long long i=0; i<n; i++){
        long long a, b;
        cin>>a>>b;
        v1.push_back({a,b});
    }

    for(long long i=0; i<m; i++){
        long long a, b;
        cin>>a>>b;
        v2.push_back({a, b});
    }

    for(long long i=0; i<v1.size(); i++){
        long long answer=100000000000, mini;
        for(long long j=0; j<v2.size(); j++){
            if(abs(v1[i].first-v2[j].first)+ abs(v1[i].second-v2[j].second)<answer){
                answer = abs(v1[i].first-v2[j].first)+ abs(v1[i].second-v2[j].second);
                mini = j+1;
            }
        }
        cout<<mini<<endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
int n,cc,c[50][50],d[1000][1000];
int a1[300000],a2[300000],a3[300000],b1[100],b2[100],b3[100];
int main()
{
scanf("%d%d",&n,&cc);
for (int i=1;i<=cc;i++)
    for (int j=1;j<=cc;j++)
scanf("%d",&c[i][j]);
int o1=0;
int o2=0;
int o3=0;
for (int i=1;i<=n;i++)
    for (int j=1;j<=n;j++)
{
    scanf("%d",&d[i][j]);
    if ((i+j)%3==0) {o1++;a1[o1]=d[i][j];}
    if ((i+j)%3==1) {o2++;a2[o2]=d[i][j];}
    if ((i+j)%3==2) {o3++; a3[o3]=d[i][j];}
}
for (int i=1;i<=cc;i++)
{
    int sum=0;
    for (int j=1;j<=o1;j++)
    sum+=c[a1[j]][i];
    b1[i]=sum;
    sum=0;
    for (int j=1;j<=o2;j++)
    sum+=c[a2[j]][i];
    b2[i]=sum;
    sum=0;
    for (int j=1;j<=o3;j++)
    sum+=c[a3[j]][i];
    b3[i]=sum;
}

int min1=1000000000;
for (int i=1;i<=cc;i++)
    for (int j=1;j<=cc;j++)
    for (int k=1;k<=cc;k++)
    if (i!=j&&i!=k&&j!=k)
{
    int ans=b1[i]+b2[j]+b3[k];
    if (ans<min1) min1=ans;
}
printf("%d",min1);
    return(0);
}


Measured memory_bytes: 4992
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double x1=scanner.nextDouble();
        double y1=scanner.nextDouble();
        double x2=scanner.nextDouble();
        double y2=scanner.nextDouble();
        
        double deltax=(x2-x1)*(x2-x1);
        double deltay=(y2-y1)*(y2-y1);
        
        double kyori=Math.sqrt(deltax+deltay);
        System.out.println(kyori);
    }
}

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

using namespace std;


string str;

bool guide0, guide1;

int main () {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> str;
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == 'A')
			guide0 = 1;
		else
			guide1 = 1;
	}
	if (guide0 == guide1)
		cout << "Yes";
	else
		cout << "No";
}


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

int main(){
while(1){
	int a[10][10000],r,c,b[11],ans=0;
	fill(b,b+11,0);
	scanf("%d%d",&r,&c);
if(r==0&&c==0)break;
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			scanf("%d",&a[i][j]);
		}
	}
	while(1){
		int d=0;
		for(int j=0;j<c;j++){
			int e=0;
			for(int i=0;i<r;i++){
				if((a[i][j]+b[i])%2==0)e++;
			}
			d+=max(e,r-e);
		}
		if(d>ans)ans=d;
		b[0]++;
		for(int i=0;i<10;i++){
			if(b[i]==2){
				b[i]=0;
				b[i+1]++;
			}
		}
		if(b[10]==1)break;
	}
	printf("%d\n",ans);
}
}

Measured memory_bytes: 1560
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int matrix[][] = new int[n+1][n+1];
		for (int i = 0; i < n; i++) {
			int v = scanner.nextInt();
			int k = scanner.nextInt();
			for (int j = 0; j < k; j++) {
				int vn = scanner.nextInt();
				matrix[v][vn] = 1;
			}
		}
		for (int i = 1; i < matrix.length; i++) {
			for (int j = 1; j < matrix.length; j++) {
				System.out.print(matrix[i][j]);
				if(j<matrix.length-1)System.out.print(" ");
			}
System.out.println();
		}
		scanner.close();

	}

}

Measured memory_bytes: 34632
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if n % 2 == 0:
        dp = [[-10**18]*2, [-10**18]*2]
        dp[0][0] = 0
        for i in range(n):
            dp2 = [[-10**18]*2, [-10**18]*2]
            # 使う場合
            dp2[1][0] = max(dp2[1][0], dp[0][0]+a[i])
            dp2[1][1] = max(dp2[1][1], dp[0][1]+a[i])
            # 使わない場合
            dp2[0][1] = max(dp2[0][1], dp[0][0])
            # 更新
            dp2[0][0] = max(dp2[0][0], dp[1][0])
            dp2[0][1] = max(dp2[0][1], dp[1][1])
            dp = dp2
        print(max(dp[1][1], dp[0][0]))
        return
    dp = [[-10**18]*3, [-10**18]*3]
    dp[0][0] = 0
    for i in range(n):
        # 使う場合
        dp2 = [[-10**18]*3, [-10**18]*3]
        dp2[1][0] = max(dp2[1][0], dp[0][0]+a[i])
        dp2[1][1] = max(dp2[1][1], dp[0][1]+a[i])
        dp2[1][2] = max(dp2[1][2], dp[0][2]+a[i])
        # 使わない場合
        dp2[0][1] = max(dp2[0][1], dp[0][0])
        dp2[0][2] = max(dp2[0][2], dp[0][1])
        # 更新
        dp2[0][0] = max(dp2[0][0], dp[1][0])
        dp2[0][1] = max(dp2[0][1], dp[1][1])
        dp2[0][2] = max(dp2[0][2], dp[1][2])
        dp = dp2
    print(max(dp[1][2], dp[0][1]))


main()


Measured memory_bytes: 31996
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define int long long
#define num(a) a-'0'
#define charr(a) (a - 'A' + 1)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define bin1(a) __builtin_popcount(a)
#define debug(x) cerr<<"["<<#x<<":"<<x<<"] "
#define debug2(a,b) debug(a);debug(b)
#define debug3(a,b,c) debug2(a,b);debug(c)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/(__gcd(a,b))
#define print(arr) for(auto it = arr.begin();it < arr.end();it ++){cout << *it << " ";}cout << ln;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define all(a) (a).begin(), (a).end()
#define vi vector<long long>
#define v vector
#define p pair
#define pii p<int,int>
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long double ld;
typedef double d;
using namespace std;
using namespace __gnu_pbds;
int modF=1e9+7;
int inf=1e18+5;

/*OUTPUT

*/

void solve(){
	string s;
	cin>>s;
	vi fr(26,0);
	rep(i,0,4){
		fr[s[i]-'A']++;
	}
	bool pos=true;
	rep(i,0,26){
		if(fr[i]!=0 && fr[i]!=2){
			pos=false;
		}
	}
	if(pos){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}

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

Measured memory_bytes: 3576
//07-3 最古の遺跡
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cstdlib>
#include<cassert>
#include<random>
#include<set>
using namespace std;
int main(){
	while(true){
		int n;
		cin >> n;
		if(n == 0) break;
		vector<pair<int,int>> xy;
		set<pair<int,int>> xys;
		for(int i=0; i<n; i++){
			int x,y;
			cin >> x >> y;
			xy.push_back(make_pair(x,y));
			xys.insert(make_pair(x,y));
		}

		long long max_menseki = 0;

		for(int i=0; i<n; i++){
			int ix = xy.at(i).first;
			int iy = xy.at(i).second;
			for(int j=0; j<n; j++){
				if(i != j){
					int jx = xy.at(j).first;
					int jy = xy.at(j).second;
					
					int sa_x = ix - jx;
					int sa_y = iy - jy;
	
					int x1 = jx + sa_y;
					int y1 = jy - sa_x;
					int x2 = ix + sa_y;
					int y2 = iy - sa_x;

					long long menseki = sa_x*sa_x + sa_y*sa_y;
					if(menseki>max_menseki){
						if(xys.count(make_pair(x1,y1))==1 && xys.count(make_pair(x2,y2))==1){
							max_menseki = menseki;
						}
					}
				}
			}
		}
		cout << max_menseki << endl;
	}
    return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  string correct = "CODEFESTIVAL2016";
  int ans = 0;
  for (int i = 0; i < 16; i++) {
    if (S.at(i) != correct.at(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main(){
  ll a, b, c; cin >> a >> b >> c;
  string ans="No";
  
  if(4*a*b<(c-a-b)*(c-a-b) && 0<(c-a-b)) ans = "Yes";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int arr[200005];
map<int,int> cnt;
int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
		cnt[arr[i]]++;
	}
	sort(arr,arr+n);
	for (int i=n-1;i>=0;i--)
	{
		if (!cnt[arr[i]])
		continue;
		cnt[arr[i]]--;
		int pw=1;
		while (pw<=arr[i])
		pw*=2;
		if (cnt[pw-arr[i]])
		{
			cnt[pw-arr[i]]--;
			ans++;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 19712
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pddd(n, m, z) printf("%d %d %d\n", n, m, z)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define plddd(n, m, z) printf("%lld %lld %lld\n", n, m, z)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ce i == n ? '\n' : ' '
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int ret = 0, sgn = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			sgn = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		ret = ret * 10 + ch - '0';
		ch = getchar();
	}
	return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
	if (a > 9)
		Out(a / 10);
	putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = x * x % mod, n >>= 1;
	}
	return res;
}

const int N = 2e5 + 5;
int a[N], b[N];
int n, k, c;
int pos;
string s;
int main()
{
	sddd(n, k, c);
	cin >> s;
	rep(i, 0, n - 1)
	{
		if (s[i] == 'o')
		{
			a[pos++] = i;
			i += c;
		}
	}
	pos = k - 1;
	for (int i = n - 1; i >= 0 && pos >= 0; i--)
	{
		if (s[i] == 'o')
		{
			b[pos--] = i;
			i -= c;
		}
	}
	rep(i, 0, k - 1)
	{
		if (a[i] == b[i])
			pd(a[i] + 1);
	}
	return 0;
}


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

int main(void) {
  string t[3] = {"the", "this", "that"};
  string str;
  
  while(getline(cin, str)) {
    while(1) {
      for(int i=0; i<str.length(); i++) if(str[i] != ' ' && str[i] != '.') str[i] = (str[i]-'a' + 1)%26 + 'a';
      for(int i=0; i<3; i++) if(str.find(t[i])!=string::npos) goto fi;
    }
  fi:
    cout << str << endl;
  }
  return 0;
}

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

using namespace std;
#define INFS (1LL<<28)
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long
#define all(n) n.begin(),n.end()

int sn(int a,int b,int n){
  int x=(2*a+(n-1)*b%DEKAI);  
  int y=n;  
  return x*y%DEKAI*500000004%DEKAI;
}

int cnt[3000];

signed main(){
  int n,k;
  cin>>n>>k;
  int a[3000];
  int re[5000];
  lp(i,n)cin>>a[i];
  reverse(a,a+n);
  lp(i,n){
    re[i]=cnt[a[i]];
    for(int j=a[i]+1;j<3000;j++){
      cnt[j]++;
    }
    //cout<<re[i]<<endl;
  }
  lp(z,n){
    int i=z+n;
    re[i]=cnt[a[z]];
    for(int j=a[z]+1;j<3000;j++){
      cnt[j]++;
    }
    //cout<<re[i]<<endl;
  }
  int ans=0;
  lp(i,n){
    ans+=sn(re[i],re[n+i]-re[i],k);
    ans%=DEKAI;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define downque(que)  priority_queue<ll> que;
#define upque(que) priority_queue<ll, vector<int>, greater<int>> que;
typedef long long ll;
const int MOD = 1e9+7;

int main(){
  int a,b; cin>>a>>b;
  int res;
  if(a>=1&&a<=9&&b>=1&&b<=9)res=a*b;
  else res=-1;

 cout<<res<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int ans = min(B, A * N);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define R return
#define MEM(dp,i) memset(dp,i,sizeof(dp))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll inf=(1ll<<60);
const int MX = 10;
int n,m,ans,adj[MX][MX],a[MX];
/*vector<int>v[MX];
void dfs(int x,int mask){
    if(mask+1==(1<<n)){ans++;R;}
    for(auto nxt:v[x]){
        if(mask&(1<<nxt)||vis[nxt])continue;
        vis[nxt]=1;
        dfs(nxt,mask|(1<<nxt));
        vis[nxt]=0;
    }
}*/
int main(){
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)a[i]=i;
    while(m--){
        int a,b;
        scanf("%d%d",&a,&b);
        --a;--b;
        adj[a][b]=adj[b][a]=1;
    }
    do{
        if(a[0])continue;
        bool b=1;
        for(int i=0;i<n-1;i++){
            if(!adj[a[i]][a[i+1]])b=0;
        }
        if(b)ans++;
    }while(next_permutation(a,a+n));
    printf("%d\n",ans);
}


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

int main() {
    char b;
    cin >> b;
    if (b == 'A') cout << 'T' << endl;
    else if (b == 'T') cout << 'A' << endl;
    else if (b == 'G') cout << 'C' << endl;
    else cout << 'G' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int l[200005],r[200005];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n,k,c;
    cin >> n >> k >> c;
    string s;
    cin >> s;
    vector<int> l,r;
    for(int i = 0 ; i < n && l.size() < k ; i++){
        if(s[i] == 'o'){
            l.push_back(i);
            i+=c;
        }
    }
    reverse(ALL(s));
    for(int i = 0 ; i < n && r.size() < k ; i++){
        if(s[i] == 'o'){
            r.push_back(n-1-i);
            i+=c;
        }
    }
    vector<int> ans;
    for(int i=0;i<min(r.size(),l.size());i++){
        if(r[k-1-i] == l[i])ans.push_back(l[i]);
    }
    for(auto x:ans)cout << x + 1 << endl;
}

Measured memory_bytes: 6316
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	int x;
	int zh(string s);
	cin>>a>>b;
	x=zh(a+b);
	if(int(sqrt(x))==sqrt(x))
	  cout<<"Yes";
	else
	  cout<<"No";
	return 0;
}

int zh(string s)
{
	int tmp=0;
	for(int i=0;i<s.size();i++)
	tmp=tmp*10+(s[i]-'0');
	return tmp;
}

Measured memory_bytes: 256
(*
 * forall l r (p : forall n, l < n <= r -> bool),
 *   ( exists m,
 *     l < m <= r /\ forall n H, p n H = true <-> m <= n ) ->
 *   { m |
 *     l < m <= r /\ forall n H, p n H = true <-> m <= n }
 *)
let rec lower_bound l r p =
  if r <= 1 + l
  then r
  else let m = (l + r) / 2 in
       if p m
       then lower_bound l m p
       else lower_bound m r p
 
(*
 * forall l r (p : forall n, l <= n < r -> bool),
 *   ( exists m,
 *     l <= m < r /\ forall n H, p n H = true <-> n <= m ) ->
 *   { m |
 *     l <= m < r /\ forall n H, p n H = true <-> n <= m }
 *)
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m
       then upper_bound m r p
       else upper_bound l m p
 
let () = Scanf.scanf "%d %d %d\n" @@ fun a b q ->
  let ss = Array.make (a + 2) 0 in
  let ts = Array.make (b + 2) 0 in
  ss.(0) <- -123456789012345;
  ss.(a + 1) <- 123456789012345;
  for i = 1 to a do
    Scanf.scanf "%d\n" @@ Array.set ss i
  done;
  ts.(0) <- -123456789012345;
  ts.(b + 1) <- 123456789012345;
  for i = 1 to b do
    Scanf.scanf "%d\n" @@ Array.set ts i
  done;
  for i = 1 to q do
    Scanf.scanf "%d\n" @@ fun x ->
      let ls = upper_bound 0 (a + 2) @@ fun i -> ss.(i) <= x in
      let rs = lower_bound (-1) (a + 1) @@ fun i -> x <= ss.(i) in
      let lt = upper_bound 0 (b + 2) @@ fun i -> ts.(i) <= x in
      let rt = lower_bound (-1) (b + 1) @@ fun i -> x <= ts.(i) in
      Printf.printf "%d\n" @@ List.fold_left min max_int
      [ x - min ss.(ls) ts.(lt);
        max ss.(rs) ts.(rt) - x;
        ss.(rs) - x + ss.(rs) - ts.(lt);
        x - ss.(ls) + ts.(rt) - ss.(ls);
        ts.(rt) - x + ts.(rt) - ss.(ls);
        x - ts.(lt) + ss.(rs) - ts.(lt) ]
  done

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#include<string.h>
using namespace std;
typedef long long int lli;
int main()
{
  ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
   lli a,b,v,w,t;
   cin>>a>>v;
   cin>>b>>w;
   cin>>t;
   if(abs(a-b)<=(v-w)*t)
   cout<<"YES"<<"\n";
   else
   cout<<"NO"<<"\n";
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define lc "\n"
#define forr(i,a,n)  for(ll i=a;i<n;i++)
using namespace std;

int main()
{
    IOS;
    string s;
    cin>>s;

    int x=s.size();

       if(s[x-1]=='s' ){s+="es";}
       else {s+="s";}


   cout<<s;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin>>N;
  vector<long long>vec(10000);
  for(int X=1;X<=100;X++){
    for(int Y=X;Y<=100;Y++){
      for(int Z=Y;Z<=100;Z++){
        if(X*X+Y*Y+Z*Z+X*Y+X*Z+Y*Z<10001){
          if(X!=Y&&X!=Z&&Y!=Z){
            vec.at(X*X+Y*Y+Z*Z+X*Y+X*Z+Y*Z-1)+=6;
          }
          else if(X==Y&&X==Z){
            vec.at(X*X+Y*Y+Z*Z+X*Y+X*Z+Y*Z-1)+=1;
          }
          else{
            vec.at(X*X+Y*Y+Z*Z+X*Y+X*Z+Y*Z-1)+=3;
          }
        }
      }
    }
  }
  for(int X=0;X<N;X++){
    cout<<vec.at(X)<<endl;
  }
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N;
    cin>>N;
    queue <int> q;
    vector <int> A(N);
    
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end() ,greater<int>());
    for(int i=0;i<N;i++){
        q.push(A[i]);
    }
    
    int al=0,bob=0;
    
    int sum=0;
    for(int i=0;i<N;i++){
        
        if(i%2==0) sum+= A[i];
        else sum-=A[i];
    }
    /*
    for(int i=0;i<q.size();i++){
        int x=q.front();
        al += x; 
        q.pop();
        
        int y=q.front();
        bob += y; 
        q.pop();
    }
    */
    cout<<sum<<endl;
}


Measured memory_bytes: 256
n = int(input())
lis = list(map(int, input().split()))

su = [0]
for i,x in enumerate(lis):
    if i == x - 1:
        su[-1] += 1
    else:
        su.append(0)

res = 0
for j in su:
    res += (j + 1)//2
print(res)


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

  vector<tuple<string,int,int>>a;
  
  for(int i=0;i<n;i++)
  {
     string s;
    int p;
    int id;
   
    cin>>s>>p;
    id=i+1;
    p=-p;
   
   a.push_back(tie(s,p,id));
  }
  sort(a.begin(),a.end());
  
  for(int i=0;i<n;i++)
  {
      cout<<get<2>(a[i])<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n;
    cin >> n;
    vector<bool> a(n+1,false);
    rep(i,n){
        int j,k;
        cin >> j >> k;
        if(j == k) a[i] = true;
    }
    bool check = false;
    for(int i = 0; i+2 < n; i++){
        if(a[i] && a[i+1] && a[i+2]) check = true;
    }
    if(check) cout << "Yes" << endl;
    else cout << "No" << endl;

return 0;
}

Measured memory_bytes: 3628
package main

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

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

/*******************************************************************/

var n, w int
var V, W [110]int
var dp [110][10100]int

func main() {
	tmp := NextIntsLine()
	n, w = tmp[0], tmp[1]
	for i := 0; i < n; i++ {
		tmp = NextIntsLine()
		V[i], W[i] = tmp[0], tmp[1]
	}

	for i := 0; i < n; i++ {
		for j := 0; j <= w; j++ {
			if j >= W[i] {
				dp[i+1][j] = Max(dp[i][j], dp[i][j-W[i]]+V[i])
			} else {
				dp[i+1][j] = dp[i][j]
			}
		}
	}
	fmt.Println(dp[n][w])
}



Measured memory_bytes: 8996
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;

vector<vector<int>>edge;
vector<pair<int,int>>num;
vector<int>value;
bool fin = false;

pair<int, int> Search(int n) {
	if (fin) {
		num[n] = { 0,0 };
		return num[n];
	}
	if (num[n].first != -1) {
		return num[n];
	}
	if (edge[n].empty()) {
		num[n] = { value[n],0 };
		return num[n];
	}
	vector<vector<bool>>flag(edge[n].size() + 1, vector<bool>(value[n] + 1, false));
	flag[0][0] = true;
	int box = 1;
	int sum = 0;
	for (auto i : edge[n]) {
		auto bag = Search(i);
		L = bag.first;
		R = bag.second;
		sum += L;
		sum += R;
		for (int j = value[n]; j >= L; j--) {
			flag[box][j] = flag[box - 1][j - L];
		}
		for (int j = value[n]; j >= R; j--) {
			if (!flag[box][j]) {
				flag[box][j] = flag[box - 1][j - R];
			}
		}
		box++;
	}
	for (int i = value[n]; i >= 0; i--) {
		if (flag[edge[n].size()][i]) {
			//cout << n << " " << i << endl;
			num[n] = { value[n],sum - i };
			return num[n];
		}
	}
	fin = true;
	num[n] = { 0,0 };
	return num[n];
}

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

	cin >> N;
	edge.resize(N + 1);
	num.resize(N + 1, { -1,-1 });
	value.resize(N + 1);
	for (int i = 2; i <= N; i++) {
		cin >> K;
		edge[K].push_back(i);
	}
	for (int i = 1; i <= N; i++) {
		cin >> value[i];
	}
	Search(1);
	if (fin) {
		cout << "IMPOSSIBLE\n";
	}
	else {
		cout << "POSSIBLE\n";
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N;
	cin>>N;
	vector<string> s(N);

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

	sort(s.begin(),s.end());

	map<string,int> m;

	for(int i=0;i<N;i++) m[s[i]]++;

	int ma=0;

	for(int i=0;i<N;i++) ma = (ma<m[s[i]])?m[s[i]]:ma;
	for(int i=0;i<N;i++){
		if(ma==m[s[i]]) cout<<s[i]<<endl,m[s[i]]=0;
	}

	return EXIT_SUCCESS;	
}

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

bool test(int N, vector<int> xs, vector<int> ys) {
	int64_t mn1 = 1e18, mx1 = -1e18, mn2 = 1e18, mx2 = -1e18;
	// vector<int> xs(N), ys(N);
	for (int i = 0; i < N; ++i) {
		int64_t x=xs[i], y=ys[i];
		// cin >> x >> y;
		// xs[i] = x;
		// ys[i] = y;
		if (x+y < mn1) {
			mn1 = x+y;
		}
		if (x+y > mx1) {
			mx1 = x+y;
		}

		if (x-y < mn2) {
			mn2 = x-y;
		}

		if (x-y > mx2) {
			mx2 = x-y;
		}
	}
	int64_t a1 = max(abs(mx1-mn1), abs(mx2-mn2));
	int a2 = -1;
	for (int i = 0; i < N; ++i) {
		for (int j = i+1; j < N; ++j) {
			a2 = max(a2, abs(xs[i]-xs[j])+abs(ys[i]-ys[j]));

		}
	}
	cout << a1 << " " << a2 << endl;
	assert(a1==a2);
}


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

	// default_random_engine re;
	// for (int tc = 0; tc < 10000; ++tc) {
	// 	int N = 10;
	// 	vector<int> xs(N), ys(N);
	// 	for (int i = 0; i < N; ++i) {
	// 		xs[i] = re()%100;
	// 		ys[i] = re()%100;
	// 	}
	// 	test(N,xs,ys);
	// }

	int N;
	cin >> N;

	int64_t mn1 = 1e18, mx1 = -1e18, mn2 = 1e18, mx2 = -1e18;
	vector<int> xs(N), ys(N);
	for (int i = 0; i < N; ++i) {
		int64_t x, y;
		cin >> x >> y;
		xs[i] = x;
		ys[i] = y;
		if (x+y < mn1) {
			mn1 = x+y;
		}
		if (x+y > mx1) {
			mx1 = x+y;
		}

		if (x-y < mn2) {
			mn2 = x-y;
		}

		if (x-y > mx2) {
			mx2 = x-y;
		}
	}
	cout << max(abs(mx1-mn1), abs(mx2-mn2)) << endl;
	// int ans = -1;
	// for (int i = 0; i < N; ++i) {
	// 	for (int j = i+1; j < N; ++j) {
	// 		ans = max(ans, abs(xs[i]-xs[j])+abs(ys[i]-ys[j]));

	// 	}
	// }
	// cout << ans << endl;
}

Measured memory_bytes: 4784
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

//using
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using LL = long long;

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

//constant
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = acos(-1.0);

//debug
#define dump(x)  cout << #x << " = " << (x) << endl;

int main() {
  string S;
  cin >> S;
  int ans = 0;
  REP(i, S.size()) {
    if (S[i] =='1') ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, m;
  int sum = 0;
  cin >> n >> m;
  vector<int> vec(m, 0);
  for (int i = 0; i < m; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }

  if (sum > n) {
    cout << "-1" << endl;
  } else {
    cout << n - sum << endl;
  }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
struct graph{
    vi v;
};

void bfs(graph G[],int start,vl & d){
    queue<int> q;
    q.push(start);
    d[start] = 0;
   
    while(!q.empty()){
        int from = q.front();
        q.pop();
        for(int i=0;i<G[from].v.size();i++){
            int to = G[from].v[i];
          //  cout << from << "  " << to << "\n";
            if(d[to] == inf){
                d[to] = d[from]+1;
                q.push(to);
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string str;   cin>>str;
    int q;   cin>>q;
    int r = 0;
    string suf,pre;
    while(q--){
        int a;  cin>>a;
        if(a==1){
            r = 1-r;
        }
        else{
            int b;  cin>>b;
            char ch ; cin>>ch;
            if(b==1){
                if(r==0){
                    pre += ch;
                }
                else{
                    suf += ch;
                }
            }
            else{
                if(r==0){
                    suf += ch;
                }
                else{
                    pre += ch;
                }
            }
        }
    }
    string ans;
    if(r==1){
        reverse(all(suf));
        reverse(all(str));
        ans = suf + str + pre;
    }
    else{
        reverse(all(pre));
        ans = pre + str + suf;
    } cout << ans;
    
    return 0;
}
    


Measured memory_bytes: 1300
N = int(input())

jisho = []
i = 1
for _ in range(N):
    value = input().split()
    jisho.append([value[0], int(value[1]), i])
    i += 1


jisho.sort(key=lambda x:(x[0],-x[1]))
for val in jisho:
    print(val[2])

Measured memory_bytes: 38256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define ins insert
#define ll long long
#define Pair pair<int,int>
#define MT make_tuple
#define MP make_pair
#define INF 0x3f3f3f3f
#define lim 1e9
#define Bigint 3e8+1
#define MAX 3e5
#define NL '\n'
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, //for indexed_set
        tree_order_statistics_node_update> indexed_set;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen("input.txt","r",stdin);

    string s;
    cin >> s;
    if(s=="SUN") cout << 6+1;
    else if(s=="MON") cout << 5+1;
    else if(s=="TUE") cout << 4+1;
    else if(s=="WED") cout << 3+1;
    else if(s=="THU") cout << 2+1;
    else if(s=="FRI") cout << 1+1;
    else cout << 0+1;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		String s=sc.next();
		String t=sc.next();
		String tmp="";
		int ngs=11451419;
		tmp=s.substring(0,s.length())+t.substring(0,t.length());
		if(tmp.substring(0,N).equals(s) && tmp.substring(tmp.length()-N,tmp.length()).equals(t)) {
			ngs=Math.min(tmp.length(), ngs);
		}
		for(int i=1; i<=N; i++) {
			tmp=s.substring(0,s.length()-i+1)+t.substring(i,t.length());
			if(tmp.length()>=N) {
				if(tmp.substring(0,N).equals(s) && tmp.substring(tmp.length()-N,tmp.length()).equals(t)) {
					ngs=Math.min(tmp.length(), ngs);
				}
			}
			tmp=s.substring(0,s.length()-i)+t.substring(i-1,t.length());
			if(tmp.length()>=N) {
				if(tmp.substring(0,N).equals(s) && tmp.substring(tmp.length()-N,tmp.length()).equals(t)) {
					ngs=Math.min(tmp.length(), ngs);
				}
			}
			tmp=s.substring(0,s.length()-i)+t.substring(i,t.length());
			if(tmp.length()>=N) {
				if(tmp.substring(0,N).equals(s) && tmp.substring(tmp.length()-N,tmp.length()).equals(t)) {
					ngs=Math.min(tmp.length(), ngs);
				}
			}
		}
		System.out.println(ngs);
	}
}

Measured memory_bytes: 21204
/*
* Problem Link: https://atcoder.jp/contests/abc042/tasks/abc042_a
*/

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

int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    (a[0] == a[1] && a[0] == 5 && a[2] == 7) ? cout << "YES\n" : cout << "NO\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <functional>

using namespace std;
using ll = long long;

#define FOR(i, m, n) for(int i = (m);i < (n);i++)
#define REP(i,n) for(int i = 0; i < int(n); i++)
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<ll>
#define PAIR pair<int,int>
#define MP make_pair
#define VP vector<pair<int,int>>
#define VS vector<string>
#define PQUE priority_queue<int> //5,5,4,3,3,2,...
#define REPQUE priority_queue<int, vector<int>, greater<int>> //1,1,2,3,4,4,5,...
#define SUM(obj) accumulate((obj).begin(), (obj).end(), 0)
#define SORT(obj) sort((obj).begin(), (obj).end()) // 1,2,3,4,5...
#define RESORT(obj) sort((obj).begin(), (obj).end(), greater<int>()) // 5,4,3,2,1...
#define UB(obj,n) upper_bound((obj).begin(), (obj).end(), n) //itr > n
#define LB(obj,n) lower_bound((obj).begin(), (obj).end(), n) //itr>= n

const ll MOD = (ll)1e9 + 7;

int main() {
	int N,c = 0;
	cin >> N;
	REP(i, N) {
		int l, r;
		cin >> l >> r;
		c += (r - l) + 1;
	}
	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#???
n=int(input())
a=list(map(int,input().split()))
MOD=10**9+7

def gcd(x,y):
  if x<y:x,y=y,x
  if y==0:return x
  return gcd(x%y,y)

def lcm(x,y):
  return x*y//gcd(x,y)

def inv(x):
  return pow(x,MOD-2,MOD)

L=1
for i in a:
  L=lcm(L,i)

L=L%MOD
ans=0
for i in a:
  ans=(ans+L*inv(i))%MOD
  

print(ans)

Measured memory_bytes: 70620
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

typedef tuple<int, ll> path;

int N;
vector<path> V[100010];
int Q, K;
path parent[100010];
ll memo[100010];
int x[100010];
int y[100010];

ll dist(int n) {
  if (memo[n] != -1) return memo[n];
  if (n == K) return memo[n] = 0;
  int p = get<0>(parent[n]);
  return memo[n] = dist(p) + get<1>(parent[n]);
}

int main () {
  cin >> N;
  for (auto i = 0; i < N-1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    V[a].push_back(path(b, c));
    V[b].push_back(path(a, c));
  }
  cin >> Q >> K;
  K--;
  for (auto i = 0; i < Q; ++i) {
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
  }
  fill(memo, memo+100010, -1);
  stack<int> S;
  S.push(K);
  parent[K] = path(-1, 0);
  while (!S.empty()) {
    int now = S.top();
    S.pop();
    for (auto x : V[now]) {
      int next = get<0>(x);
      ll d = get<1>(x);
      if (next != get<0>(parent[now])) {
        parent[next] = path(now, d);
        S.push(next);
      }
    }
  }
  for (auto i = 0; i < Q; ++i) {
    cout << dist(x[i]) + dist(y[i]) << endl;
  }
}


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

namespace _6_D
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[,] gyoretu = new int[x[0], x[1]];
            for (int i = 0; i < x[0]; i++)
            {
                int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < x[1]; j++)
                {
                    gyoretu[i, j] = a[j];
                }
            }
            int[] bekutoru = new int[x[1]];
            for (int i = 0; i < x[1]; i++)
            {
                bekutoru[i] = int.Parse(Console.ReadLine());
            }
            for (int i = 0; i < x[0]; i++)
            {
                long ret = 0;
                for (int j = 0; j < x[1]; j++)
                {
                    ret += gyoretu[i, j] * bekutoru[j];
                }
                Console.WriteLine(ret);
            }
        }
    }
}

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

using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define wt(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define wt(x...)
#endif
/////////////////////////////////////////////////////////////////////////////////////////////////


#define LL long long
const int MAXN = 1005;
const LL INF  = 0x3f3f3f3f3f3f3f3f;

int N, M;
LL dp[MAXN][MAXN], a[MAXN], b[MAXN], c[MAXN];

LL solve (int n, int m, int x, int y, int z) {

	if (m == 0)
		return 0;

	if (n >= N)	
		return -INF;

	LL &k = dp[n][m];
	if (k != -1)
		return k;

	LL q = x * a[n];
	LL p = y * b[n];
	LL t = z * c[n];

	return k = max (solve (n + 1, m, x, y, z), q + p + t + solve (n + 1, m - 1, x, y, z));

}

int main () {

	scanf("%d %d", &N, &M);

	for (int i = 0; i < N; ++i)
		scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);


	LL ans = -INF;

	for (int x = -1; x <= 1; x += 2)
		for (int y = -1; y <= 1; y += 2)
			for (int z = -1; z <= 1; z += 2) {
				memset (dp, -1, sizeof dp);
				ans = max (ans, solve (0, M, x, y, z));
			}

	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int h[50];
	int cnt=0;
	for(int i=0;i<n;i++){
		bool yn=1;
		cin>>h[i];
		for(int j=0;j<i;j++){
			if(h[i]<h[j]){
				yn=0;
				break;
			}
		}
		if(yn==1){
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
} 

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


xor = [0]*(N+1)
cum = [0]*(N+1)
for i in range(N):
    xor[i] = xor[i-1]^A[i]
    cum[i] = cum[i-1]+A[i]

rlist = []
r = 0
for l in range(N):
    r = max(l+1,r)
    while r < N and xor[r]^xor[l-1] == cum[r]-cum[l-1]:
        r += 1
    if r == N:
        break
    r -= 1
    rlist.append(r)
ans = 0
rlist += [N-1]*(N-len(rlist))
for l in range(N):
    r = rlist[l]
    ans += r-l+1
print(ans)

Measured memory_bytes: 36152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define INF (1LL<<57)
#define MV 200001
#define LMV 21
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define emp emplace
#define whoami(x) cerr<<#x<<" "<<x<<"\n";
#define mp make_pair
#define ins insert
#define sz size

void FLASH() {ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);}
void SETF() {cout.ios_base::setf(ios_base::fixed);}
void UNSETF() {cout.ios_base::unsetf(ios_base::fixed);}

typedef long long ll;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<PII, int> PPII;
typedef pair<PLL, ll> PPLL;
typedef map<int, int> MII;

const int MOD = 1000000007;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

struct h_llint {
  static uint64_t splitmix64(uint64_t x) {    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

struct h_pair{
  size_t operator()(const PLL&x)const{
    return hash<ll>()(((ll)x.ff)^(((ll)x.ss)<<32));
  }
};

typedef map<ll, ll> MLL;
typedef map<PII, int> MPII;
typedef map<PLL, ll> MPLL;
typedef set<int> SI;
typedef set<ll> SL;
//ordered_set = order_of_key(.)
//ordered_set = find_by_order(.)
typedef ordered_set<int> OSI;
typedef ordered_set<ll> OSL;
typedef ordered_multiset<int> MOSI;
typedef ordered_multiset<ll> MOSL;
typedef unordered_map<ll, int, h_llint> UMLI;
typedef unordered_map<ll, ll, h_llint> UMLL;
typedef unordered_map<PLL, int, h_pair> UMPI;
typedef unordered_map<PLL, ll, h_pair> UMPL;

int ar[MV], dl[MV], dr[MV];
ll arr[MV];

void solve(int T)
{
	int n,k,c;
	cin>>n>>k>>c;
	string s;
	cin>>s;
	int dy = 1, lst = -MOD;
	for(int i=0;i<n;i++)
	{
		if(dy > k)
		break;
		if((s[i] == 'o') && (lst + c + 1 <= i))
		{
			dl[dy] = i;
			lst = i;
			dy++;
		}	
	}	
	dy = k, lst = MOD;
	for(int i=n-1;i>=0;i--)
	{
		if(dy < 1)
		break;	
		if((s[i] == 'o') && (lst - c - 1 >= i))
		{
			dr[dy] = i;
			lst = i;
			dy--;
		}
	}
	for(int i=1;i<=k;i++)
	{	
		if(dl[i] == dr[i])
		cout<<dl[i]+1<<"\n";
	}
	return;	
}

int main(void)
{
	FLASH();
	int T;
	T = 1;

// #ifndef ONLINE_JUDGE
// 	time_t time_t1, time_t2;
// 	time_t1 = clock();
// #endif

	while(T--)
	solve(T);

// #ifndef ONLINE_JUDGE
// 	time_t2 = clock();
// 	SETF();
// 	cout<<"Time taken: "<<setprecision(7)<<(time_t2 - time_t1)/(double)CLOCKS_PER_SEC<<"\n";
// 	UNSETF();
// #endif

	return 0;
}

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

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector <int> > vvi;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);


typedef pair<int,bool> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B,X;
    cin >> A >> B >> X;
    int ans = 0;
    ans += min(A,B*2) * (X / 1000);
    X %= 1000;
    if(X > 500){
        ans += min(A,B*2);
    }else if(X != 0){
        ans += min(A,B);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3216
H, W, K = map(int, input().split())
cList = list()
for i in range(H):
  cList.append(input())

ans = 0
for maskR in range((1 << H)):
  for maskC in range((1 << W)):
    black = 0
    for i in range(H):
      for j in range(W):
        if ((maskR >> i) & 1) == 0 and ((maskC >> j) & 1) == 0 and cList[i][j] == '#':
          black += 1
    if black == K:
      ans += 1
print(ans)

Measured memory_bytes: 9120