akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
//#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)

ll N,M;
string s1,s2;
ll g1[2001],g2[2001];
ll dp[2001][2001][2];
ll ans=0;
int main()
{
	cin>>N>>M>>s1>>s2;
	rep(i,N+1) rep(j,M+1) dp[i][j][1]=-1;
	rep(i,N) if(s1[i]=='I') g1[i+1]=1;
	rep(i,M) if(s2[i]=='I') g2[i+1]=1;
	dp[0][0][0]=0;
	
	/*if(g1[0]&&g2[0]){
		dp[0][0][1]=1;
	}
	if(g1[0]&&(!g2[0])){
		dp[0][0][1]=1;
		dp[0][0][0]=2;
	}
	if((!g1[0])&&g2[0]){
		dp[0][0][1]=1;
		dp[0][0][0]=2;
	}*/
	
	rep(i,N+1){
		rep(j,M+1){
			if(i>0){ if(g1[i]){
				dp[i][j][1]=max(dp[i][j][1],dp[i-1][j][0]+1);
			}
			else{
				if(dp[i-1][j][1]!=-1){
					dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][1]+1);
				}
			} }
			if(j>0){ if(g2[j]){
				dp[i][j][1]=max(dp[i][j][1],dp[i][j-1][0]+1);
			}
			else{
				if(dp[i][j-1][1]!=-1){
					dp[i][j][0]=max(dp[i][j][0],dp[i][j-1][1]+1);
				}
			} }
		}
	}
	ans=0;
	rep(i,N+1) rep(j,M+1) ans=max(ans,dp[i][j][1]);
	cout<< ans <<endl;
}


Measured memory_bytes: 65808
N,x=map(int,input().split())
A=[int(x) for x in input().split()]
dp=A[:]

#dp[i]:k回魔法を唱えた時にA[i]を手に入れる最小の時間。
#dp=Aで初期化。その後、１〜Nまでの各ステップでdp[i]はmin(dp[i],A[i-k])で順に更新されていく。
#各回におけるsum(dp)+k*xを算出して最小値が答え。

#ans初期値は魔法を唱えず、全てを入手した数字（sum(A))
ans=sum(A)
for k in range(1,N):
  for i in range(N):
    if dp[i]>A[i-k]:
      dp[i]=A[i-k]
  ans=min(ans,sum(dp)+x*k)

print(ans)


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll a,b,c,d,n;cin>>a>>b>>c>>d>>n;
  ll mi=min({4*a,2*b,c});

  if(d<2*mi){
    if(n%2==0)out(n/2*d);
    else out(n/2*d+mi);
  }
  else out(n*mi);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>

int SumOfDigit(int n) {

	int sum = 0;
	while (n > 0) {

		sum += n % 10;
		n /= 10;
	}

	return sum;

}


int main() {

	int N;
	std::cin >> N;

	int f = SumOfDigit(N);

	if (N % f == 0) std::cout << "Yes" << std::endl;
	else std::cout << "No" << std::endl;

}

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

int main()
{
    double x1, y1, x2, y2, distance;
    scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
    distance = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
    printf("%.4lf", distance);
    return 0;
}


Measured memory_bytes: 2688
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
#define MAXN 100002
 
int n;
int a[MAXN];
int fron[MAXN];
int bak[MAXN];
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d",&a[i]);
	sort(a,a+n);
	
	fron[0] = a[0];
	for (int i=1;i<n;i++){
		fron[i] = __gcd(a[i], fron[i-1]);
	}
	
	bak[n-1] = a[n-1];
	for (int i=n-1;i>0;i--){
		bak[i-1] = __gcd(a[i-1], bak[i]); 
	}
	int maxi = max(fron[n-2], bak[1]);
 
	for (int i=1;i<n-1;i++){
		maxi = max(maxi, __gcd(fron[i-1], bak[i+1]));
	}
	printf("%d\n",maxi);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  if((c - a - b) * (c - a - b) > 4 * a * b && c - a - b > 0){
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << "No" <<endl;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  
 if ( A == B && B != C ){
    cout << "Yes" << endl;
  }
  else if ( B == C && B != A ){
    cout << "Yes" << endl;
  }
  else if ( A == C &&  B != A ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
    
int main(){
  int n;
  cin >> n;
  bool can = false;
  rep(i,26){
    rep(j,26-i){
      if(n == 4*i + 7*j) can = true;
    }
  }
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

int main() {
    long n;
    std::cin >> n;
    if(0 == n%2){
        cout <<  (n/2)*(n-1) << endl;
    }else{
        cout <<  ((n-1)/2)*(n) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
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 s = ten(a)+ten(b)+ten(c)+ten(d)+ten(e);
    char t='a';
    int m=(a-1)%10;
    if(m>(b-1)%10){t='b';m=(b-1)%10;}
    if(m>(c-1)%10){t='c';m=(c-1)%10;}
    if(m>(d-1)%10){t='d';m=(d-1)%10;}
    if(m>(e-1)%10){t='e';m=(e-1)%10;}
    switch(t){
      case 'a':
        m=a-ten(a);break;
      case 'b':
        m=b-ten(b);break;
      case 'c':
        m=c-ten(c);break;
      case 'd':
        m=d-ten(d);break;
      case 'e':
        m=e-ten(e);break;
    }
    Console.WriteLine(s+m);
  }
  static int ten(int t){
    return t%10==0?t:t-(t%10)+10;
  }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
#define PI acos(-1.0)
#define eps 1e-9
#define ll long long
#define ull unsigned long long
#define nl printf("\n")
#define sf scanf
#define pf printf
#define INF (ll)1e15
#define mod 1000000007

///#define isValid(n,m,nx,ny)nx>=0&&nx<n&&ny>=0&&ny<m
///int kx[]={1,1,-1,-1,2,2,-2,-2}; //knight moves
///int ky[]={2,-2,2,-2,1,-1,1,-1}; //knight moves
///int dx[]={1,-1,0,0,1,-1,1,-1};  //eight direction
///int dy[]={0,0,1,-1,1,-1,-1,1};  //eight direction
 
///using namespace __gnu_pbds;
using namespace std;
///typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
 
const int S=123456;
int main()
{
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt","r",stdin);
    //#endif
   	int n;
   	while(sf("%d",&n)==1)
   	{
   		int B[n+5];
   		for(int i=1;i<=n-1;i++)sf("%d",&B[i]);
   		
   		int A[n+5];
   		A[1]=B[1];
   		A[2]=B[1];
   		for(int i=3;i<=n;i++)
   		{
   			if(A[i-1]>B[i-1])A[i-1]=B[i-1];
   			A[i]=B[i-1];
   		}

   		int sum=accumulate(A+1,A+n+1,0);
   		pf("%d\n",sum);
   	}
    return 0;
}
 









 




























Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
int main()
{
    int h, w, cnt = 0, ccnt = 0;
    string r;
    cin >> h >> w;
    string a[h];
    int L[h][w];
    std::vector<int> cl0{};
    std::vector<int> cl1{};
    for (int i = 0; i < h; i++)
    {
        cin >> a[i];
        for (int j = 0; j < w; j++)
        {
            if (a[i][j] == '#')
            {
                L[i][j] = 0;
                cl0.emplace_back(i);
                cl1.emplace_back(j);
                ccnt++;
            }
            else
            {
                L[i][j] = -1;
            }
        }
    }
    while (ccnt < h * w)
    {
        std::vector<int> cl0new{};
        std::vector<int> cl1new{};
        cnt++;
        for (int i = 0; i < cl0.size(); i++)
        {
            int ii = cl0[i], jj = cl1[i];
            int sl[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
            for (int si = 0; si < 4; si++)
            {
                int ip = ii + sl[si][0], jp = jj + sl[si][1];
                if (ip < 0 || jp < 0 || ip >= h || jp >= w || L[ip][jp] >= 0)
                    continue;
                L[ip][jp] = cnt;
                ccnt++;
                cl0new.emplace_back(ip);
                cl1new.emplace_back(jp);
            }
        }
        cl0 = cl0new;
        cl1 = cl1new;
    }
    // for (int i = 0; i < h; i++)
    // {
    //     for (int j = 0; j < w; j++)
    //     {
    //         printf("(%d,%d)=%d\n", i, j, L[i][j]);
    //     }
    // }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 15016
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
	int n;
	cin>>n;
	int a[n];
	r(i,n)cin>>a[i];

	for(int i=100000;;i--){
		int s=0,f=0;

		r(j,n){
			s+=a[j];
			if(s<i){
				f=1;
				break;
			}
			s-=i;
		}
		if(f)continue;
		cout<<i<<endl;
		break;
	}
}


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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

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

#define mkp make_pair
#define pb push_back

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

int main(){

    bool flag=false;

    ll ans=0,sum=0;
    
    int x,y,z,k;
    cin >>x>>y>>z>>k;
    vector<ll> a(x),b(y),c(z);
    vector<ll> ab,abc;

    for (int i = 0; i < x; i++)cin >>a[i];
    for (int i = 0; i < y; i++)cin >>b[i];
    for (int i = 0; i < z; i++)cin >>c[i];

    for (int i = 0; i < x; i++){
        for (int j = 0; j < y; j++){
            ab.emplace_back(a[i]+b[j]);
        }
    }
    sort(all(ab),greater<ll>());

    for (int i = 0; i < min(k,(int)ab.size()); i++){
        for (int j = 0; j < z; j++){
            abc.emplace_back(ab[i]+c[j]);
        }
    }
    sort(all(abc),greater<ll>());

    for (int i = 0; i < min(k,(int)abc.size()); i++){
        cout << abc[i] <<endl;
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


Measured memory_bytes: 43368
import java.util.*;

public class Main {

    public static void main(String args[])  {


        Scanner scan = new Scanner(System.in);

        int l = scan.nextInt();
        int r = scan.nextInt();
        int d = scan.nextInt();

        int a = l / d;
        int b = r / d;
        

        if ( l % d== 0 && r % d == 0) {
            System.out.println(b - a + 1);
            
        } else {
            System.out.println(b - a);
            
        }
        
    }


}

Measured memory_bytes: 35472
n,l = map(int, input().split())
#print(n,l)

sum = 0
for i in range(1, n+1):
  sum += l + i - 1
#print(sum)

c = float("inf")
ans = 0
for i in range(1 , n+1):
  taste = l + i - 1
  a = sum - taste
  x = abs(sum - a)
  if x < c:
    c = x
    ans = a
print(ans)

Measured memory_bytes: 38704
using System;
using System.Collections.Generic;

namespace Shell_Sort
{
    class Progaram
    {
        static int cnt = 0;
        static List<int> g = new List<int>();
        private static int[] I_Sort(int[] ca, int n)
        {
            var c = new int[ca.Length];
            ca.CopyTo(c, 0);
            for (int i = n; i < c.Length; i++)
            {
                var v = c[i];
                var j = i - n;
                while (j >= 0 && c[j] > v)
                {
                    c[j+n] = c[j];
                    j -= n;
                    cnt++;                        
                }
                c[j+n] = v;
            }
            return c;
        }

        private static int[] Shell_Sort(int[] ca)
        {
            var m = 1;
            var n = ca.Length / 9;
            while (m <= n) m = m * 3 + 1;
            for (;m > 0; m /= 3)
            {
                ca = I_Sort(ca, m);
                g.Add(m);
            }        
            return ca;
        }

        static void Main()
        {
            var ls = new int[int.Parse(Console.ReadLine())];
            string s;
            var i = 0;
            while ((s = Console.ReadLine()) != null)
                ls[i++] = int.Parse(s);
            var result = Shell_Sort(ls);
            var m = g.Count;
            Console.WriteLine(m);
            for (var j = 0; j < m; j++)
            {
                Console.Write(g[j]);
                Console.Write(j == m - 1 ? '\n' : ' ');
            }
            Console.WriteLine(cnt);
            foreach(var k in result)
                Console.WriteLine(k);
        }
    }
}

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

int main(){
  string s;
  cin >> s;
  int count = 0;
  if(s[0] == '1')count ++;
  if(s[1] == '1')count ++;
  if(s[2] == '1')count ++;
  
  cout << count << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<utility>
#include<string>
#include <iomanip>
#define Pi 3.1415926535897932384626433
using namespace std;
using vi = vector<int>;
using ll = long long;
using P = pair<ll, ll>;
	
vector<ll> Y;
int getY(ll n) {
	return distance(Y.begin(), lower_bound(Y.begin(), Y.end(), n));
}
int main() {
	ll x1, x2, y1, y2;
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a < c) {
		x1 = a;
		y1 = b;
		x2 = c;
		y2 = d;
	}
	else {
		x2 = a;
		y2 = b;
		x1 = c;
		y1 = d;
	}

	int n;
	cin >> n;
	vector<P> V;
	for (int i = 0; i < n; i++) {
		ll x, y;
		cin >> x >> y;
		if (y1 > y2) {
			y = 100000000 - y;
		}
		V.emplace_back(x, y);
		Y.push_back(y);
	}
	if (y1 > y2) {
		y1 = 100000000 - y1;
		y2 = 100000000 - y2;
	}
	sort(V.begin(), V.end());
	sort(Y.begin(), Y.end());
	if (x1 == x2) {
		for (P p : V) {
			if (p.first == x1) {
				if (p.second > y1 && p.second < y2) {
					cout << std::setprecision(17 )<< 100.0 * (y2 - y1) + 10 * Pi - 20.0<< endl;
				}
				else {
					cout << std::setprecision(17) << 100.0 * (y2 - y1) << endl;
				}
				return 0;
			}
		}
	}
	else if (y1 == y2) {
		for (P p : V) {
			if (p.second == y1) {
				if (p.first > x1 && p.first < x2) {
					cout << std::setprecision(17 )<< 100.0 * (x2 - x1) + 10 * Pi - 20<<endl;
				}
				else {
					cout << std::setprecision(17) << 100.0 * (x2 - x1) << endl;
				}
				return 0;
			}
		}

	}
	//LIS
	vector<ll> dp(n + 10,1000000000);
	for (int i = 0; i < V.size(); i++) {
		if (V[i].first < x1)continue;
		if (V[i].first > x2)break;
		if (V[i].second < y1)continue;
		if (V[i].second > y2)continue;
		ll index = V[i].second - y1;
		*lower_bound(dp.begin(), dp.end(), index) = index;
	}
	int lis = distance(dp.begin(), lower_bound(dp.begin(), dp.end(),1000000000));
	if (min(x2 - x1, y2 - y1) + 1 == lis) {
		double ans = x2 + y2 - x1 - y1;
		cout << std::setprecision(17) << ans * 100.0 - lis * (20.0 - 5 * 3.141592653589793238)+5.0*Pi << endl;
		return 0;
	}
	double ans = x2 + y2 - x1 - y1;
	cout << std::setprecision(17)<<ans * 100.0 - lis * (20.0 - 5 * 3.141592653589793238) << endl;
}


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

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

		int[] a = new int[n];

		long sum = 0;
		for(int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			sum += a[i];
		}

		Arrays.sort(a);

		System.out.println(a[0] + " " + a[a.length - 1] + " " + sum);

		scan.close();
	}
}


Measured memory_bytes: 41984
import java.util.*;

public class Main {
	
	public static long rest(long a, long b){
		if(a%b==0) return 0;
		return b-(a%b);
	}
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] A = new long[N];
        long[] B = new long[N];
        for(int i=0;i<N;i++){
        	A[i]=sc.nextLong();
        	B[i]=sc.nextLong();
        }
        long button = 0;
        for(int i=N-1;i>=0;i--){
        	button += rest(A[i]+button,B[i]);
        }
        System.out.println(button);
    }
}

Measured memory_bytes: 68600
unittest
{
	assert( [ "119" ].parse.expand.solve == 991 );
	assert( [ "999" ].parse.expand.solve == 111 );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( dchar[] );
	return tuple( n );
}

auto solve( dchar[] n )
{
	auto r = 0L;
	foreach( c; n )
	{
		r *= 10;
		auto d = ( c - '0' ).to!long;
		switch( d )
		{
			case 1 : d = 9; break;
			case 9 : d = 1; break;
			default:        break;
		}
		r += d;
		
	}
	return r;
}


Measured memory_bytes: 256
i = list(map(int, input().split()))
j= list(map(int, input().split()))
x=sorted(j, reverse=True)
z=0
 
if i[1]>=len(j):
  print(0)
else:
  for a in range(i[1],len(x)):
    z+=x[a]
  print(z)

Measured memory_bytes: 26764
#
# abc144 c
#
import unittest
from io import StringIO
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def resolve():
    N = int(input())

    S = math.ceil(math.sqrt(N))
    ans = N - 1

    for i in range(1, S+1):
        if N % i == 0:
            j = N // i
            ans = min(ans, i+j-2)
    print(ans)


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[: -1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """10"""
        output = """5"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """50"""
        output = """13"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10000000019"""
        output = """10000000018"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 6360
#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;

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
  int root(int x) {
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};

int main() {
  int n,m,k;
  cin>>n>>m>>k;
  UnionFind tree(n);
  vi cnt(n);
  vi G[n];
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].push_back(b);
    G[b].push_back(a);
    tree.unite(a,b);
  }
  vi B[n];
  rep(i,k){
    int a,b;
    cin>>a>>b;
    a--;b--;
    B[a].push_back(b);
    B[b].push_back(a);
  }

  rep(i,n){
    int ans = tree.size(i)-sz(G[i])-1;
    for(auto e: B[i]){
      if(tree.same(i,e))ans--;
    }
    cout<<ans<<" ";
  }
  cout<<endl;
  return 0;
}

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

class Main {

    private static void print_arr (int[] arr) {
        for (int i = 0; i < arr.length - 1; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.print(arr[arr.length - 1]);
        System.out.println();
    }

    private static int[] sort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            print_arr(arr);
            int key = arr[i];
            int j = i - 1;
            while (j >= 0 && arr[j] > key) {
                arr[j + 1] = arr[j];
                j--;
                arr[j + 1] = key;
            }
        }
        print_arr(arr);
        return arr;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in));
        int size = Integer.parseInt(reader.readLine());
        String[] str = reader.readLine().trim().split(" ");
        int[] arr = new int[size];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = Integer.parseInt(str[i]);
        }
        reader.close();
        sort(arr);
    }
}

Measured memory_bytes: 34240
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int k = in.ni(), t = in.ni();
        int[] a = in.ni(t);
        int[] sum = new int[t];
        sum[0] = a[0];
        for (int i = 1; i < t; i++) sum[i] = sum[i - 1] + a[i];
        int[] dp = new int[t];
        dp[0] = a[0]-1;
        for (int i = 1; i < t; i++) {
            if(a[i]<=dp[i-1]){
                dp[i] = dp[i-1] - a[i];
            }else{
                if(a[i]<=sum[i-1]+1) dp[i] = 0;
                else dp[i] = a[i] - sum[i-1] -1;
            }
        }
        out.println(dp[t-1]);
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
string s;
map<string,int> m;
int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> s;
	m["SUN"] = 7; m["SAT"] = 1; m["FRI"] = 2; m["THU"] = 3;
	m["WED"] = 4; m["TUE"] = 5; m["MON"] = 6;
	cout << m[s] << endl;	
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll cnt[200010][5];
int n;
ll a[200010],ans;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		ll up=a[i]+i;
		ll dw=i-a[i];
		if(up<=n)cnt[up][0]++;
		if(dw>=1)cnt[dw][1]++;
	}
	for(int i=1;i<=n;i++){
		ans+=cnt[i][0]*cnt[i][1];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 13028
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

map<int, int> rec;
 
signed main() {
    int N; cin >> N;
    rec[0] = -1;

    int sum = 0, ans = 0;
    for(int i=0; i<N; i++) {
        int val; cin >> val;
        sum += val;
        if(!rec.count(sum)) rec[sum] = i;
        else chmax(ans, i - rec[sum]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 15548
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    reverse(all(a));
    const int inf = 1001001001;
    vector<int> dp(n, inf);
    rep(i, n) {
        *upper_bound(all(dp), a[i]) = a[i];
    }
    cout << lower_bound(all(dp), inf) - dp.begin() << endl;
}


Measured memory_bytes: 3964
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x / GCD(x, y) * y;
}

ll wazu = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (wazu - inv(wazu % x) * (wazu / x)) % wazu;
        if (a >= 0) { return a; }
        else { return wazu + a; }
    }
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    string w;
    cin >> w;

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

    int nag = w.size();

    int j = 0;

    rep(i, nag) {
        if (w[i] == w[i + 1]) { ++j; }
        else { 
            if (j % 2 == 0) { cout << "No" << endl; goto xyz; }
            j = 0;
        }
    }

    cout << "Yes" << endl;

xyz:;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.ExceptionServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Read();
            var T = Read();
            var Ans = int.MaxValue;

            for (int i = 0; i < S.Length - T.Length + 1; i++)
            {
                var st = S.Substring(i, T.Length);
                var needchange = 0;
                for (int j = 0; j < T.Length; j++)
                {
                    if (st[j] != T[j])
                    {
                        needchange++;
                    }
                }
                Ans = Min(Ans, needchange);
            }
            WriteLine(Ans);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 26252
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n,m,k=map(int,input().split())
n+=1
A=list(map(int,input().split()))
A = [0]+A
B= list(map(int,input().split()))
S = sum(B)
ind = m-1
data=[0]*n
tmp = 0
for i in range(n):
  tmp += A[i]
  while tmp + S > k and ind>=-1:
    S -= B[ind]
    ind-=1
  if ind == -2:data[i] = -inf
  else:data[i] = ind+1

for i in range(n):
  ans = max(ans,i+data[i])
    
print(ans)
# print(data)

Measured memory_bytes: 109580
///not today

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

#define SZ(x) (int)(x).size()
#define pb push_back
#define ll long long
#define xmax(x, y) (x) = max((x), (y))
#define xmin(x, y) (x) = min((x), (y))
#define F first
#define S second
#define pii pair<int, int>
#define pll pair<long long, long long>
#define int long long
#define pipii pair<int, pair<int, int> >
#define pf push_front
#define accept_sho ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int32_t main(){
    ll n, a, b;
    cin >>n >>a >>b;
    if(b < a)
        swap(a, b);
    if(abs(a - b)% (ll)2){
        cout <<min(a, n - b + 1) + (b - a - 1)/ 2 <<'\n';
    }
    else
        cout <<abs(a - b)/ (ll)2 <<'\n';
    return false;
}


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

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

using namespace std;

int main() {


	SINT64 N;

	cin >> N;

	SINT64 ANS = 1000;
	
	for (SINT64 i = 0; i < 10; i++) {
		SINT64 BUF = (N % (SINT64)pow(10,i+3)) / (SINT64)pow(10,i);
		BUF = ABS(753 - BUF);
		ANS = MIN(ANS,BUF);
	}

	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();

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

#define INF 99999999
#define FER 0.0000000001

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

struct Edge
{
	int s, t, w;
	Edge(int s,int t,int w):s(s),t(t),w(w){}
	Edge() :Edge(-1, -1, -1) {}
	bool operator<(const Edge& e)const
	{
		return w != e.w ? w < e.w : (s != e.s ? s < e.s : t < e.t);
	}
};


struct P
{
	double x, y;
	P(double x, double y) :x(x), y(y) {}
	P() :P(0, 0) {}
	P operator+(const P& v)const
	{
		return P(x + v.x, y + v.y);
	}
	P operator-(const P& v)const
	{
		return P(x - v.x, y - v.y);
	}
	P operator*(const double v)const
	{
		return P(x*v, y*v);
	}
	bool operator==(const P& v)const
	{
		return abs(x - v.x) <= 0.0000000000001&&abs(y - v.y) <= 0.00000000000001;
	}
	bool operator!=(const P& v)const
	{
		return abs(x - v.x) > 0.0000000000001 || abs(y - v.y) > 0.00000000000001;
	}

	double dot(const P& v)const
	{
		return x*v.x + y*v.y;
	}
	double cross(const P& v)const
	{
		return x*v.y - y*v.x;
	}
	double length()const
	{
		return sqrt(x*x + y*y);
	}
	double length2()const
	{
		return (x*x + y*y);
	}

	bool operator<(const P& v)const
	{
		return x<v.x || (x == v.x) && y < v.y;
	}
	bool operator>(const P& v)const
	{
		return x>v.x || (x == v.x) && y > v.y;
	}
};

struct Rectangle
{
	int h;
	int p;
	Rectangle(int h,int p):h(h),p(p){}
};

ll a[1000], b[1000], c[1000], d[1000];

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

	int N;
	ll V;
	cin >> N >> V;
	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++)cin >> b[i];
	for (int i = 0; i < N; i++)cin >> c[i];
	for (int i = 0; i < N; i++)cin >> d[i];

	vector<ll> va, vb;
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)
	{
		va.push_back(a[i] + b[j]);
		vb.push_back(c[i] + d[j]);
	}

	sort(va.begin(), va.end());
	sort(vb.begin(), vb.end());

	ll ans = 0;
	for (int i = 0; i != va.size(); i++)
	{
		int ub = upper_bound(vb.begin(), vb.end(), V - va[i]) - vb.begin();
		int lb = lower_bound(vb.begin(), vb.end(), V - va[i]) - vb.begin();
		ans += (ub - lb);
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  string S; cin >> S;
  string week[7] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  int now = find(week, week+7, S) - week;
  int result = 7 - now;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

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

	if (x >= 30) {
		col("Yes");
	}
	else {
		col("No");
	}

	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define lundi ios_base::sync_with_stdio(false); cin.tie(NULL);

const int M = 1e9 + 7;

void solve(){
    int n;
    cin>>n;
    vector<int> v(n);
    vector<int> suffix(n, 0);
    for(int i=0;i<n;i++) cin>>v[i];
    int sm = 0;
    int ans = 0;
    for(int i=n-2;i>=0;i--){
        sm += v[i+1];
        ans += v[i]*sm;
        ans %= M;
        sm %= M;
    }
    cout<<ans<<endl;
}

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

Measured memory_bytes: 6356
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int H = Integer.parseInt(S[0]);
    int W = Integer.parseInt(S[1]);
    int N = Integer.parseInt(sc.nextLine());
    String[] T = sc.nextLine().split(" ");
    int[][] field = new int[H][W];
    int h = 0, w = 0;
    boolean f = true;
    for(int i = 0; i < N; i++){
      int M = Integer.parseInt(T[i]);
      for(int j = 0; j < M; j++){
        field[h][w] = i+1;
        if(f){
          if(w == W-1){
            f = false;
            h++;
          }else{
            w++;
          }
        }else{
          if(w == 0){
            h++;
            f = true;
          }else{
            w--;
          }
        }
      }
    }
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(j == W-1){
          System.out.println(field[i][j]);
        }else{
          System.out.print(field[i][j]+" ");
        }
      }
    }
  }
}

Measured memory_bytes: 25172
#include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
#include<iomanip>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int leg[2] = {0};
        int ans = 0;
        bool ground = true;
        rep(i, n){
            string inp;
            cin >> inp;
            if(inp == "lu"){
                leg[0]++;
            }else if(inp == "ru"){
                leg[1]++;
            }else if(inp == "ld"){
                leg[0]--;
            }else if(inp == "rd"){
                leg[1]--;
            }
            if(ground == true && leg[0] == 1 && leg[1] == 1){
                ans++;
                ground = false;
            }else if(ground == false && leg[0] == 0 && leg[1] == 0){
                ans++;
                ground = true;
            }
        }
        cout << ans << endl;
    }
}

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

int main() {
  int a,b; cin>>a>>b;
  if ((1<=a&&a<=9)&&(1<=b&&b<=9)) cout<<a*b<<endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define hi cout<<"hi"
#define ll long long
#define all(c) c.begin(),c.end()
#define mod 1000000007
#define pb push_back
#define pb2 pop_back
#define ff first
#define ss second
#define debug(x) cout<<#x<<" : "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\n";
#define IO ios_base::sync_with_stdio(0);cin.tie(NULL);
const char nl = '\n';
int main(){
    ll n,m,k;cin>>n>>m>>k;
    ll a[n+1],b[m+1];a[0]=0;b[0]=0;
    for(ll i=1;i<=n;i++)cin>>a[i],a[i]+=a[i-1];
    for(ll i=1;i<=m;i++)cin>>b[i],b[i]+=b[i-1];
    ll ans=0,j=m;
    for(ll i=0;i<=n;i++){
        if(a[i]>k)break;
        while(b[j]>k-a[i]){
            j--;
        }ans=max(ans,i+j);
    }cout<<ans<<nl;
}


Measured memory_bytes: 6716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), m = in.nextInt();
			P[] ps = new P[m];
			for (int i = 0; i < m; i++) {
				int a = in.nextInt(), b = in.nextInt();
				ps[i] = new P(a, b);
			}

			Arrays.sort(ps);

			int s = 0, count = 0;;
			for (int i = 0; i < m; i++) {
				if (ps[i].a < s) continue;
				if (s < ps[i].b) {
					s = ps[i].b;
					count++;
				}
			}

			out.println(count);

		}

		class P implements Comparable<P> {
			int a, b;

			public P(int a, int b) {
				super();
				this.a = a;
				this.b = b;
			}

			@Override
			public int compareTo(P o) {
				if (this.b == o.b) {
					return this.a - o.a;
				} else {
					return this.b - o.b;
				}
			}

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 45340
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int count = 0;
            if(a == 0 && b == 0) {
                return;
            }
            for(int i = 1; i < a + 1; i++) {
                for(int j = 1; j < a + 1; j++) {
                    if(i == j) {
                        break;
                    }
                    for(int k = 1; k < a + 1; k++) {
                        if(i == k || j == k) {
                            break;
                        }
                        if(i + j + k == b) {
                            count++;
                            break;
                        }
                    }
                }
            }
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 27076
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int N=110000;
int v[N], s, nbp;
vi adj[N];

void dfs(int x, int t) {
    v[x]=t;
    s++;
    for(int y:adj[x]) {
        if(v[y]==t) nbp=1;
        if(!v[y]) dfs(y, -t);
    }
}

int main() {
    int i, n, m, x, y;
    ll c, c1, cbp;
    scanf("%d%d", &n, &m);
    while(m--) {
        scanf("%d%d", &x, &y);
        adj[x].pb(y);
        adj[y].pb(x);
    }
    c=c1=cbp=0;
    for(i=1; i<=n; i++) if(!v[i]) {
        s=nbp=0;
        dfs(i, 1);
        if(s==1) c1++;
        else {
            c++;
            if(!nbp) cbp++;
        }
    }
    printf("%lld\n", 2*c1*n-c1*c1+c*c+cbp*cbp);
    return 0;
}

Measured memory_bytes: 10240