akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;


int main(){

   int height,width,count,limit,row,col;
   char table[100][101];

   while(true){
	   scanf("%d %d",&height,&width);
	   if(height == 0 && width == 0)break;

	   for(int i = 0; i < height; i++){
		   scanf("%s",table[i]);
	   }

	   count = 0;
	   row = 0; col = 0;
	   limit = height*width;

	   while(table[row][col] != '.' && count < limit){
		   switch(table[row][col]){
		   case '>':col++;
		   	   	   count++;
		   	   	   break;
		   case '<':col--;
		   	   	   count++;
		   	   	   break;
		   case '^':row--;
		   	   	   count++;
		   	   	   break;
		   case 'v':row++;
		   	   	   	count++;
		   	   	   	break;
		   }
	   }

	   if(count >= limit){
		   printf("LOOP\n");
	   }else{
		   printf("%d %d\n",col,row);
	   }

   }

    return 0;
}

Measured memory_bytes: 2620
a = input().split(" ")
N = eval(a[0])
K = eval(a[1])
dic = {}
b = input().split(" ")
n_lst = [-1]
for i in range(1, N + 1):
    dic[i] = eval(b[i - 1])
    n_lst.append(-1)
ans = 1
lst = []
length = 0
while K > 0:
    if n_lst[ans] != -1:
        left = n_lst[ans]
        zq = length - left
        K = K % zq
        if K == 0:
            break
    else:
        n_lst[ans] = length
        length += 1
    ans = dic[ans]
    K -= 1

print(ans)

Measured memory_bytes: 52576
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <cstring>
 
using namespace std;

#define MAX_N 100005
#define MAX_M 100005
 
struct UF {
	int n;
	vector<int>d;
	UF() {}
	UF(int n) :n(n), d(n, -1) {}
 
	int root(int v) {
		if (d[v] < 0) { return v; }
		return d[v] = root(d[v]);
	}
	bool unite(int x,int y) {
		x = root(x);
		y = root(y);
		if (x == y) { return false; }
		if (size(x) < size(y)) { swap(x, y); }
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	int size(int v) { return -d[root(v)]; }
};

int p[MAX_N];
int x[MAX_M];
int y[MAX_M];

int main() {

	int N,M;

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

	int i;

	for(i=0;i<N;i++){
	scanf(" %d",&p[i]);
	}

	UF t(N+5);

	for(i=0;i<M;i++){
	scanf("%d %d",&x[i],&y[i]);
	t.unite(x[i],y[i]);
	}

	int ans=0;

	for(i=0;i<N;i++){
		if(t.root(p[i])==t.root(i+1)){ans++;}
	}
	printf("%d\n",ans);


return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			int N = Integer.parseInt(br.readLine());
			int[] F = new int[N];
			for (int i = 0; i < N; i++) {
				F[i] = Integer.parseInt(br.readLine().replaceAll(" ", ""), 2);
				// int[] array = Arrays.stream(br.readLine().split("
				// ")).mapToInt(Integer::parseInt).toArray();
				// int value = 0;
				// for (int j = 0; j < 10; j++) {
				// value |= array[j] << j;
				// }
				// F[i] = value;
			}

			int[][] P = new int[N][11];

			for (int i = 0; i < N; i++) {
				P[i] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
			}

			int max = Integer.MIN_VALUE;

			for (int mask = 1; mask <= 0b11_1111_1111; mask++) {
				int value = 0;
				for (int i = 0; i < N; i++) {
					int order = mask & F[i];
					value += P[i][Integer.bitCount(order)];
				}
				max = Math.max(max, value);
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 26964
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int a[55], b[55], c[55];
int res = 0;
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i<=n; i++)
		cin >> a[i];
	for (int i = 1; i<=n; i++)
		cin >> b[i];
	for (int i = 2; i<=n; i++)
		cin >> c[i];
	for (int i = 1; i<=n; i++)
	{
		res += b[a[i]];
		if (i >= 2)
		{
			if (a[i-1]+1 == a[i])
				res += c[a[i]];
		}
	}
	cout << res << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>

int main()
{
  int G[100][100];
  int d[100];
  int pi[100];
  int color[100];
  int i, j, k;
  int n,a,b,c;
  int mincost,sum=0;

  scanf("%d", &n);

  for(i = 0; i < n; i++)
  {
       for(j = 0; j < n; j++)
       {
            G[i][j] = -1;
       }
  }

  for(i = 0; i < n; i++)
  {
    d[i] = INT_MAX;
    pi[i] = 0;
    color[i] = 0;
    scanf("%d%d", &b, &k);
    for(j = 0; j < k; j++)
    {
      scanf("%d%d", &a, &c);
      G[b][a] = c;
    }
  }

  d[0] = 0;

  while(1)
  {
    mincost = INT_MAX;
    for(i = 0; i < n; i++)
    {
      if(color[i] != 1 && d[i] < mincost)
      {
	mincost = d[i];
	b = i;
      }
    }
if(mincost == INT_MAX)
{
     break;
}
    color[b] = 1;
    for(i = 0; i < n; i++)
    {
      if(G[b][i] != -1 && color[i] != 1 && d[b] + G[b][i] < d[i])
      {
	pi[i] = b;
	d[i] = G[b][i];
	d[i] += d[pi[i]];
      }
    }
  }

  for(i = 0; i < n; i++){
       printf("%d %d\n", i, d[i]);
  }
  
  return 0;
}



Measured memory_bytes: 2080
def query(tree,begin,end,target,left,right,infinity,func):
  if right <= begin or end <= left:
    return infinity
  if begin <= left and right <= end:
    return tree[target]
  next_position = (left + right) // 2
  left_index = 2 * target + 1
  right_index = left_index + 1
  left_side_value = query(tree, begin, end, left_index, left, next_position, infinity, func)
  right_side_value = query(tree, begin, end, right_index, next_position, right, infinity, func)
  return func(left_side_value,right_side_value)

over_value = 2000000000
ary_size = int(input())
data_ary = list(map(int,input().split()))

leaf_size = 1
while leaf_size < ary_size:
  leaf_size = leaf_size * 2

tree_size = leaf_size * 2 - 1

min_tree = [over_value] * tree_size
max_tree= [-over_value] * tree_size
for i in range(ary_size):
  index = leaf_size - 1 + i
  min_tree[index] = data_ary[i]
  max_tree[index] = data_ary[i]

for i in range(leaf_size-2,-1,-1):
  left_index = 2 * i + 1
  right_index = left_index + 1
  min_tree[i] = min(min_tree[left_index], min_tree[right_index])
  max_tree[i] = max(max_tree[left_index], max_tree[right_index])

query_size = int(input())
for i in range(query_size):
  input_data = list(map(int,input().split()))
  command = input_data[0]
  begin = input_data[1]
  end = input_data[2]
  if command == 0:
    min_value = query(min_tree,begin,end,0,0,leaf_size,over_value,min)
    print(min_value)
  elif command == 1:
    max_value = query(max_tree,begin,end,0,0,leaf_size,-over_value,max)
    print(max_value)



Measured memory_bytes: 5732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define F first
#define S second
#define inf LLONG_MAX
#define mod 1000000007
#define vll vector <ll>
#define pll pair <ll,ll>
#define dbg(n) cout<<n<<' '
#define cu continue
#define br break

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

	ll a[3][3];
	bool vis[3][3];
	memset(vis,0,sizeof vis);
	for(ll i=0;i<3;i++)
		for(ll j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	ll n;
	cin>>n;
	ll b[n];
	for(ll i=0;i<n;i++) cin>>b[i];
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<3;j++)
		{
			for(ll k=0;k<3;k++)
			{
				if(a[j][k]==b[i])
				{
					vis[j][k]=1;
				}
			}
		}
	}
	ll fl=0;
	if(vis[0][0] && vis[0][1] && vis[0][2]) fl=1;
	if(vis[1][0] && vis[1][1] && vis[1][2]) fl=1;
	if(vis[2][0] && vis[2][1] && vis[2][2]) fl=1;
	if(vis[0][0] && vis[1][0] && vis[2][0]) fl=1;
	if(vis[0][1] && vis[1][1] && vis[2][1]) fl=1;
	if(vis[0][2] && vis[1][2] && vis[2][2]) fl=1;
	if(vis[0][0] && vis[1][1] && vis[2][2]) fl=1;
	if(vis[0][2] && vis[1][1] && vis[2][0]) fl=1;
	if(fl)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

class Main {
    public static void main(String[] args) throws NumberFormatException, IOException {
      BufferedReader Bf=new BufferedReader(new InputStreamReader(System.in));
      
        
             int n=Integer.parseInt(Bf.readLine());
                          long a[]=new long[(int)(n)];
                          String in[]=Bf.readLine().trim().split(" ");
                         
             for(int i=0;i<n;++i){
                 a[i]=Long.parseLong(in[i]);
             }
           
             //prefix sum technique
             long sum[]=Arrays.copyOf(a, a.length);

             long mod=(long)1e9+7;
               
             for(int i=1;i<n;++i){
                    sum[i]=(sum[i]%mod+sum[i-1]%mod)%mod;
                   
             }
           long ans=0;
           long sum1=0;
           for(int i=1;i<a.length;++i){
               ans+=(a[i]*sum[i-1])%mod;
                 ans%=mod;

           }
           System.out.print(ans);
           
             

         
    }
}

Measured memory_bytes: 63120
#include <iostream>
using namespace std;
int main(){
int a,b,c;
cin >> a >>b >> c;
if(a >=c  && c>= b ){
cout << "Yes" <<endl;
}else if(a <= c && c<= b){
cout << "Yes" <<endl;
}else{
cout << "No" <<endl;
}
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int main()
{
    int n;
    vi a;
    cin >> n;
    a.resize(n);
    rep(i,n) cin >> a[i];
    
    sort(all(a));

    int ans=0;
    int ima=a[0];
    int imak=1;
    rep(i,n){
        if(i == 0) continue;
        if(a[i] == ima){
             imak++;
        }
        else{
            ans += imak%2;
            ima = a[i];
            imak = 1;
        }
    }
    ans += imak%2;
    cout << ans << endl;
}


Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int n,k;
int a[100005];
int MAX;
int gcd(int a, int b)
{
 if (a < b)
  swap(a, b);

 if (b == 0)
  return a;
 else
  return gcd(b, a%b);
}
int ngcd(int *a, int n)
{
 if (n==1)
  return *a;
 return gcd(a[n], ngcd(a,n-1));
}
int main()
{
    scanf("%d%d",&n,&k);
    MAX=-1;
    int flag=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        MAX=max(a[i],MAX);
        if(a[i]==k)
            flag=1;
    }
    if(flag)
        printf("POSSIBLE\n");
    else if(k>MAX)
        printf("IMPOSSIBLE\n");
    else
    {
        if(k%ngcd(a,n)==0)
        printf("POSSIBLE\n");
        else
            printf("IMPOSSIBLE\n");
    }
    return 0;
}


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

int main(){
    int n, m; cin >> n >> m;
    vector<int> a;
    rep(i,n){
        int v; cin >> v;
        a.push_back(v);
    }
    sort(a.begin(),a.end());
    rep(i,m){
        int b = a.back() / 2;
        a.pop_back();
        auto itr = lower_bound(a.begin(), a.end(), b);
        a.insert(itr,b);
    }
    ll ans = 0; 
    rep(i,n) ans += a[i];
    cout << ans << endl;
    return 0;
}

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

int pre[40],in[40],n,count;
vector<int> out;

void rep(int left,int right){
	if(left>=right)	return;
	int root=pre[count++];
	int next;
	for(int i=0;i<n;i++){
		if(in[i]==root){
			next=i;
			break;
		}
	}
	rep(left,next);	rep(next+1,right);
	out.push_back(root);
}

void solve(){
	count=0;
	rep(0,n);
	for(int i=0;i<(int)out.size();i++){
		if(i)	cout<<" ";
		cout<<out[i];
	}
	cout<<endl;
}


int main(){
	cin>>n;
	for(int i=0;i<n;i++)	cin>>pre[i];
	for(int i=0;i<n;i++)	cin>>in[i];
	solve();
	return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,x;
int main()
{
 ll a,b,x;
 cin>>a>>b>>x;
 x=min(x,b-1);
 ll ans1=(a*x/b)-a*(x/b);
 cout<< ans1<<endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string s, t;
    cin >> s >> t;
    bool v = true;
    rep(i, s.size())if(s[i] != t[i])v = false;
    cout << (v ? "Yes" : "No") << endl;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

tuple<int64, int64> Normalize(int64 x, int64 y) {
  if (x == 0 && y == 0) return {0, 0};
  if (x == 0) return {0, 1};
  if (y == 0) return {1, 0};
  int64 d = __gcd(x, y);
  x /= d;
  y /= d;
  if (x < 0) {
    x *= -1;
    y *= -1;
  }
  return {x, y};
}

tuple<int64, int64> Pair(int64 x, int64 y) {
  if (x == 0 && y == 0) return {0, 0};
  if (x == 0) return {1, 0};
  if (y == 0) return {0, 1};
  int64 rx = -y;
  int64 ry = x;
  if (rx < 0) {
    rx *= -1;
    ry *= -1;
  }
  return {rx, ry};
}

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

FiniteField Power(FiniteField x, int p) {
  if (p < 0) return FiniteField(1) / Power(x, -p);
  FiniteField value = 1;
  while (p) {
    if (p % 2) value *= x;
    x *= x;
    p /= 2;
  }
  return value;
}

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

  int n;
  cin >> n;
  map<tuple<int64, int64>, int> m;
  for (int i = 0; i < n; i++) {
    int64 x, y;
    cin >> x >> y;
    tie(x, y) = Normalize(x, y);
    m[{x, y}]++;
  }

  FiniteField ans = 1;
  set<tuple<int64, int64>> visited;
  for (const auto& kv : m) {
    tuple<int64, int64> v1 = kv.first;
    if (visited.find(v1) != visited.end()) {
      continue;
    }
    if (v1 == make_tuple(0, 0)) {
      continue;
    }
    int c1 = kv.second;
    auto v2 = Pair(get<0>(v1), get<1>(v1));
    int c2 = m[v2];
    ans *= (Power(2, c1) + Power(2, c2) - 1);
    visited.insert(v1);
    visited.insert(v2);
  }
  ans += m[{0, 0}];
  ans -= 1;
  cout << ans << endl;
}

Measured memory_bytes: 53552
import sys
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))
A = [A1, A2, A3]
n = int(input())
for i in range(n):
  b = int(input())
  for j in range(3):
    for k in range(3):
      if A[j][k] == b:
        A[j][k] = 0
#print(A)
#横
for i in range(3):
  if A[i].count(0) == 3:
    print("Yes")
    sys.exit()
#縦
for i in range(3):
  if A1[i] == 0 and A2[i] == 0 and A3[i] == 0:
    print("Yes")
    sys.exit()
#斜め
if A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0:
    print("Yes")
    sys.exit()
if A[0][2] == 0 and A[1][1] == 0 and A[2][0] == 0:
    print("Yes")
    sys.exit()

print("No")

Measured memory_bytes: 38488
using System;
class Program
{
  static void Main (string[] args)
  {
    int a = int.Parse(Console.ReadLine());
    int b = int.Parse(Console.ReadLine());
    int c = int.Parse(Console.ReadLine());
    int d = int.Parse(Console.ReadLine());
    int e = int.Parse(Console.ReadLine());
    int k = int.Parse(Console.ReadLine());
    Console.WriteLine((k < (e-a)) ? ":(" : "Yay!");
  }
}

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

int main(){
  int h, w, a, b;cin>>h>>w>>a>>b;
  for(int i=0;i<h;i++){
    bool bit=i<b;
  	for(int j=0;j<a;j++)cout<<int(bit);
    for(int j=0;j<w-a;j++)cout<<int(!bit);
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
	
	public static int gcd(int x, int y) {
		if(y == 0) {
			return x;
		}
		return gcd(y, x%y);
	}
	
	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);
		int x = Integer.parseInt(in.next());
		int y = Integer.parseInt(in.next());
		
		System.out.println(gcd(x,y));
		
		in.close();
	}
}




Measured memory_bytes: 26324
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;
 
 int n;
 int arr[10+2];
 int term[10+2];
 long long int cnt;
 
 void dfs(int x)
 {
   if(x==n)
   {
     bool flag=false;
     for(int i=0;i<n;i++)
     { 
       if((term[i]%2)==0)
       { 
         flag=true;
         break;
       }
     }
     if(flag)
     {
       //for(int i=0;i<n;i++) cout<<term[i]<<" ";
       //cout<<endl; 
       cnt++;
     }
     return;              
   }
     term[x]=arr[x]-1;
     dfs(x+1);
     term[x]=arr[x];
     dfs(x+1);
     term[x]=arr[x]+1;
     dfs(x+1);    
     return;
 }

 int main()
 {
   while(cin>>n)
   {
     for(int i=0;i<n;i++) cin>>arr[i];
     cnt=0;
     dfs(0);  
     cout<<cnt<<endl;
   } 
   return 0;
 }
 


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#define R pair<string, long long>

using namespace std;

int main(){
  queue<R> Q;
  long long n, q, time;
  string name;
  cin >> n >> q;
  for(long long i=0;i<n;i++){
    cin >> name >> time;
    Q.push(R(name, time));
  }
  long long total=0;
  while(!Q.empty()){
    R r = Q.front();Q.pop();
    if(r.second <= q){
      total += r.second;
      cout << r.first << ' ' << total << endl;
    }
    else{
      total += q;
      Q.push(R(r.first, r.second - q));
    }
  }
}


Measured memory_bytes: 6256
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")
def getlist():
	return list(map(int, input().split()))

class SegmentTree(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N0 = 2 ** (N - 1).bit_length()
		self.data = [INF] * (2 * self.N0)

	#k番目の値をxに更新
	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = min(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の最小値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = INF
		while L < R:
			if R & 1:
				R -= 1
				m = min(m, self.data[R - 1])
			if L & 1:
				m = min(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m

class SegmentTreeMAX(object):
	#N:処理する区間の長さ
	def __init__(self, N):
		self.N0 = 2 ** (N - 1).bit_length()
		self.data = [-INF] * (2 * self.N0)

	#k番目の値をxに更新
	def update(self, k, x):
		k += self.N0 - 1
		self.data[k] = x
		while k > 0:
			k = (k - 1) // 2
			self.data[k] = max(self.data[2 * k + 1], self.data[2 * k + 2])

	#区間[l, r]の最小値
	def query(self, l, r):
		L = l + self.N0; R = r + self.N0 + 1
		m = -INF
		while L < R:
			if R & 1:
				R -= 1
				m = max(m, self.data[R - 1])
			if L & 1:
				m = max(m, self.data[L - 1])
				L += 1
			L >>= 1; R >>= 1

		return m


#処理内容
def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		Seg = SegmentTree(N)
		SegMAX = SegmentTreeMAX(N)
		#セグ木をindexで初期化
		for i in range(N):
			Seg.update(i, i)
			SegMAX.update(i, i)

		ans = 0
		Lis = []
		for i in range(N):
			K, L, R = getlist()
			ans += R
			dif = L - R
			Lis.append([abs(dif), dif, K - 1])

		Lis.sort()
		for i in range(N):
			ab, diff, ind = Lis[-1 - i]
			# 絶対にK番目以内になる場合
			if diff >= 0:
				if ind >= N - 1:
					ans += diff
				else:
					segInd = SegMAX.query(0, ind)
					if segInd == -INF:
						pass
					else:
						ans += diff
						SegMAX.update(segInd, -INF)
			else:
				if ind >= N - 1:
					ans += diff
				# K番目に入るかの判定
				else:
					segInd = Seg.query(ind + 1, N - 1)
					if segInd == INF:
						ans += diff
					else:
						Seg.update(segInd, INF)

		print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 110672
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a == 2)
		a = 3;
	else if (a == 4 || a == 6 || a == 9 || a == 11)
		a = 2;
	else a = 1;
	if (b == 2)
		b = 3;
	else if (b == 4 || b == 6 || b == 9 || b == 11)
		b = 2;
	else b = 1;
	if (a == b)
		cout << "Yes";
	else
		cout << "No";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define inf 10000000007
#define ff first
#define ss second
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5 + 5;
lli dp[N][3],a[N][3];
int main()
{
    IOS
    int n;cin>>n;
    for(int i=0;i<n;i++)
        {
            cin>>a[i][0]>>a[i][1]>>a[i][2];
            dp[i][0] = dp[i][1] = dp[i][2] = 1e16;
        }

    dp[0][0] = a[0][0];dp[0][1] = a[0][1];dp[0][2] = a[0][2];
    for(int i=1;i<n;i++)
    {
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + a[i][0];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + a[i][1];
        dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + a[i][2];
    }    
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
    return 0;
}

Measured memory_bytes: 4992
#include<cmath>
#include<cstdio>
#include<vector>

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

using namespace std;

const long double EPS=1e-8;
const long double PI=acos(-1);

struct point{
	long double x,y;
	point():x(0),y(0){}
	point(long double x,long double y):x(x),y(y){}
	point operator-(const point &a)const{ return point(x-a.x,y-a.y); }
};

long double cross(const point &a,const point &b){ return a.x*b.y-a.y*b.x; }

long double arg(const point &a){
	long double t=atan2(a.y,a.x);
	return t<0?t+2*PI:t;
}

struct line{
	point a,b;
	line(){}
	line(const point &a,const point &b):a(a),b(b){}
};

enum{CCW=1,CW=-1,ON=0};
int ccw(const point &a,const point &b,const point &c){
	long double rdir=cross(b-a,c-a);
	if(rdir>0) return CCW;
	if(rdir<0) return CW;
	return ON;
}

long double dist(const point &a,const point &b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}

const long double g=9.8;

int main(){
	int n;
	long double v; scanf("%d%Lf",&n,&v);
	point p[10000];
	rep(i,n) scanf("%Lf%Lf",&p[i].x,&p[i].y);

	long double a[9999],b[9999]; // y = a*x + b
	rep(i,n-1){
		a[i]=(p[i+1].y-p[i].y)/(p[i+1].x-p[i].x);
		b[i]=p[i].y-a[i]*p[i].x;
	}

	long double ans=dist(p[0],p[1]);
	for(int i=1;i<n-1;){
		if(ccw(p[i-1],p[i],p[i+1])!=CW){ // テ」ツつクテ」ツδ」テ」ツδウテ」ツδ療」ツ?療」ツ?ェテ」ツ??
			ans+=dist(p[i],p[i+1]);
			i++;
		}
		else{ // テ」ツつクテ」ツδ」テ」ツδウテ」ツδ療」ツ?凖」ツつ?
			long double vx=v*cos(arg(p[i]-p[i-1]));
			long double vy=v*sin(arg(p[i]-p[i-1]));
			long double x0=p[i].x,y0=p[i].y;
			for(;i+1<n;i++){
				// テヲツ鳴愿ゥツ敖「テ」ツ?ィテ」ツ?カテ」ツ?、テ」ツ?凝」ツつ凝ヲツ卍づ・ツ按サ t テ」ツつ津ヲツアツづ」ツつ?」ツつ?
				// A*t^2 + B*t + C = 0
				long double A=-g/2;
				long double B=vy-a[i]*vx;
				long double C=y0-a[i]*x0-b[i];
				if(B*B-4*A*C<0) continue;

				long double t0=(-B+sqrt(B*B-4*A*C))/(2*A);
				long double t1=(-B-sqrt(B*B-4*A*C))/(2*A);

				long double xx; // テヲツ鳴愿ゥツ敖「テ」ツ?ィテ」ツ?カテ」ツ?、テ」ツ?凝」ツつ凝、ツスツ催ァツスツョ
				xx=x0+vx*t0;
				if(p[i].x<xx && xx<p[i+1].x){ point q(xx,-g/2*t0*t0+vy*t0+y0); ans+=dist(q,p[i+1]); break; }
				xx=x0+vx*t1;
				if(p[i].x<xx && xx<p[i+1].x){ point q(xx,-g/2*t1*t1+vy*t1+y0); ans+=dist(q,p[i+1]); break; }
			}
			i++;
		}
	}

	printf("%.15Lf\n",ans);

	return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

int main(){
    int a, b;
    while(cin >> a >> b){
        int s= a+b, cnt = 0;
        while(s>0){
            s /= 10;
            cnt++;
        }
        cout << cnt << endl;
        // printf("%d\n", N);
    
    }
    return 0;
}


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

long long int dp[5001][51];
int n, a;

int x[50];

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> a;
	for(int i = 0; i < n; i++) {
		cin >> x[i];
		x[i] -= a;
	}

	for(int i = 0; i < 5001; i++) {
		for(int j = 0; j < 51; j++) {
			dp[i][j] = 0;
		}
	}

	dp[0 + 2500][0] ++;
	dp[x[0] + 2500][0] ++;


	for(int j = 1; j < n; j++) {
		for(int i = 0; i < 5001; i++) {
			dp[i][j] += dp[i][j-1];
			if(i + x[j] >= 0 && i + x[j] <= 5000) dp[i+x[j]][j] += dp[i][j-1];
		}
	}

	cout << dp[0 + 2500][n-1]-1 << endl;
	
	return 0;
}

Measured memory_bytes: 2304
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,y = I()
if n*10000 < y or n*1000 > y:
    print("-1 -1 -1")
    sys.exit()

a = -1
b = -1
c = -1

for i in range(0,n+1):
    for j in range(0,n+1):
        k = n-i-j
        if k < 0:
            continue
        if 1000*i+5000*j+10000*k == y:
            a = k
            b = j
            c = i
            break

print("{} {} {}".format(a,b,c))


Measured memory_bytes: 10392
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 10 ** 9 + 7
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rf(): return float(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]
def rf_(): return [float(_) for _ in rs().split()]
def divisors(n, sortedresult=True):
    div = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            div.append(i)
            if i != n // i:
                div.append(n//i)
    if sortedresult:
        div.sort()
    return div
# endregion
from decimal import Decimal
A, B = rs_()
ans = int(Decimal(A) * Decimal(B))
print(ans)

Measured memory_bytes: 72904
#include<stdio.h>
#include<stdlib.h>
int top=0,s[100];
void push(int);
int pop();

int main(){
  char c[100];
  int ans,popn;
  while(scanf("%s",c)!=EOF){
    ans=0;
    switch(c[0]){
    case '+':
      ans=pop();
      ans+=pop();
      push(ans);
      break;
    case '-':
      ans=(-1)*pop();
      ans+=pop();
      push(ans);
      break;
    case '*':
      ans=pop();
      ans*=pop();
      push(ans);
      break;
    default:
      push(atoi(c));
      break;
    }
  }
  printf("%d\n",pop());
  return 0;
}

void push(int x){
  s[++top]=x;
}
int pop(){
  return s[top--];
}



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

int main()
{ 
  int n, x, l, l_sum = 0, ans = 1;

  cin >> n >> x;
  for (int i = 0; i < n; i++)
  {
    cin >> l;
    l_sum += l;
    if (l_sum <= x)
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
[D,X] = list(map(int,input().split()))
A = []
for i in range(N):
    A.append(int(input()))

out=0
for i in range(N):
    j=0
    dam=0
    while True:
        dam = 1 + A[i]*j
        if dam > D:
            break
        out+=1
        j+=1
    # print(i,out)

print(X + out)


Measured memory_bytes: 63516
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

ll dp[500][500];
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() { 
  int n;
  cin >> n;
  Fill(dp,LONG_MAX);
  vl a(n), S(n+1,0);
  rep(i,n) cin >> a[i];
  rep(i,n)S[i+1] = S[i]+a[i];
  rep(i,n) dp[i][i] = 0;
  

  for(int w = 1;w<n;w++){
    for(int i =0;i+w<n;i++){
      int j = i+w;
      for(int k=i;k<j;k++){
        ll cost = S[k+1]-S[i] + S[j+1]-S[k+1];
        dp[i][j] = min(dp[i][j], dp[i][k]+dp[k+1][j]+cost);
      }
    }
  }
  cout<<dp[0][n-1]<<endl;
  return 0;
}

Measured memory_bytes: 5596
# C
import math
N = int(input())
x = [0]*N
y = [0]*N
for i in range(N):
    x[i],y[i] = map(int,input().split())
sum = 0
for i in range(N):
    for j in range(N):
        sum += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)

ans = sum/N
print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll x;
  cin >> x;

  ll div11 = x / 11;
  ll rem = x - 11 * div11;

  if(rem == 0) cout << 2 * div11 << endl;
  else if(rem <= 6) cout << 2 * div11 + 1 << endl;
  else cout << 2 * div11 + 2 << endl;
  
  return 0;
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> vecX(N), vecY(N), vecZ(M), vecW(M);
	for (int i = 0; i < N; i++)
		cin >> vecX.at(i) >> vecY.at(i);
	for (int i = 0; i < M; i++)
		cin >> vecZ.at(i) >> vecW.at(i);
	int length, point, Manhattan;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			Manhattan = abs(vecX.at(i) - vecZ.at(j)) + abs(vecY.at(i) - vecW.at(j));
			if (j == 0){
				point = 1;
				length = Manhattan;
			}
			else {
				if (Manhattan < length) {
					length = Manhattan;
					point = j + 1;
				}
			}
		}
		cout << point << endl;
	}
}

Measured memory_bytes: 256
/***************************************************************
	File name: C.cpp
	Author: huhao
	Create time: Sun 04 Aug 2019 08:05:06 PM CST
***************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=r*10+c-48;
		c=getchar();
	}
	return r*t;
}
const int N=100010;
int n,ans,a[N];
int main()
{
	ans=1;
	n=read();
	fr(i,1,n)
	{
		a[i]=read();
	}
	fd(i,n-1,1)
	{
		if(a[i]>a[i+1])
			a[i]--;
		if(a[i]>a[i+1])
			ans=0;
	}
	printf("%s\n",ans?"Yes":"No");
	return 0;
}

Measured memory_bytes: 512
using System;
 
class Program{
  static void Main(string[] args){
    string line = Console.ReadLine();
    string[] terms = line.Split(' ');
    long H = int.Parse(terms[0]);
    long W = int.Parse(terms[1]);
    if(H == 1 || W == 1){
      Console.WriteLine(1);
    }else{
      Console.WriteLine(H * W / 2 + H * W % 2);
    }
  }
}

Measured memory_bytes: 13140
s = gets.chomp

x = (0...s.size).map { |i| i.even? ? '0' : '1' }.join('')
y = (0...s.size).map { |i| i.even? ? '1' : '0' }.join('')

def diff(as, bs)
  as.split('').zip(bs.split('')).reject { |a, b| a == b }.count
end

puts [diff(s, x), diff(s, y)].min


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

using namespace std;

 

#define int long long

#define pb push_back

#define mp make_pair

#define F first

#define S second

#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)

#define REP(i,n) FOR(i,0,n)

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

#define RALL(a) (a).rbegin(),(a).rend()

#define SORT(c) sort((c).begin(),(c).end())

 

typedef long long ll;

const ll INF = 1e15+7;

const ll mod = 1e9 + 7;

const int MAX_N = 5e5 + 5;

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

vector<ll> prime;

 

ll inv[MAX_N], fac[MAX_N];

 

template <class T = ll> T in() { T x; cin >> x; return (x); }

inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }

inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }

inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }

inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }

inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

 

typedef pair<int, pair<int, int>> edge;

 

class UnionFind {

private:

	vector<int> par;

public:

	UnionFind(int N) { par = vector<int>(N, -1LL); }

	int find(int x);

	ll size(int x);

	void unite(int x, int y);

	bool same(int x, int y);

};

 

 

 

class Kruskal {

private:

	UnionFind *uf;

	vector<edge> e;

public:

	vector<edge> mst;

	Kruskal(int N) { uf = new UnionFind(N); }

	void add(int x, int y, ll z);

	void run();

};

 

 


signed main() {
	int n;
	cin >> n;
	vector<vector<int>> A(n);
	int cost[n][n];
	REP (i,n) {
		REP (j,n) {
			A[i].push_back(in());
			cost[i][j] = A[i][j];
			if (i == j) cost[i][j] = 0;
		}
	}
	pair<int,pair<int,int>> e[n * (n - 1) / 2];

	bool used[n][n];

	int po = 0;
	int ans = 0;
	REP (i,n) {

		REP (j,n) {if (i < j) {e[po].F = A[i][j];e[po].S = {i,j};po++;ans+=A[i][j];}used[i][j]=true;}

	}

	sort(e,e+n*(n-1)/2);
	//i -> j

	REP (i,n) {
		REP (j,n) {
			REP (k,n) {
				if (i != j && j != k && k != i) {
					int a = A[i][j],b = A[j][k],c = A[i][k];
					if (a + b < c) {
						cout<<-1<<endl;
						return 0;
					}
					if (a+b==c) {
						int ma = max(i,k);
						int mi = min(i,k);
						if (used[mi][ma]) {
							ans-=c;
							used[mi][ma] = false;
						}
					}
				}
			}
		}
	}
	cout << ans << endl;

}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  bool poor = false;
  if (a == b) {
    if (a != c) poor = true;
  }
  else if (b == c) {
    if (b != a) poor = true;
  }
  else if (c == a) {
    if (c != b) poor = true;
  }
  if (poor) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
n, y = gets.chomp.split.map(&:to_i)

0.upto(n) do |ichiman|
  nokori = n - ichiman
  0.upto(nokori) do |gosen|
    sen = n - ichiman - gosen
    if (10000 * ichiman + 5000 * gosen + 1000 * sen === y) 
      puts "#{ichiman} #{gosen} #{sen}"
      exit
    end
  end
end

puts '-1 -1 -1'


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

using namespace std;

const int MAX = 1e5+5;

int plans[MAX][3], dp[MAX][3];

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

    int n;
    cin >> n;

    for(int i=1; i<=n; i++)
        for(int j=0; j<3; j++)
            cin >> plans[i][j]; 

    for(int i=1; i<=n; i++){
        dp[i][0] = plans[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1] = plans[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2] = plans[i][2] + max(dp[i-1][1], dp[i-1][0]);
    }

    cout << max(max(dp[n][0], dp[n][1]), dp[n][2]) << "\n";   

    return 0;
}

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

int main(){
    int ans = 0;
    string s;
    cin >> s;

    char now = s[0];

    for(int i = 1; i < s.size(); i++){
        if(now != s[i]){
            ans++;
            now = s[i];
        }
    }

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

Measured memory_bytes: 512
#include<iostream>
#include<string>
using namespace std;
string s,t;
int main(){
  int a,b;
  cin >> a >> b;
  char c = '0'+a, d = '0'+b;
  string s,t;
  for(int i = 0;i < a;i++){
    s += d;
  }
  for(int i = 0;i < b;i++){
	t += c;
  }
  cout << min(s,t) << endl;
}
  

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

int main() {
    int a, b;
    cin >> a >> b;

    int ans = 0;
    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        if (s[0] == s[4] && s[1] == s[3]) ans++;
    }

    cout << ans << endl;
}

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

long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

long long lcm(long long a, long long b){
  long long g = gcd(a, b);
  return a / g * b;
}

int main() {
  int N;
  cin >> N;
  long long ans = 1LL;
  for(int i=0; i<N; i++){
    long long T;
    cin >> T;
    ans = lcm(ans, T);
  }
  cout << ans << endl;
  return 0;
}

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


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

	int n;	cin >> n;

	int ans = 0;

	multiset <ll> m;

	for (int i = 0; i < n; i++) {
		ll take;	cin >> take;
		m.insert(take);
	}

	while (!m.empty()) {
		auto x = *m.rbegin();
		m.erase(m.find(x));
		ll stepval = pow(2, logb(x) + 1);
		auto it = m.find(stepval - x);
		if (it == m.end())
			continue;

		m.erase(it);
		ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
using namespace std;
long long int mod_pow(int x,int n,int mod);
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b, c;
	cin >> a;
	cin >> b; 
	cin >> c;
	int d = c-a-b;
	
	unsigned long long int e= d*d;
	unsigned long long int f= 4*a*b;
	if(a+b>c){
		cout << "No";
	}else if (e>f){
		cout <<"Yes";
	}else{
		cout <<"No";
	}
 
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
using namespace std;

int main(){
	string s;
	cin >> s;
	string a="",b="";
	int center=(s.size()+1)/2;
	
	for(int i=1;i<center;i++){
			a+=s[i-1];
		}
	//cout << a << endl;
	
	for(int i=center+1;i<=s.size();i++){
			b+=s[i-1];
	}
	//cout << b << endl;
	
	if(a!=b){
		cout << "No" << endl;
		return 0;
	}	
	
	
	for(int i=0;i<=a.size()/2;i++){
		if(a[i]!=a[a.size()-1-i]){
			cout << "No" << endl;
			return 0;
		}	
		if(b[i]!=b[a.size()-1-i]){
			cout << "No" << endl;
			return 0;
		}	
	}
	
	cout << "Yes" << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    int A, B;
    cin >> A >> B;
    cout << max({A + B, A - B, A * B}) << endl;
}


Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;

int N;
int main(){
    cin>>N;
    if(N<1200)cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
    
    
    //cout<<""<<endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	Scanner sc;
	int N, K;
	String s;

	Main() {
		sc = new Scanner(System.in);
	}
	
	void calc() {
		N = sc.nextInt();
		K = sc.nextInt();
		s = sc.next();
		
		int u = 0;
		int len = s.length();
		for (int i = 1; i < len; i++)
			if (s.charAt(i-1) != s.charAt(i)) u++;
		System.out.println(Math.min(len-1-u+2*K, len-1));
	}

	public static void main(String[] args) {
		new Main().calc();
	}

}

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD =   1000000007;

int main()
{
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    string s; cin >> s;
    map<char, int> mp;
    for(int i = 0; i < 4; ++i){
        mp[s[i]]++;
    }

    int size = 0;
    bool flag = true;
    for(auto itr : mp){
        ++size;
        if(itr.second != 2){
            flag = false;
        }

    }
    if(size != 2){
        flag = false;
    }

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

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = System.Console.ReadLine().Trim();
            int iA = 0;
            int iB = 0;
            if (sS == "2")
            {
                iA = int.Parse(System.Console.ReadLine().Trim());
                iB = int.Parse(System.Console.ReadLine().Trim());
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析出力
            if (sS == "1")
            {
                System.Console.WriteLine("{0}", "Hello World".ToString().Trim());
            }
            else
            {
                System.Console.WriteLine("{0}", (iA + iB).ToString().Trim());
            }

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,i,j;
    cin>>n>>m;
    int a[n+1];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int ans[m+1];
    memset (ans , 0 ,sizeof ans);
    for(i=1;i<=m;i++)
    {
        for(j=0;j<n;j++)
        {
            if(i-a[j]>=0) 
                ans[i]=ans[i] or (not ans[i-a[j]]);
        }
    }
    if (ans[m]) cout<<"First"<<"\n";
    else cout<<"Second"<<"\n";
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> xy_t;

double dot_product(xy_t a, xy_t b){
    return (conj(a)*b).real();
}
double cross_product(xy_t a, xy_t b){
    return (conj(a)*b).imag();
}
double tri_area(xy_t o, xy_t a, xy_t b){
    return cross_product(a-o,b-o)/2;
}
xy_t projection(xy_t p, xy_t b){
    return b*dot_product(p,b)/norm(b);
}

xy_t polys[100];
int n;

double solve(){
    xy_t origin = polys[0];
    double S = 0;
    for(int i=1; i<n-1; i++){
        S += tri_area(origin, polys[i], polys[i+1]);
    }
    return abs(S);
}
signed main(){
    double x, y;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> x >> y;
        polys[i] = xy_t(x,y);
    }
    printf("%.1f\n", solve());
}


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

int main(){
  int n,k;
  cin>>n>>k;
  int a[n];
  rep(i,0,n) cin>>a[i];
  ll ans=0;
  rep(i,1,min(n,k)+1){
    rep(j,0,i+1){
      ll cur=0;
      priority_queue<int,vector<int>,greater<int>> p;
      rep(l,0,j){
        p.push(a[l]);
        cur+=a[l];
      }
      rep(l,0,i-j){
        p.push(a[n-1-l]);
        cur+=a[n-1-l];
      }
      rep(l,0,k-i){
        int x=p.top();
        if(x<0) {
          cur-=x;
          p.pop();
        }
        else break;
        if(!p.size()) break;
      }
      ans=max(ans,cur);
    }
  }
  cout<<ans<<endl;
}

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

//型定義
typedef long long ll;

//定数
const ll INF=1e+18;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

//グローバル変数


//ライブラリ挿入

int main(){
    ll N,M,L;
    cin>>N>>M>>L;
    vector<vector<ll>> cost(N,vector<ll>(N,INF));
    vector<vector<ll>> dp(N,vector<ll>(N,INF));
    REP(i,N){
        cost[i][i]=0;
    }
    REP(i,M){
        ll a,b,c;
        cin>>a>>b>>c;
        a--;
        b--;
        if(c>L) continue;
        cost[a][b]=c;
        cost[b][a]=c;
    }
    ll Q;
    cin>>Q;
    vector<ll> s(Q),t(Q);
    REP(i,Q){
        cin>>s[i]>>t[i];
        s[i]--;
        t[i]--;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (cost[i][k] + cost[k][j] < min(L+1,cost[i][j])) {
                    cost[i][j] = cost[i][k] + cost[k][j];
                }
            }
        }
    }

    REP(i,N){
        REP(j,N){
            if(cost[i][j]!=INF) dp[i][j]=0;
        }
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]+1);
            }
        }
    }
    
    REP(i,Q){
        if(dp[s[i]][t[i]]==INF) cout<<-1<<endl;
        else cout<<dp[s[i]][t[i]]<<endl;
    }



    
}

Measured memory_bytes: 6140
import java.util.Scanner;

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

	int N = sc.nextInt();
	int A[] = new int[N];
	double x = 0.0;
	for (int i = 0; i < N; i++) {
	    A[i] = sc.nextInt();
	    x += (1.0 / A[i]);
	}
	System.out.println(1.0 / x);
    }
}

Measured memory_bytes: 22356