akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int H = 2 * K;
		int W = 2 * K;
		int[][][] M = new int[2][][];
		for(int i=0;i<2;i++){
			M[i] = new int[H][];
			for(int j=0;j<H;j++){
				M[i][j] = new int[W];
			}
		}
		
		for(int i=0;i<N;i++){
			M[C[i]][Y[i] % H][X[i] % W]++;
		}
		
		var asum = new Acc[2];
		for(int i=0;i<2;i++){
			asum[i] = new Acc(H,W);
			asum[i].Init(M[i]);
		}
		
		int max = 0;
		for(int t=0;t<2;t++){
			for(int i=0;i<K;i++){
				for(int j=0;j<K;j++){
					
					int cnt0 = 0;
					cnt0 += asum[t].cal(j, i, j + K, i + K);
					cnt0 += asum[t].cal(j + K, i + K, W, H);
					cnt0 += asum[t].cal(0, 0, j, i);
					cnt0 += asum[t].cal(j + K, 0, W, i);
					cnt0 += asum[t].cal(0, i + K, j, H);
					
					int cnt1 = 0;
					cnt1 += asum[t^1].cal(j, i, j + K, i + K);
					cnt1 += asum[t^1].cal(j + K, i + K, W, H);
					cnt1 += asum[t^1].cal(0, 0, j, i);
					cnt1 += asum[t^1].cal(j + K, 0, W, i);
					cnt1 += asum[t^1].cal(0, i + K, j, H);
					
					int tt = asum[t^1].cal(0,0,W,H);
					cnt1 = tt - cnt1;
					
					max = Math.Max(max, cnt1 + cnt0);
				}
			}
		}
		
		Console.WriteLine(max);
		
		
		
		
		
		
	}
	int N,K;
	int[] X,Y,C;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		X = new int[N];
		Y = new int[N];
		C = new int[N];
		for(int i=0;i<N;i++){
			var ss = rsa();
			X[i] = int.Parse(ss[0]);
			Y[i] = int.Parse(ss[1]);
			C[i] = (ss[2][0] == 'B' ? 1 : 0);
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

class Acc{

	public Acc(int h, int w){
		H = h; W = w;
	}
	public void Init(int[][] M){
		H = M.Length;
		W = M[0].Length;
		acc = new int[H+1][];
		for(int i=0;i<=H;i++){
			acc[i] = new int[W+1];
			if(i == 0) continue;
			for(int j=1;j<=W;j++){
				acc[i][j] = M[i-1][j-1];
			}
		}
		
		for(int i=1;i<=H;i++){
			for(int j=1;j<=W;j++){
				acc[i][j] += acc[i][j-1];
			}
		}
		for(int j=1;j<=W;j++){
			for(int i=1;i<=H;i++){
				acc[i][j] += acc[i-1][j];
			}
		}
	}
	
	int H,W;
	int[][] acc;
	public int cal(int x1,int y1,int x2,int y2){
		//return num of land [x1,x2)*[y1,y2); left-inclusive / right-noninclusive;
		if(x2<x1||y2<y1)return 0;
		return acc[y2][x2]-acc[y2][x1]-acc[y1][x2]+acc[y1][x1];
	}
	





}

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

int main(){
	int n[3], x, y;
	for(int i = 0; i < 3; i++)
	cin >> n[i];
	for(int i = 0; i < 2; i++){
		for(int j = 2; j > i; j--){
			if(n[j] > n[j-1])
				swap(n[j], n[j-1]);
		}
	}
	x = n[0]*10+n[1];
	y = n[2];
	cout << x+y << endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace _1_2a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ab =Console.ReadLine().Split(' ');
            int a = int.Parse(ab[0]);
            int b = int.Parse(ab[1]);

            if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }

       
        }
    }
}



Measured memory_bytes: 15932
import java.util.Scanner;

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

              for(int i=1;i<10;i++){
                  for(int j=1;j<10;j++){
                       System.out.println(i + "x" + j + "=" + i*j);
                  }
              }
         }
   
   
   
   }

Measured memory_bytes: 25644
A, B, C, X, Y = map(int, input().split())

res = A * X + B * Y
res = min(res, C * 2 * max(X, Y))
if min(X, Y) == X:
    res = min(res, C * 2 * X + (Y - X) * B)
else:
    res = min(res, C * 2 * Y + (X - Y) * A)

print(res)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define LOOP(val, times)   for(val = 0; val < (times); val++)
using namespace std;

int main(){
    string W,i;
    vector<string> vec;
    int words=0;
    cin>>W;
    while(1<2){
    cin>>i;
        
    if(i=="END_OF_TEXT"){break;}

    for(int j=0;j<(int)i.size();++j){
    i[j] = tolower(i.at(j));
    } 
        
    if(W==i)words+=1;

    }
    
    cout<<words<<endl;
}


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

int main()
{
    int n, q;
    cin >> n >> q;
    string name[n];
    int time[n];
    int sumtime=0;

    for(int i=0; i<n; i++){
        cin >> name[i];
        cin >> time[i];
    }

    int i=0, j=0;
    int counter=0;
    while(counter!=n){
        if(time[i]>q){
            time[i]-=q;
            sumtime+=q;
            time[j]=time[i];
            name[j]=name[i];
            i++;
            j++;
        }
        else{
            sumtime+=time[i];
            cout << name[i] << ' ' << sumtime << endl;
            i++;
            counter++;
        }

        if(i==n) i=0;
        if(j==n) j=0;
    }

    return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main()
{
  ll H, W;
  cin >> H >> W;
  char s[H][W];
  rep(i,0,H){
    rep(j,0,W){
      cin >> s[i][j];
    }
  }

  bool ans = true;
  rep(i,0,H){
    rep(j,0,W){
      if (s[i][j] == '#')
      {
        if (!(s[i-1][j] == '#' || s[i+1][j] == '#' || s[i][j-1] == '#' || s[i][j+1] == '#'))
        {
          ans = false;
        }
      }
    }
  }
  if (ans)
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


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

def kyori(x,y):
    return (x-y)**2

ave=sum(X_list)//N
av2=ave+1
c1=sum([kyori(x,ave) for x in X_list])
c2=sum([kyori(x,av2) for x in X_list])
print(min([c1,c2]))


Measured memory_bytes: 3060
(a,b,c)=gets.split.map(&:to_i)
n=gets.split.map(&:to_i)
a=0
t=0
cost=0
kost=0
while t<b
 if n[t]>c
   cost+=1
 else
   kost+=1
  end
 t+=1
end
if cost<=kost
  puts cost
else
  puts kost
end



Measured memory_bytes: 1788
N = int(input())
A = [0]*(N+2)
B = [0]*N

for i,x in enumerate(input().split()):
  A[i+1] = int(x)

s = 0
for i in range(N+1):
  s += abs(A[i+1] - A[i])

for i in range(N):
  B[i] = abs(A[i+1]-A[i]) + abs(A[i+2]-A[i+1]) - abs(A[i+2]-A[i])

for i in range(N):
  print(s-B[i])


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

using namespace std;

typedef long long ll;

ll X;

ll pot5(ll v){
    return v*v*v*v*v;
}

int main(){
    //freopen("a.in","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> X;

    for (ll a = -120; a <= 120; a++)
        for (ll b = -120; b <= 120; b++){
            ll val = pot5(a) - pot5(b);
            if (val == X){
                cout << a << " " << b << "\n";
                return 0;
            }
        }
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include<vector>
#define MAXN 100001

using namespace std;

int a[MAXN];

int main()
{
    int N;
    scanf("%d",&N);
    int count2=0,count4=0;
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
        if(a[i]%2==0&&a[i]%4!=0)
            count2++;
        if(a[i]%4==0)
            count4++;
    }
    if((3+(count4-1)*2)>=(N-(count2/2*2)))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

const ll INF = 1e18;
const ll MOD = 998244353;
const ll MX = 1000001;

ll N, D, A;

void solve() {
    cin >> N >> D >> A;
    vector<l_l> a(N);
    for (auto& i : a) {
		cin >> i.first >> i.second;
		i.second = ceil(i.second / (double)A);
	}
    sort(a.begin(), a.end());
    ll dp[N + 5] = { 0 };
    ll change = 0, ans = 0;
	int r = 0;
    for (int i = 0; i < N; i++) {
		if (a[i].second + change > 0) {
			while (r < N && a[r].first - a[i].first <= 2 * D) r++;
			r--;
			ans += (a[i].second + change);
			dp[r] += (a[i].second + change);
			change -= (a[i].second + change);
		}
		change += dp[i];
	}
	cout << ans;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    ll T = 1; // cin >> T;
    while (T--) solve();
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


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

int main()
{
    int n;
    while(cin>>n)
    {
        string a,b;
        cin>>a>>b;
        string ans="";
        for(int i=0;i<n;i++)
        {
            ans=ans+a[i]+b[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.math.*;
class Main{
	public static void main(String[]z){
		BigInteger b=BigInteger.ONE;
		int i=2,n=new java.util.Scanner(System.in).nextInt();
		for(;i<1501;i++)b=b.multiply(new BigInteger(String.valueOf(i)));System.out.println(b.add(new BigInteger("2")));
		for(i=0;i<n;i++)System.out.println(i+2);
	}
}

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

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

    ll n, m;
    cin >> n >> m;

    ll res = 0;
    if (2 * n >= m) {
        res = m / 2;
    } else {
        res = n + ((m - 2 * n) / 4);
    }

    cout << res << '\n';
    return 0;
}


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


int N,i,j;

int L[2010];


int bsearch (int a)
{


	int l=0;
	int r=N;

	while(r-l>1)
		{
			
			int mid=(r+l)/2;

			if(L[mid]>=a)
				r=mid;

			else
				l=mid;

		}

		return r;

}

int main(void)
{

	cin >> N;


	for(i=0;i<N;i++)
	{
		
		cin >> L[i];

	}
   
	sort(L,L+N);

	int ans=0;

	for(i=0;i<N;i++)
	{
		for(j=i+1;j<N;j++)
		{

			int index=bsearch(L[i]+L[j]);

			ans=ans+(index-j-1);

		}

	}
	
	cout << ans << endl;

}



Measured memory_bytes: 256
1729
s = int(raw_input())
mem = {}
def f(s):
	mod = 10 ** 9 + 7
	if s in mem:
		return mem[s]
	if s == 0:
		return 1
	r = 0
	for ii in range(3, s+1):
		r+= f(s-ii)
		r %= mod

	mem[s] = r % mod
	return r
print f(s)

Measured memory_bytes: 73232
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    x,y = LI()
    ans = 1
    for i in range(10000000000000):
        x *= 2
        if x > y:break
        ans += 1
    print(ans)

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int h, w;
  cin >> h >> w;
  vector<vi> g(h + 2, vi(w + 2, 0));
  rep2(i, 1, h + 1) rep2(j, 1, w + 1) {
    char c;
    cin >> c;
    if(c == '#') g[i][j] = -1;
  }
  rep2(i, 1, h + 1) {
    rep2(j, 1, w + 1) {
      if(g[i][j] == -1) {
        cout << '#';
        continue;
      }
      rep(k, 8) {
        int ni = i + dir[k];
        int nj = j + dir[k + 1];
        if(g[ni][nj] == -1) g[i][j]++;
      }
      cout << g[i][j];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
def main():
    S = input()
    cnt = 0
    max_cnt = 0
    for s in S:
        if s == 'A' or s=='T' or s=='G' or s=='C':
            cnt += 1
        else:
            cnt = 0
        if max_cnt <= cnt:
            max_cnt = cnt
    print(max_cnt)
    return 0

main()


Measured memory_bytes: 2940
#include <iostream>
    #include <string>
    #include <vector>
    using namespace std;
     
    const int MAX = 200010;
     
    int main() {
      string s;
      cin >> s;
     
      vector<unsigned long long> ans(s.size(), 0);
      vector<unsigned long long> rec(26, 0);
     
      ans[0] = 1;
      rec[s[0] - 'a'] = 1;
      for (int i = 1; i < s.size(); ++i) {
        ans[i] = ans[i - 1];
        ans[i] += (i - rec[s[i] - 'a']);
     
        rec[s[i] - 'a']++;
      }
      cout << ans.back() << endl;
    }

Measured memory_bytes: 2180
function main(){
  var i = 0;
  while(true){
    var fieldInfo = input[i].split(' ');
    var width = fieldInfo[0] - 0;//toInt
    var height = fieldInfo[1] - 0;//toInt
 
    // 0 0が入力された
    if(!width && !height){
      break;
    }
 
    var start;
    var goal;
    var elem = [[],[],[],[],[]];
    for(var ei = 0;ei < 5; ei++){
      elem[ei].length = 0;
    }
     
    for(var y = 0; y < height; y++){
      i++;//1行進める
      for(var x = 0; x < width; x++){
        var c = input[i][x];
 
        switch(c){
        case 'S':
          start = pos(x, y);
          break;
        case 'G':
          goal = pos(x, y);
          break;
        case '.':
          break;
        default : // 入力値が正しいので、絶対に属性
          elem[c - 1][elem[c - 1].length] = pos(x, y);
          break;
        }
      }
    }
 
     
    var bestElement = -1;
    var distance = Infinity;
     
    // 属性ごとにループ
    for (var startElem = 0; startElem < 5; startElem++) {
      // DPの初期化 DP[属性][同じ属性内の連番]
      var dp = [[],[],[],[],[]];
      for(var h = 0; h < 5; h++){
        var hLength = elem[h].length;
        dp[h].length = hLength;
        for(var hidx = 0; hidx < hLength; hidx++){
          dp[h][hidx] = Infinity;
        }
      }
       
      // 最初に選んだパチモンから次に捕まえられる属性番号
      var first = (startElem + 1) % 5;
 
      var firstLength = elem[first].length;
      for (var j = 0; j < firstLength; j++) {
        // s→e1を計算
        dp[first][j] = dist(start, elem[first][j]);
      }
       
      // s->1->2->3->4->g
      // なので、ループは間の-> * 3分まわす
      for (var e = 0; e < 3; e++) {
        // ex->e(x+1)
        var now = (first + e) % 5;
        var next = (now + 1) % 5;
        var nowLength = elem[now].length;
        var nextLength = elem[next].length;
        for (var j = 0; j < nowLength; j++) {
          for (var k = 0; k < nextLength; k++) {
            dp[next][k] = fmin(
              dp[next][k],
              dp[now][j] + 
                  dist(elem[now][j], elem[next][k]));
          }
        }
      }
       
      var last = (first + 3) % 5;
      var lastLength = elem[last].length;
      for (var j = 0; j < lastLength; j++) {
        // e4->g
        var d = dp[last][j] + 
                    dist(elem[last][j], goal);
         
        if (d < distance) {
          distance = d;
          bestElement = startElem + 1;
        }
         
      }
       
    }
     
    if (distance == Infinity) {
      console.log("NA");
    } else {
      console.log(bestElement + " " + distance);
    }
 
    i++;
  }
   
 
}
 
function dist(from, to){
  return fabs((from >> 11) - (to >> 11)) + fabs((from & 2047) - (to & 2047));
}
 
function fmin(a1, a2){
  var t = (a1 - a2);
  return a2 + (t & (t >> 31));
}
 
function pos(a, b){
  // 2^10 = 1024なので、下位10ビットでy座標を、上位ビットでx座標を表す
  return (a << 11) + b;
}

function fabs(a){
 var mask = a >> 31;
 return (a ^ mask) - mask;
}
 
var
input = '';
 
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});

Measured memory_bytes: 65284
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a*b > c*d){
        cout << a*b << endl;
    }else{
        cout << c*d << endl;
    }
    return 0;
}

Measured memory_bytes: 764
n,m=map(int,input().split())
al=set([int(input()) for i in range(m)])
mod=1000000007
ansl=[0,1]
for i in range(1,n+1):
    if i in al:
        ansl.append(0)
    else:
        ansl.append((ansl[-2]+ansl[-1])%mod)
print(ansl[-1]%mod)

Measured memory_bytes: 13192
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		ArrayList<Integer> A = new ArrayList<Integer>();
		for(int i = 0; i < N; i ++) {
			A.add(stdIn.nextInt());
		}
		Collections.sort(A, Comparator.reverseOrder());
		long ans = 0;
		ans += A.get(0);
		for(int i = 2; i < N; i ++) {
			double idx = i;
			ans += A.get((int) Math.floor((double) idx/2));
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 65448
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 11:47:51 2020

@author: shinba
"""

n = int(input())

data = {}
ans = 0

for x in map(int,input().split()):
    if not x in data:
        data[x] = 1
    else:
        if data[x] < x:
            data[x] += 1
        else:
            ans += 1

for i,j in data.items():
    if i == j:
        continue
    ans += j
    
print(ans)


Measured memory_bytes: 27028
# -*- coding: utf-8 -*-
N, H = map(int, input().split(" "))
a = []
b = []

for i in range(N):
  c, d = map(int, input().split(" "))
  a.append(c)
  b.append(d)
  
amax = max(a)
b.sort()
b.reverse()
bf = [x for x in b if x > amax]

count = 0
judge = 0
for i in bf:
    H -= i
    if H <= 0:
        judge = 1
        count += 1
        print(count)
        break
    count += 1

if judge != 1:
    sho = H//amax
    amr = H%amax
    if amr != 0:
        sho += 1
    print(count+sho)

Measured memory_bytes: 11952
/*
    @uthor: Amit Kumar
    user --> CodeChef: dr_virus_ ; Codeforces,AtCoder,Hackerearth,Hakerrank: dr_virus;
*/
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//#define ln mp::cpp_int;
#define ll    long long
#define ld    long double
#define ull   unsigned long long
#define endl "\n"
ll google_itr = 1;
#define google(x) cout<<"\Case #"<<x<<"\:"
#define pi 3.14159265358979323846264338327950L

const ll mod = 1e9+7;
const ll inf = 1e18;

ll popcount(ll num){
    num = num - ((num >> 1) & 0x55555555);
    num = (num & 0x33333333) + ((num >> 2) & 0x33333333);
    return ((num + (num >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}


void virus(){
        ll nodes, vertices;
        cin>>nodes>>vertices;

        vector<ll> adj[nodes+1];

        for(auto i=0;i<vertices; i++){
            ll scr, dest;
            cin>>scr>>dest;
            adj[scr].push_back(dest);
            adj[dest].push_back(scr);
        }

        queue<ll> q;
        vector<bool> visited(nodes+1);
        vector<ll> res(nodes+1);

        q.push(1);
        visited[1] = true;
        while(!q.empty()){
            ll val = q.front();
            q.pop();
            for(auto i:adj[val]){
                if(!visited[i]){
                    q.push(i);
                    visited[i] = true;
                    res[i] = val;
                }
            }
        }
        cout<<"Yes\n";
        for(auto i=2;i<=nodes; i++) cout<<res[i]<<"\n";
}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/

    ll t = 1;
    //cin>>t;
    while(t--){
           auto start = high_resolution_clock::now();
           virus();
           auto stop = high_resolution_clock::now();
           auto duration = duration_cast<seconds>(stop - start);
         //cout << "Time: "<<duration.count()<<endl;
        //your code goes here
    }
    return 0;
}

Measured memory_bytes: 12944
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    ll res = 1e+15;
    for(ll i=1;i*i<=n;i++) {
        if(n%i==0) {
            chmin(res, i+n/i-2);
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

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

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

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;

	int n;
	cin >> n;
	cout << (n - 2) * 180 << rt;

	please AC;
}
//参考：---

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

#define repd(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

template <typename T>
void output(T a,int precision){
	if(precision > 0){
		cout << setprecision(precision) << a << "\n";
	}else{
		cout << a << "\n";
	}
}

int main(){
	//source
	int n,k;
	cin >> n >> k;
	vector<int> h;
	inputVector(&h,n);
	sort(h.begin(),h.end());
	int min_value=pow(10,9);
	rep(i,n-k+1){
		min_value=min(h[i+k-1]-h[i],min_value);
	}
	cout << min_value << endl;
	return 0;
}


Measured memory_bytes: 892
package main

import (
	"fmt"
)

func main()  {
	var input string

	_, _ = fmt.Scan(&input)

	isSimmilarToCoffee := IsSimilarToCoffee(input)

	if isSimmilarToCoffee{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}

func SwapNumbers(num1 int, num2 int) (int, int){
	return num2, num1
}

func IsSimilarToCoffee(str string)bool{
	return str[2] == str[3] && str[4] == str[5]
}

Measured memory_bytes: 512
from sys import stdin

N = int(stdin.readline().rstrip())
V = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().split()]

res = 0

for i in range(N):
    res = max(res, res+(V[i]-C[i]))

print(res)

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include "iomanip"

using namespace std;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    set<int> set;
    set.insert(m);
    set.insert(n);
    set.insert(x);
    cout << set.size();
    return 0;
}


Measured memory_bytes: 256
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int dp[2][110],ma[2][110];
int main()
{
	memset(dp,0,sizeof(dp));
	int n;
	cin>>n;
	rep(i,2) rep(j,n) cin>>ma[i][j];
	rep(i,2) rep(j,n){
		if(i>0) dp[i][j]=max(dp[i][j],dp[i-1][j]);
		if(j>0) dp[i][j]=max(dp[i][j],dp[i][j-1]);
		dp[i][j]+=ma[i][j];
	}
	cout<<dp[1][n-1]<<endl;
}


Measured memory_bytes: 256
import collections

n =int(input())
a = list(map(int,input().split()))
s = [0]
for i in range(n):
    s.append(s[i]+a[i])

cs = list(collections.Counter(s).values())
res = 0
for scs in cs:
    res += scs * (scs-1)//2

print(res)

Measured memory_bytes: 41696
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
  int n,x,m[110];
  cin >> n >> x;
 
  int sum = 0;
  int mi = 1100;
  for(int i = 0; i < n; i++) {
    cin >> m[i];
    sum += m[i];
    mi = min(mi, m[i]);
  }
  
  int res = x - sum;
  cout << n + res/mi << endl; 
}

Measured memory_bytes: 3608
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	int n,c=0;
	int a[101010]={};
	cin>>n;
	FOR(i,0,n){
		cin>>a[i];
	}
	int now=-1,r=0;
	sort(a,a+n);
	FOR(i,0,n){
		if(now==a[i]){
			r^=1;
		}else{
			c+=r;
			now=a[i];
			r=1;
		}
		//cout<<" "<<r<<endl;
	}
	c+=r;
	cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 640
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (N, A, B) = nextIntList()
    println(Math.min(N * A, B))
}

Measured memory_bytes: 36428
#pragma warning(disable: 4996)
#define _USE_MATH_DEFINES
#include <iostream>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
using namespace std;

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

	int N;
	cin >> N;
	bool ans = false;
	for (int i = 1; i <= 9; i++) {
		for (int j = 1; j <= 9; j++) {
			if ((i * j) == N) ans = true;
		}
	}

	if (ans) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
int n, m, q, cnt[N];
char s[N];
ll ans;
int main() {
	cin >> n;
	scanf("%s", s + 1);
	for (int i = 1; i <= n; ++i) cnt[s[i] - 'a']++;
	ans = 1;
	for (int i = 0; i < 26; ++i) {
		if (cnt[i] == 0) continue;
		ans = ans + ans * cnt[i] % mod;
		ans %= mod; 
	}
	(ans += mod - 1) %= mod;
	cout << ans; 
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>

int t,n,m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	double d,t,sp;
	cin >> d >> t >> sp;
	if (d/sp < t+1e-9) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
  int k, n;
  cin >> k >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  a.push_back(a[0]+k);
  int l = 0;
  rep(i,n) {
    l = max(l, a[i+1]-a[i]);
  }
  int ans = k-l;
  cout << ans << endl;
  return 0;
}


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

int main() {
	int a = 0;
        int b = 0;
        int c = 0;

	cin >> a >> b >> c;
if(a >= 0 && a <= 10000 && a <= 10000 && b >= 0 && b <=10000 && c >= 0 && c <= 10000){

	if (a <= b&&b <= c&&a <= c) {
		cout << a << " " << b << " " << c << endl;
	}
	else if (a <= b && b >= c && a <= c) {
		cout << a << " " << c << " " << b << endl;
	}
	else if (a >= b && b <= c && a <= c) {
		cout << b << " " << a << " " << c << endl;
	}
	else if (a >= b && b <= c && a >= c) {
		cout << b << " " << c << " " << a << endl;
	}
	else if (a >= b && b >= c && a >= c) {
		cout << c << " " << b << " " << a << endl;
	}
	else if (a <= b && b >= c && a >= c) {
		cout << c << " " << a << " " << b << endl;
	}

}	return 0;

}


Measured memory_bytes: 3076
def dist(a,b)
  if a >= 0
    b
  elsif b <= 0
    -a
  else
    zab = b - 2 * a
    zba = b * 2 - a
    zab < zba ? zab : zba
  end
end

N,K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
ans = (0 .. N - K).inject((A.first.abs + A.last.abs) * 2) do |s, i| 
  x = dist(A[i], A[i + K- 1])
  x < s ? x : s 
end
puts ans



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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

void fcn(ll &a, ll &b){
	cout << a << " " << b << endl;
	a-=b;
	return;
}

int main(){
	int n;
	cin >> n;
	ll a[n];
	for(int i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);

	ll m=0;
	if(a[0]>=0){
		m=-a[0];
		for(int i=1; i<n; i++) m+=a[i];
		cout << m << endl;

		for(int i=1; i<n-1; i++) fcn(a[0], a[i]);
		fcn(a[n-1], a[0]);
	}else if(a[n-1]<=0){
		m=a[n-1];
		for(int i=0; i<n-1; i++) m-=a[i];
		cout << m << endl;

		for(int i=n-2; i>=0; i--) fcn(a[n-1], a[i]);
	}else{
		int k=0;
		for(int i=0; i<n; i++){
			if(a[i]>=0) m+=a[i];
			else{
				m-=a[i];
				k++;
			}
		}
		cout << m << endl;

		for(int i=k; i<n-1; i++) fcn(a[0], a[i]);
		fcn(a[n-1], a[0]);
		for(int i=1; i<k; i++) fcn(a[n-1], a[i]);
	}
	return 0;
}

Measured memory_bytes: 2688
#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 all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

// int f(char c){
//     if(c=='R') {
//         return 0;
//     }
//     if(c=='G') {
//         return 1;
//     }
//     if(c=='B') {
//         return 2;
//     }
// }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    string s;cin>>s;
    vector<ll> r(n),g(n),b(n);
    if(s[0]=='R') {
        r[0]=1;
    }
    if(s[0]=='G') {
        g[0]=1;
    }
    if(s[0]=='B') {
        b[0]=1;
    }
    for(int i=1;i<n;i++){
        if(s[i]=='R') {
            r[i]=r[i-1]+1;
            g[i]=g[i-1];
            b[i]=b[i-1];
        }
        if(s[i]=='G') {
            r[i]=r[i-1];
            g[i]=g[i-1]+1;
            b[i]=b[i-1];
        }
        if(s[i]=='B') {
            r[i]=r[i-1];
            g[i]=g[i-1];
            b[i]=b[i-1]+1;
        }
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        char t = s[i];
        for(int j=i+1;j<n;j++){
            if(s[j]==t) continue;
            char u = s[j];
            char m;
            if((t=='R' && u=='G') || (t=='G' && u=='R' )) {
                m='B';
                ans += b[n-1]-b[j];
            }
            if((t=='G' && u=='B') || (t=='B' && u=='G')) {
                m='R';
                ans += r[n-1]-r[j];
            }
            if((t=='R' && u=='B') || (t=='B' && u=='R')){
                m='G';
                ans += g[n-1]-g[j];
            }
            if(j+(j-i)<n && s[j+(j-i)] == m) ans--;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using pii = pair<int,int>;
using pll = pair<long,long>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back

vll rem(1e5+5,0),vec(1e5+5,0);

int main() {
  ll n,x,m,first=0,period=0;
  cin>>n>>x>>m;
  ll sum=0,ans=0;
  bool found=false;

  for(ll i=1;i<=m-1;i++) {
    rem[i]=x;
    if(vec[x]!=0&&!found) {
      first=vec[x];
      period=i-first;
      found=true;
    }
    vec[x]=i;
    x*=x;
    x%=m;
  }
  if(found) {
    for(ll i=first;i<=first+period-1;i++) sum+=rem[i];
  } else {
    if(m==1) {
      ans=0;
    } else {
      for(ll i=1;i<=m-1;i++) sum+=rem[i];
      ans+=sum*(n/(m-1));
      n%=(m-1);
      for(ll i=1;i<=n;i++) ans+=rem[i];
    }
    cout<<ans<<endl;
    return 0;
  }

  if(n<=first) {
    for(ll i=1;i<=n;i++) ans+=rem[i];
  } else {
    for(ll i=1;i<=first-1;i++) ans+=rem[i];
    n-=first-1;
    ans+=sum*(n/period);
    n%=period;
    for(ll i=first;i<=first+n-1;i++) ans+=rem[i];
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 4620
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

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

    double ans = (n / 3.0) * (n / 3.0) * (n / 3.0);

    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#define ll long long
#define N 200005
using namespace std;
int n,x,y;
struct pi{
	ll a,b;
	pi(){};
	pi(ll _a,ll _b){
		a=_a;b=_b;
	}
}tmp[N];
vector<pi>h[N];
struct pl{int l,r,lv,rv;}s[N];
void add(int a,int b,int c){
	if(s[a].l==0) s[a].l=b,s[a].lv=c;
	else s[a].r=b,s[a].rv=c;
}
bool cmp(const pi &A,const pi &B){return A.a<B.a||A.a==B.a&&A.b<B.b;} 
void dfs(int a,int fa,ll v,int w){
	if(s[a].l==0){h[a].push_back(pi(w,w));return;}
	else dfs(s[a].l,a,v,s[a].lv),dfs(s[a].r,a,v,s[a].rv);
	if(h[s[a].l].size()>h[s[a].r].size()) swap(s[a].l,s[a].r),swap(s[a].lv,s[a].rv);
	int l=0,top=0;
	for(int i=0;i<h[s[a].l].size();i++){
		while(l<h[s[a].r].size()&&h[s[a].r][l].a+h[s[a].l][i].b<=v) l++;
		if(l!=0) top++,tmp[top]=pi(h[s[a].l][i].a+w,h[s[a].r][l-1].b+w);
	}
	int tip=top;
	for(int i=1;i<=tip;i++)
		if(tmp[i].a!=tmp[i].b) top++,tmp[top]=pi(tmp[i].b,tmp[i].a);
	sort(tmp+1,tmp+1+top,cmp);
	if(top!=0) h[a].push_back(tmp[1]);
	for(int i=2;i<=top;i++)
		if(tmp[i].b<h[a][h[a].size()-1].b) h[a].push_back(tmp[i]);
}
int main()
{
	//freopen("cc.in","r",stdin);
	//freopen("cc.out","w",stdout);
	scanf("%d",&n);
	for(int i=2;i<=n;i++) scanf("%d%d",&x,&y),add(x,i,y);
	ll l=0,r=1e10;
	while(l+1<r){
		ll mid=(l+r)/2;
		for(int i=1;i<=n;i++) h[i].clear();
		dfs(1,0,mid,0);
		if(h[1].size()!=0) r=mid;else l=mid;
	}
	for(int i=1;i<=n;i++) h[i].clear();
	dfs(1,0,l,0);if(h[1].size()!=0) r--;else l++;
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 32888
/* ex2-4
    kas056*/

#include<stdio.h>
#define SIZE 15


int main(void){
    char sentence[SIZE];
    char *p;
    int length = 0;
    int maxlen = 0;

    scanf("%s", sentence);

    p = sentence;//ポインタを連結

    //ヌル文字に到達するまで操作を行う
    while(*p){
        //該当する文字があったらカウント開始。
        if(*p == 'A' || *p == 'C' || *p == 'G' || *p == 'T'){
            length++;
        }
        else{//該当するものが続かなければ、カウントをリセットする。
            length = 0;
        }

        if(length > maxlen){
            maxlen = length;//最高記録を超えたら更新
        }

        p++;//次の文字に進む
    }

    printf("%d", maxlen);

    return 0;

}

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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
vector<vector<ii>> adj;
vector<ii> res;

vi e;

lli p2[55];


int dfs(int v, int tar, int par = -1) {
  if(v == tar) return 1;
  int flag = 0;
  for(auto x: adj[v]) {
    if(x.fi == par) continue;
    if(dfs(x.fi, tar, v)) {
      flag = 1;
      e[x.se] = 1;
    }
  }
  return flag;
}


int solve(int mask) {
  e.clear();
  e.resize(SZ(adj));
  rep(i,0,SZ(res)) {
    if(mask & (1<<i)) {
      dfs(res[i].fi, res[i].se, -1);
    }
  }
  int cnt = 0;
  rep(i,0,SZ(adj)-1) if(e[i] == 1) cnt++;
  return cnt;
}


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  preprocess();
  int n;
  cin>>n;
  adj.resize(n+1, vector<ii>(0));
  rep(i,0,n-1) {
    int a, b; cin>>a>>b;
    adj[a].pb({b, i});
    adj[b].pb({a, i});
  }
  int m; cin>>m;
  rep(i,0,m) {
    int u, v; cin>>u>>v;
    res.pb({u, v});
  }
  p2[0] = 1;
  rep(i,1,n+2) p2[i] = (p2[i-1] * 2);
  lli ans = 0;
  rep(mask, 0, (1<<m)) {
    int c = __builtin_popcount(mask);
    int p = solve(mask);
    if(c % 2 == 0) ans += p2[n-1-p];
    else ans -= (p2[n-1-p]);
  }
  cout<<ans<<endl;
}



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

int main(){
    int i, j;
    char s[20];
    int strl;
    int ans=0;
    int cnum=0;
    int strlarge = 0;

    scanf("%s", s);
    strl = strlen(s);

    if(s[0] != 'A'){
        ans = 1;
    }
    for(i=2; i<strl-1; i++){
        if(s[i]=='C'){
            cnum +=1;
        }
    }
    if(cnum!=1){
        ans =1;
    }

    for(i=0; i<strl; i++){
        if( 65 <= s[i] && s[i] <= 90){
            strlarge += 1;
        }
    }

    if(strlarge != 2){
        ans =1;
    }

    if(ans == 1){
        printf("WA");
    }else{
        printf("AC");
    }

    return 0;
}

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

vector<bool> sf(11);
int main(void){
	int N,M,ans = 0;
	cin >> N >> M;
	int k[15],s[15][15],p[15];
	for(int i=0;i<M;i++){
		cin >> k[i];
		for(int j=0;j<k[i];j++){
			cin >> s[i][j];
			s[i][j]--;
		}
	}
	for(int i=0;i<M;i++)cin>>p[i];
	
	for(int i=0;i< 1<<N;i++){
		fill(sf.begin(),sf.end(),false);
		for(int j=0;j<N;j++){
			if((i>>j)&1){
				sf[j] = true;
			}
		}
		bool flag = true;
		for(int j=0;j<M;j++){
			int cnt = 0;
			for(int a=0;a<k[j];a++){
				if(sf[s[j][a]]==true)cnt++;
			}
			if(cnt%2 == p[j]){
			}else{
				flag = false;
				break;
			}
		}
		if(flag)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int N;
    cin>>N;
    vector<int> a;
    vector<long long> s(N+1);
    s[0]=0;
    rep(i,N){
        int t;
        cin>>t;
        a.push_back(t);
        s[i+1]=t+s[i];
    }
    //s[N]=総和
    long long ans=LLONG_MAX;
    rep2(i,1,N){
        ans=min(ans,abs((s[N]-s[i])-s[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5776
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


class sp_t
{
public:
	char s[10+2];
	int p;
	int n;
	bool operator<(const sp_t&rhs) const
	{
		int c=strcmp(s, rhs.s);

		if(c)
		{
			return c<0;
		}
		return p>rhs.p;
	}
};


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vector<sp_t> sp(n);

		for(int i=0;i<n;i++)
		{
			scanf("%s%d", sp[i].s, &sp[i].p);
			sp[i].n=i+1;
		}
		sort(sp.begin(), sp.end());
		for(auto&msp:sp)
		{
			printf("%d\n", msp.n);
		}
	}
	return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
 
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979
#define MAXI 7500000

//.size()はunsigned int　0-1をするとオーバーフローする
 
using namespace std;
typedef long long int ll;
typedef pair< long long int , long long int> P;

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

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

struct edge{long long int to;
long long int cost;};

 
int main(void){

	int a,b;

	cin>>a>>b;

	if(a>=13){
		cout<<b<<endl;
	}else  if(a>=6){
		cout<<b/2<<endl;
	}else{
		cout<<0<<endl;
	}

}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
struct edge
{
	int v,nxt;
}e[500005];
int n,h[100005],t,f[100005],a[100005],size[100005],tans=1e9;
char s[100005];
void add(int u,int v)
{
	e[++t].v=v;
	e[t].nxt=h[u];
	h[u]=t;
}
void dfs(int u,int fa)
{
	size[u]=s[u]-'0';
	a[u]=0;
	int mx=0,id=0;
	for(int i=h[u];i;i=e[i].nxt)
	{
		int v=e[i].v,nw;
		if(v==fa) continue;
		dfs(v,u);
		size[u]+=size[v];
		nw=size[v]+a[v];
		if(nw>mx) id=v,mx=nw;
		a[u]+=nw;
	}
	if(mx<=a[u]-mx) f[u]=a[u]/2;
	else f[u]=a[u]-mx+min((2*mx-a[u])/2,f[id]);
	if(!fa&&a[u]==f[u]*2) tans=min(tans,f[u]);
}
int main()
{
	scanf("%d%s",&n,s+1);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
	}
	for(int i=1;i<=n;i++)
		dfs(i,0);
	if(tans==1e9) printf("-1");
	else printf("%d",tans);
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
#include <time.h>
#include<stdlib.h>
#include<string.h>

void swap(int* x, int* y) {
	int tmp;

	tmp = *x;
	*x = *y;
	*y = tmp;
}

void sort(int array[], int n) {
	int i, j;
	for (i = 0; i < n - 1; i++) {
		for (j = n - 1; j >= i + 1; j--) {
			if (array[j] < array[j - 1]) {
				swap(&array[j], &array[j - 1]);
			}
		}
	}
}

int main(void) {
	float v[1000], max = 0;
	int n, i;

	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%f", &v[i]);
	}

	sort(v, n);

	for (i = 0; i < n - 1; i++) {
		if (i == 0) {
			max += (v[i] + v[i + 1]) / 2;
		}
		else {
			max = (max + v[i + 1]) / 2;
		}
	}
	printf("%f", max);
}

Measured memory_bytes: 1740
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
char S[100001];
char ans[600000];
#define OFFSET (200000)

int main()
{
  int Q;
  scanf("%s", S);
  cin >> Q;
  int len = strlen(S);
  memcpy(&ans[OFFSET], S, len);

  int left = OFFSET - 1;
  int right = OFFSET + len;

  bool rev = false;
  for (int i = 0; i < Q; i++) {
    int T, F;
    char c;
    cin >> T;
    if (T==1) {
      rev = !rev;
    } else {
      cin >> F >> c;
      if (F==1) {
        if (rev) {
          ans[right++] = c;
        } else {
          ans[left--] = c;
        }
      } else {
        if (rev) {
          ans[left--] = c;
        } else {
          ans[right++] = c;
        }
      }
    }
  }
  if (rev) {
    for (int i = right-1; i > left; i--) {
      putchar(ans[i]);
    }
  } else {
    for (int i = left+1; i < right; i++) {
      putchar(ans[i]);
    }
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 896